From b706f60959834e120c29df2005e6e54617ed789d Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Sat, 8 Apr 2017 17:57:16 -0700 Subject: [PATCH] Windows symlink: exec cmd as shell option; small os.path.join() test fix --- dvc/executor.py | 5 +++-- dvc/runtime.py | 2 +- dvc/utils.py | 4 +--- tests/basic_env.py | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/dvc/executor.py b/dvc/executor.py index d48257a75..f81108c41 100644 --- a/dvc/executor.py +++ b/dvc/executor.py @@ -10,7 +10,7 @@ class ExecutorError(DvcException): class Executor: @staticmethod - def exec_cmd(cmd, stdout_file=None, stderr_file=None, cwd=None): + def exec_cmd(cmd, stdout_file=None, stderr_file=None, cwd=None, shell=False): stdout, stdout_fd = Executor.output_file(stdout_file) stderr, stderr_fd = Executor.output_file(stderr_file) @@ -18,7 +18,8 @@ class Executor: p = subprocess.Popen(cmd, cwd=cwd, stdout=stdout, - stderr=stderr) + stderr=stderr, + shell=False) p.wait() out, err = map(lambda s: s.decode().strip('\n\r') if s else '', p.communicate()) diff --git a/dvc/runtime.py b/dvc/runtime.py index 526c54d0d..acf66285f 100644 --- a/dvc/runtime.py +++ b/dvc/runtime.py @@ -40,7 +40,7 @@ class Runtime(object): return False # It is definitely not the best way to check a symlink. - code, output, _ = Executor.exec_cmd(["dir", path]) + code, output, _ = Executor.exec_cmd(["dir", path], shell=True) if code != 0: return False diff --git a/dvc/utils.py b/dvc/utils.py index e9f4e4276..8f73b897c 100644 --- a/dvc/utils.py +++ b/dvc/utils.py @@ -20,9 +20,7 @@ def cached_property(f): def rmtree(dir): '''Cross platform rmtree()''' if os.name == 'nt': - if not os.access(dir, os.W_OK): + if os.path.exists(dir) and not os.access(dir, os.W_OK): os.chmod(dir, stat.S_IWUSR) - else: - raise shutil.rmtree(dir, ignore_errors=True) diff --git a/tests/basic_env.py b/tests/basic_env.py index 3bf6b1b3f..4f2c082c1 100644 --- a/tests/basic_env.py +++ b/tests/basic_env.py @@ -71,7 +71,7 @@ class DirHierarchyEnvironment(BasicEnvironment): self.settings = Settings([], self._git, self._config) self.dir1 = os.path.join('dir1') - self.dir11 = os.path.join('dir1/dir11') + self.dir11 = os.path.join('dir1', 'dir11') self.dir2 = os.path.join('dir2') os.mkdir('cache')