From 8b024eba53b3046457943b2a3b4fdc70a7787068 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Mon, 10 Apr 2017 16:49:32 -0700 Subject: [PATCH] Windows symlink: os.path.realpath - get rid of recursion --- dvc/runtime.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/dvc/runtime.py b/dvc/runtime.py index 5dec34043..662282af7 100644 --- a/dvc/runtime.py +++ b/dvc/runtime.py @@ -14,6 +14,7 @@ from dvc.settings import Settings class Runtime(object): CONFIG = 'dvc.conf' SYMLINC_OVERRIDE = None + REALPATH_NATIVE = None @staticmethod def ls_command_name(): @@ -30,6 +31,8 @@ class Runtime(object): os.symlink = Runtime.symlink os.path.islink = Runtime.is_link + + Runtime.REALPATH_NATIVE = os.path.realpath os.path.realpath = Runtime.realpath @staticmethod @@ -57,10 +60,10 @@ class Runtime(object): @staticmethod def realpath(path): if os.name != 'nt': - return os.path.realpath(path) + return Runtime.REALPATH_NATIVE(path) if not os.path.islink(path): - return os.path.realpath(path) + return Runtime.REALPATH_NATIVE(path) # It is definitely not the best way to check a symlink. code, output, _ = Executor.exec_cmd(["dir", path], shell=True) @@ -69,7 +72,7 @@ class Runtime(object): groups = re.compile(r'\[\S+\]$').findall(output.strip()) if len(groups) < 1: - return os.path.realpath(path) + return Runtime.REALPATH_NATIVE(path) resolved_link = groups[0][1:-1] return resolved_link