diff options
-rw-r--r-- | manifest_xml.py | 57 | ||||
-rw-r--r-- | platform_utils_win32.py | 17 | ||||
-rw-r--r-- | subcmds/diffmanifests.py | 4 |
3 files changed, 43 insertions, 35 deletions
diff --git a/manifest_xml.py b/manifest_xml.py index f37732cd..23b4fb74 100644 --- a/manifest_xml.py +++ b/manifest_xml.py | |||
@@ -135,6 +135,7 @@ class XmlManifest(object): | |||
135 | self.globalConfig = GitConfig.ForUser() | 135 | self.globalConfig = GitConfig.ForUser() |
136 | self.localManifestWarning = False | 136 | self.localManifestWarning = False |
137 | self.isGitcClient = False | 137 | self.isGitcClient = False |
138 | self._load_local_manifests = True | ||
138 | 139 | ||
139 | self.repoProject = MetaProject(self, 'repo', | 140 | self.repoProject = MetaProject(self, 'repo', |
140 | gitdir = os.path.join(repodir, 'repo/.git'), | 141 | gitdir = os.path.join(repodir, 'repo/.git'), |
@@ -146,15 +147,26 @@ class XmlManifest(object): | |||
146 | 147 | ||
147 | self._Unload() | 148 | self._Unload() |
148 | 149 | ||
149 | def Override(self, name): | 150 | def Override(self, name, load_local_manifests=True): |
150 | """Use a different manifest, just for the current instantiation. | 151 | """Use a different manifest, just for the current instantiation. |
151 | """ | 152 | """ |
152 | path = os.path.join(self.manifestProject.worktree, name) | 153 | path = None |
153 | if not os.path.isfile(path): | 154 | |
154 | raise ManifestParseError('manifest %s not found' % name) | 155 | # Look for a manifest by path in the filesystem (including the cwd). |
156 | if not load_local_manifests: | ||
157 | local_path = os.path.abspath(name) | ||
158 | if os.path.isfile(local_path): | ||
159 | path = local_path | ||
160 | |||
161 | # Look for manifests by name from the manifests repo. | ||
162 | if path is None: | ||
163 | path = os.path.join(self.manifestProject.worktree, name) | ||
164 | if not os.path.isfile(path): | ||
165 | raise ManifestParseError('manifest %s not found' % name) | ||
155 | 166 | ||
156 | old = self.manifestFile | 167 | old = self.manifestFile |
157 | try: | 168 | try: |
169 | self._load_local_manifests = load_local_manifests | ||
158 | self.manifestFile = path | 170 | self.manifestFile = path |
159 | self._Unload() | 171 | self._Unload() |
160 | self._Load() | 172 | self._Load() |
@@ -435,23 +447,26 @@ class XmlManifest(object): | |||
435 | nodes.append(self._ParseManifestXml(self.manifestFile, | 447 | nodes.append(self._ParseManifestXml(self.manifestFile, |
436 | self.manifestProject.worktree)) | 448 | self.manifestProject.worktree)) |
437 | 449 | ||
438 | local = os.path.join(self.repodir, LOCAL_MANIFEST_NAME) | 450 | if self._load_local_manifests: |
439 | if os.path.exists(local): | 451 | local = os.path.join(self.repodir, LOCAL_MANIFEST_NAME) |
440 | if not self.localManifestWarning: | 452 | if os.path.exists(local): |
441 | self.localManifestWarning = True | 453 | if not self.localManifestWarning: |
442 | print('warning: %s is deprecated; put local manifests in `%s` instead' | 454 | self.localManifestWarning = True |
443 | % (LOCAL_MANIFEST_NAME, os.path.join(self.repodir, LOCAL_MANIFESTS_DIR_NAME)), | 455 | print('warning: %s is deprecated; put local manifests ' |
444 | file=sys.stderr) | 456 | 'in `%s` instead' % (LOCAL_MANIFEST_NAME, |
445 | nodes.append(self._ParseManifestXml(local, self.repodir)) | 457 | os.path.join(self.repodir, LOCAL_MANIFESTS_DIR_NAME)), |
446 | 458 | file=sys.stderr) | |
447 | local_dir = os.path.abspath(os.path.join(self.repodir, LOCAL_MANIFESTS_DIR_NAME)) | 459 | nodes.append(self._ParseManifestXml(local, self.repodir)) |
448 | try: | 460 | |
449 | for local_file in sorted(platform_utils.listdir(local_dir)): | 461 | local_dir = os.path.abspath(os.path.join(self.repodir, |
450 | if local_file.endswith('.xml'): | 462 | LOCAL_MANIFESTS_DIR_NAME)) |
451 | local = os.path.join(local_dir, local_file) | 463 | try: |
452 | nodes.append(self._ParseManifestXml(local, self.repodir)) | 464 | for local_file in sorted(platform_utils.listdir(local_dir)): |
453 | except OSError: | 465 | if local_file.endswith('.xml'): |
454 | pass | 466 | local = os.path.join(local_dir, local_file) |
467 | nodes.append(self._ParseManifestXml(local, self.repodir)) | ||
468 | except OSError: | ||
469 | pass | ||
455 | 470 | ||
456 | try: | 471 | try: |
457 | self._ParseManifest(nodes) | 472 | self._ParseManifest(nodes) |
diff --git a/platform_utils_win32.py b/platform_utils_win32.py index a6431216..7ab2bf04 100644 --- a/platform_utils_win32.py +++ b/platform_utils_win32.py | |||
@@ -17,7 +17,7 @@ import errno | |||
17 | 17 | ||
18 | from ctypes import WinDLL, get_last_error, FormatError, WinError, addressof | 18 | from ctypes import WinDLL, get_last_error, FormatError, WinError, addressof |
19 | from ctypes import c_buffer | 19 | from ctypes import c_buffer |
20 | from ctypes.wintypes import BOOL, LPCWSTR, DWORD, HANDLE, POINTER, c_ubyte | 20 | from ctypes.wintypes import BOOL, BOOLEAN, LPCWSTR, DWORD, HANDLE, POINTER, c_ubyte |
21 | from ctypes.wintypes import WCHAR, USHORT, LPVOID, Structure, Union, ULONG | 21 | from ctypes.wintypes import WCHAR, USHORT, LPVOID, Structure, Union, ULONG |
22 | from ctypes.wintypes import byref | 22 | from ctypes.wintypes import byref |
23 | 23 | ||
@@ -33,7 +33,7 @@ ERROR_PRIVILEGE_NOT_HELD = 1314 | |||
33 | 33 | ||
34 | # Win32 API entry points | 34 | # Win32 API entry points |
35 | CreateSymbolicLinkW = kernel32.CreateSymbolicLinkW | 35 | CreateSymbolicLinkW = kernel32.CreateSymbolicLinkW |
36 | CreateSymbolicLinkW.restype = BOOL | 36 | CreateSymbolicLinkW.restype = BOOLEAN |
37 | CreateSymbolicLinkW.argtypes = (LPCWSTR, # lpSymlinkFileName In | 37 | CreateSymbolicLinkW.argtypes = (LPCWSTR, # lpSymlinkFileName In |
38 | LPCWSTR, # lpTargetFileName In | 38 | LPCWSTR, # lpTargetFileName In |
39 | DWORD) # dwFlags In | 39 | DWORD) # dwFlags In |
@@ -145,19 +145,12 @@ def create_dirsymlink(source, link_name): | |||
145 | 145 | ||
146 | 146 | ||
147 | def _create_symlink(source, link_name, dwFlags): | 147 | def _create_symlink(source, link_name, dwFlags): |
148 | # Note: Win32 documentation for CreateSymbolicLink is incorrect. | 148 | if not CreateSymbolicLinkW(link_name, source, dwFlags | SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE): |
149 | # On success, the function returns "1". | ||
150 | # On error, the function returns some random value (e.g. 1280). | ||
151 | # The best bet seems to use "GetLastError" and check for error/success. | ||
152 | CreateSymbolicLinkW(link_name, source, dwFlags | SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE) | ||
153 | code = get_last_error() | ||
154 | if code != ERROR_SUCCESS: | ||
155 | # See https://github.com/golang/go/pull/24307/files#diff-b87bc12e4da2497308f9ef746086e4f0 | 149 | # See https://github.com/golang/go/pull/24307/files#diff-b87bc12e4da2497308f9ef746086e4f0 |
156 | # "the unprivileged create flag is unsupported below Windows 10 (1703, v10.0.14972). | 150 | # "the unprivileged create flag is unsupported below Windows 10 (1703, v10.0.14972). |
157 | # retry without it." | 151 | # retry without it." |
158 | CreateSymbolicLinkW(link_name, source, dwFlags) | 152 | if not CreateSymbolicLinkW(link_name, source, dwFlags): |
159 | code = get_last_error() | 153 | code = get_last_error() |
160 | if code != ERROR_SUCCESS: | ||
161 | error_desc = FormatError(code).strip() | 154 | error_desc = FormatError(code).strip() |
162 | if code == ERROR_PRIVILEGE_NOT_HELD: | 155 | if code == ERROR_PRIVILEGE_NOT_HELD: |
163 | raise OSError(errno.EPERM, error_desc, link_name) | 156 | raise OSError(errno.EPERM, error_desc, link_name) |
diff --git a/subcmds/diffmanifests.py b/subcmds/diffmanifests.py index 751a2026..a1e823cd 100644 --- a/subcmds/diffmanifests.py +++ b/subcmds/diffmanifests.py | |||
@@ -190,12 +190,12 @@ synced and their revisions won't be found. | |||
190 | self.printProject = self.printAdded = self.printRemoved = self.printRevision = self.printText | 190 | self.printProject = self.printAdded = self.printRemoved = self.printRevision = self.printText |
191 | 191 | ||
192 | manifest1 = XmlManifest(self.manifest.repodir) | 192 | manifest1 = XmlManifest(self.manifest.repodir) |
193 | manifest1.Override(args[0]) | 193 | manifest1.Override(args[0], load_local_manifests=False) |
194 | if len(args) == 1: | 194 | if len(args) == 1: |
195 | manifest2 = self.manifest | 195 | manifest2 = self.manifest |
196 | else: | 196 | else: |
197 | manifest2 = XmlManifest(self.manifest.repodir) | 197 | manifest2 = XmlManifest(self.manifest.repodir) |
198 | manifest2.Override(args[1]) | 198 | manifest2.Override(args[1], load_local_manifests=False) |
199 | 199 | ||
200 | diff = manifest1.projectsDiff(manifest2) | 200 | diff = manifest1.projectsDiff(manifest2) |
201 | if opt.raw: | 201 | if opt.raw: |