WindowsSymlinkOverride class

This commit is contained in:
Dmitry Petrov
2017-04-07 18:22:22 -07:00
parent 449517c511
commit a6ceb02f97
2 changed files with 21 additions and 20 deletions
+21 -19
View File
@@ -1,28 +1,30 @@
import os
__CSL = None
import ctypes
def win_symlink(source, link_name):
'''symlink(source, link_name) - DVC override for Windows
Creates a symbolic link pointing to source named link_name'''
class WindowsSymlinkOverride(object):
FUNC = None
flags = 0
if source is not None and os.path.isdir(source):
flags = 1
if __CSL(link_name, source, flags) == 0:
raise ctypes.WinError()
def __index__(self):
func = ctypes.windll.kernel32.CreateSymbolicLinkW
func.argtypes = (ctypes.c_wchar_p, ctypes.c_wchar_p, ctypes.c_uint32)
func.restype = ctypes.c_ubyte
WindowsSymlinkOverride.FUNC = func
@staticmethod
def symlink(source, link_name):
'''symlink(source, link_name) - DVC override for Windows
Creates a symbolic link pointing to source named link_name'''
flags = 0
if source is not None and os.path.isdir(source):
flags = 1
if WindowsSymlinkOverride.FUNC(link_name, source, flags) == 0:
raise ctypes.WinError()
def setup():
if os.name == 'nt':
global __CSL
if __CSL is None:
import ctypes
csl = ctypes.windll.kernel32.CreateSymbolicLinkW
csl.argtypes = (ctypes.c_wchar_p, ctypes.c_wchar_p, ctypes.c_uint32)
csl.restype = ctypes.c_ubyte
__CSL = csl
os.symlink = win_symlink
os.symlink = WindowsSymlinkOverride().symlink
pass
-1
View File
@@ -89,4 +89,3 @@ class ReproChangedDeepDependency(ReproChangedDependency):
CmdRepro(self.settings).run()
self.assertEqual(open(self.file_name_res).read(), 'Goodbye\nBobby')
self.assertEqual(1, 2)