Chromium Code Reviews| Index: git_drover.py |
| diff --git a/git_drover.py b/git_drover.py |
| index 18756d84fbb092f5665afbd83db58e5d46afc7b2..7cca76d460fec29c9c4fd4a5af6c8910d12d7e50 100755 |
| --- a/git_drover.py |
| +++ b/git_drover.py |
| @@ -20,6 +20,25 @@ class Error(Exception): |
| pass |
| +if os.name == 'nt': |
| + # This is a just-good-enough emulation of os.symlink for drover to work on |
| + # Windows. It uses junctioning of directories (most of the contents of |
| + # the .git directory), but copies files. Note that we can't use |
| + # CreateSymbolicLink or CreateHardLink here, as they both require elevation. |
| + # Creating reparse points is what we want for the directories, but doing so |
| + # is a relatively messy set of DeviceIoControl work at the API level, so we |
| + # simply shell to `mklink /j` instead. |
| + def emulate_symlink_windows(source, link_name): |
| + if os.path.isdir(source): |
| + subprocess.check_call(['mklink', '/j', |
| + link_name.replace('/', '\\'), |
| + source.replace('/', '\\')], |
| + shell=True) |
| + else: |
| + shutil.copy(source, link_name) |
| + os.symlink = emulate_symlink_windows |
|
iannucci
2015/10/07 22:58:26
Though I'm not totally sold on adding this back in
scottmg
2015/10/07 23:03:52
It sort of has to be os.symlink, or else various c
|
| + |
| + |
| class _Drover(object): |
| def __init__(self, branch, revision, parent_repo, dry_run): |
| @@ -72,7 +91,11 @@ class _Drover(object): |
| self._run_git_command(['branch', '-D', self._branch_name]) |
| if self._workdir: |
| logging.debug('Deleting %s', self._workdir) |
| - shutil.rmtree(self._workdir) |
| + if os.name == 'nt': |
| + # Use rmdir to properly handle the junctions we created. |
| + subprocess.check_call(['rmdir', '/s', '/q', self._workdir], shell=True) |
| + else: |
| + shutil.rmtree(self._workdir) |
| self._dev_null_file.close() |
| @staticmethod |