Add support for creating symbolic links on Windows
Replace all calls to os.symlink with platform_utils.symlink.
The Windows implementation calls into the CreateSymbolicLinkW Win32
API, as os.symlink is not supported.
Separate the Win32 API definitions into a separate module
platform_utils_win32 for clarity.
Change-Id: I0714c598664c2df93383734e609d948692c17ec5
diff --git a/project.py b/project.py
index 269fd7e..de5c791 100644
--- a/project.py
+++ b/project.py
@@ -35,6 +35,7 @@
from error import GitError, HookError, UploadError, DownloadError
from error import ManifestInvalidRevisionError
from error import NoManifestException
+import platform_utils
from trace import IsTrace, Trace
from git_refs import GitRefs, HEAD, R_HEADS, R_TAGS, R_PUB, R_M
@@ -277,7 +278,7 @@
dest_dir = os.path.dirname(absDest)
if not os.path.isdir(dest_dir):
os.makedirs(dest_dir)
- os.symlink(relSrc, absDest)
+ platform_utils.symlink(relSrc, absDest)
except IOError:
_error('Cannot link file %s to %s', relSrc, absDest)
@@ -2379,7 +2380,8 @@
self.relpath, name)
continue
try:
- os.symlink(os.path.relpath(stock_hook, os.path.dirname(dst)), dst)
+ platform_utils.symlink(
+ os.path.relpath(stock_hook, os.path.dirname(dst)), dst)
except OSError as e:
if e.errno == errno.EPERM:
raise GitError('filesystem must support symlinks')
@@ -2478,7 +2480,8 @@
os.makedirs(src)
if name in to_symlink:
- os.symlink(os.path.relpath(src, os.path.dirname(dst)), dst)
+ platform_utils.symlink(
+ os.path.relpath(src, os.path.dirname(dst)), dst)
elif copy_all and not os.path.islink(dst):
if os.path.isdir(src):
shutil.copytree(src, dst)