diff options
Diffstat (limited to 'project.py')
-rw-r--r-- | project.py | 35 |
1 files changed, 20 insertions, 15 deletions
@@ -35,6 +35,7 @@ from git_config import GitConfig, IsId, GetSchemeFromUrl, GetUrlCookieFile, \ | |||
35 | from error import GitError, HookError, UploadError, DownloadError | 35 | from error import GitError, HookError, UploadError, DownloadError |
36 | from error import ManifestInvalidRevisionError | 36 | from error import ManifestInvalidRevisionError |
37 | from error import NoManifestException | 37 | from error import NoManifestException |
38 | import platform_utils | ||
38 | from trace import IsTrace, Trace | 39 | from trace import IsTrace, Trace |
39 | 40 | ||
40 | from git_refs import GitRefs, HEAD, R_HEADS, R_TAGS, R_PUB, R_M | 41 | from git_refs import GitRefs, HEAD, R_HEADS, R_TAGS, R_PUB, R_M |
@@ -62,7 +63,7 @@ def _lwrite(path, content): | |||
62 | fd.close() | 63 | fd.close() |
63 | 64 | ||
64 | try: | 65 | try: |
65 | os.rename(lock, path) | 66 | platform_utils.rename(lock, path) |
66 | except OSError: | 67 | except OSError: |
67 | os.remove(lock) | 68 | os.remove(lock) |
68 | raise | 69 | raise |
@@ -283,7 +284,7 @@ class _LinkFile(object): | |||
283 | dest_dir = os.path.dirname(absDest) | 284 | dest_dir = os.path.dirname(absDest) |
284 | if not os.path.isdir(dest_dir): | 285 | if not os.path.isdir(dest_dir): |
285 | os.makedirs(dest_dir) | 286 | os.makedirs(dest_dir) |
286 | os.symlink(relSrc, absDest) | 287 | platform_utils.symlink(relSrc, absDest) |
287 | except IOError: | 288 | except IOError: |
288 | _error('Cannot link file %s to %s', relSrc, absDest) | 289 | _error('Cannot link file %s to %s', relSrc, absDest) |
289 | 290 | ||
@@ -1288,7 +1289,7 @@ class Project(object): | |||
1288 | 1289 | ||
1289 | need_to_fetch = not (optimized_fetch and | 1290 | need_to_fetch = not (optimized_fetch and |
1290 | (ID_RE.match(self.revisionExpr) and | 1291 | (ID_RE.match(self.revisionExpr) and |
1291 | self._CheckForSha1())) | 1292 | self._CheckForImmutableRevision())) |
1292 | if (need_to_fetch and | 1293 | if (need_to_fetch and |
1293 | not self._RemoteFetch(initial=is_new, quiet=quiet, alt_dir=alt_dir, | 1294 | not self._RemoteFetch(initial=is_new, quiet=quiet, alt_dir=alt_dir, |
1294 | current_branch_only=current_branch_only, | 1295 | current_branch_only=current_branch_only, |
@@ -1898,7 +1899,7 @@ class Project(object): | |||
1898 | 1899 | ||
1899 | 1900 | ||
1900 | # Direct Git Commands ## | 1901 | # Direct Git Commands ## |
1901 | def _CheckForSha1(self): | 1902 | def _CheckForImmutableRevision(self): |
1902 | try: | 1903 | try: |
1903 | # if revision (sha or tag) is not present then following function | 1904 | # if revision (sha or tag) is not present then following function |
1904 | # throws an error. | 1905 | # throws an error. |
@@ -1952,7 +1953,9 @@ class Project(object): | |||
1952 | tag_name = self.revisionExpr[len(R_TAGS):] | 1953 | tag_name = self.revisionExpr[len(R_TAGS):] |
1953 | 1954 | ||
1954 | if is_sha1 or tag_name is not None: | 1955 | if is_sha1 or tag_name is not None: |
1955 | if self._CheckForSha1(): | 1956 | if self._CheckForImmutableRevision(): |
1957 | print('Skipped fetching project %s (already have persistent ref)' | ||
1958 | % self.name) | ||
1956 | return True | 1959 | return True |
1957 | if is_sha1 and not depth: | 1960 | if is_sha1 and not depth: |
1958 | # When syncing a specific commit and --depth is not set: | 1961 | # When syncing a specific commit and --depth is not set: |
@@ -2108,7 +2111,7 @@ class Project(object): | |||
2108 | # We just synced the upstream given branch; verify we | 2111 | # We just synced the upstream given branch; verify we |
2109 | # got what we wanted, else trigger a second run of all | 2112 | # got what we wanted, else trigger a second run of all |
2110 | # refs. | 2113 | # refs. |
2111 | if not self._CheckForSha1(): | 2114 | if not self._CheckForImmutableRevision(): |
2112 | if current_branch_only and depth: | 2115 | if current_branch_only and depth: |
2113 | # Sync the current branch only with depth set to None | 2116 | # Sync the current branch only with depth set to None |
2114 | return self._RemoteFetch(name=name, | 2117 | return self._RemoteFetch(name=name, |
@@ -2211,7 +2214,7 @@ class Project(object): | |||
2211 | 2214 | ||
2212 | if os.path.exists(tmpPath): | 2215 | if os.path.exists(tmpPath): |
2213 | if curlret == 0 and self._IsValidBundle(tmpPath, quiet): | 2216 | if curlret == 0 and self._IsValidBundle(tmpPath, quiet): |
2214 | os.rename(tmpPath, dstPath) | 2217 | platform_utils.rename(tmpPath, dstPath) |
2215 | return True | 2218 | return True |
2216 | else: | 2219 | else: |
2217 | os.remove(tmpPath) | 2220 | os.remove(tmpPath) |
@@ -2312,10 +2315,10 @@ class Project(object): | |||
2312 | print("Retrying clone after deleting %s" % | 2315 | print("Retrying clone after deleting %s" % |
2313 | self.gitdir, file=sys.stderr) | 2316 | self.gitdir, file=sys.stderr) |
2314 | try: | 2317 | try: |
2315 | shutil.rmtree(os.path.realpath(self.gitdir)) | 2318 | platform_utils.rmtree(os.path.realpath(self.gitdir)) |
2316 | if self.worktree and os.path.exists(os.path.realpath | 2319 | if self.worktree and os.path.exists(os.path.realpath |
2317 | (self.worktree)): | 2320 | (self.worktree)): |
2318 | shutil.rmtree(os.path.realpath(self.worktree)) | 2321 | platform_utils.rmtree(os.path.realpath(self.worktree)) |
2319 | return self._InitGitDir(mirror_git=mirror_git, force_sync=False) | 2322 | return self._InitGitDir(mirror_git=mirror_git, force_sync=False) |
2320 | except: | 2323 | except: |
2321 | raise e | 2324 | raise e |
@@ -2357,9 +2360,9 @@ class Project(object): | |||
2357 | self.config.SetString('core.bare', None) | 2360 | self.config.SetString('core.bare', None) |
2358 | except Exception: | 2361 | except Exception: |
2359 | if init_obj_dir and os.path.exists(self.objdir): | 2362 | if init_obj_dir and os.path.exists(self.objdir): |
2360 | shutil.rmtree(self.objdir) | 2363 | platform_utils.rmtree(self.objdir) |
2361 | if init_git_dir and os.path.exists(self.gitdir): | 2364 | if init_git_dir and os.path.exists(self.gitdir): |
2362 | shutil.rmtree(self.gitdir) | 2365 | platform_utils.rmtree(self.gitdir) |
2363 | raise | 2366 | raise |
2364 | 2367 | ||
2365 | def _UpdateHooks(self): | 2368 | def _UpdateHooks(self): |
@@ -2393,7 +2396,8 @@ class Project(object): | |||
2393 | self.relpath, name) | 2396 | self.relpath, name) |
2394 | continue | 2397 | continue |
2395 | try: | 2398 | try: |
2396 | os.symlink(os.path.relpath(stock_hook, os.path.dirname(dst)), dst) | 2399 | platform_utils.symlink( |
2400 | os.path.relpath(stock_hook, os.path.dirname(dst)), dst) | ||
2397 | except OSError as e: | 2401 | except OSError as e: |
2398 | if e.errno == errno.EPERM: | 2402 | if e.errno == errno.EPERM: |
2399 | raise GitError('filesystem must support symlinks') | 2403 | raise GitError('filesystem must support symlinks') |
@@ -2492,7 +2496,8 @@ class Project(object): | |||
2492 | os.makedirs(src) | 2496 | os.makedirs(src) |
2493 | 2497 | ||
2494 | if name in to_symlink: | 2498 | if name in to_symlink: |
2495 | os.symlink(os.path.relpath(src, os.path.dirname(dst)), dst) | 2499 | platform_utils.symlink( |
2500 | os.path.relpath(src, os.path.dirname(dst)), dst) | ||
2496 | elif copy_all and not os.path.islink(dst): | 2501 | elif copy_all and not os.path.islink(dst): |
2497 | if os.path.isdir(src): | 2502 | if os.path.isdir(src): |
2498 | shutil.copytree(src, dst) | 2503 | shutil.copytree(src, dst) |
@@ -2527,7 +2532,7 @@ class Project(object): | |||
2527 | except GitError as e: | 2532 | except GitError as e: |
2528 | if force_sync: | 2533 | if force_sync: |
2529 | try: | 2534 | try: |
2530 | shutil.rmtree(dotgit) | 2535 | platform_utils.rmtree(dotgit) |
2531 | return self._InitWorkTree(force_sync=False, submodules=submodules) | 2536 | return self._InitWorkTree(force_sync=False, submodules=submodules) |
2532 | except: | 2537 | except: |
2533 | raise e | 2538 | raise e |
@@ -2547,7 +2552,7 @@ class Project(object): | |||
2547 | self._CopyAndLinkFiles() | 2552 | self._CopyAndLinkFiles() |
2548 | except Exception: | 2553 | except Exception: |
2549 | if init_dotgit: | 2554 | if init_dotgit: |
2550 | shutil.rmtree(dotgit) | 2555 | platform_utils.rmtree(dotgit) |
2551 | raise | 2556 | raise |
2552 | 2557 | ||
2553 | def _gitdir_path(self, path): | 2558 | def _gitdir_path(self, path): |