mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
WindowsSymlinkOverride class
This commit is contained in:
+21
-19
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user