From 74a810174160a314fda304840df2c7273ad6a2fa Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Fri, 7 Apr 2017 19:07:25 -0700 Subject: [PATCH] os.path.islink for Windows --- dvc/runtime.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/dvc/runtime.py b/dvc/runtime.py index f30fe38a5..e54439f4b 100644 --- a/dvc/runtime.py +++ b/dvc/runtime.py @@ -4,6 +4,7 @@ import ctypes from dvc.config import Config, ConfigI from dvc.exceptions import DvcException +from dvc.executor import Executor from dvc.git_wrapper import GitWrapper from dvc.logger import Logger from dvc.settings import Settings @@ -18,13 +19,26 @@ class Runtime(object): if os.name != 'nt': return + Runtime._setup_windows_symlink() + + os.symlink = Runtime.symlink + os.path.islink = Runtime.is_link + + @staticmethod + def _setup_windows_symlink(): func = ctypes.windll.kernel32.CreateSymbolicLinkW func.argtypes = (ctypes.c_wchar_p, ctypes.c_wchar_p, ctypes.c_uint32) func.restype = ctypes.c_ubyte - Runtime.SYMLINC_OVERRIDE = func - os.symlink = Runtime.symlink + @staticmethod + def is_link(path): + if not os.path.exists(path): + return False + + # Definitely ont the best way to check a symlink. + output = Executor.exec_cmd_only_success("dir", path) + return '' in output @staticmethod def symlink(source, link_name):