Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import ast | 5 import ast |
| 6 import contextlib | 6 import contextlib |
| 7 import fnmatch | 7 import fnmatch |
| 8 import json | 8 import json |
| 9 import os | 9 import os |
| 10 import pipes | 10 import pipes |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 191 return device_state.strip() == 'device' | 191 return device_state.strip() == 'device' |
| 192 | 192 |
| 193 | 193 |
| 194 def CheckZipPath(name): | 194 def CheckZipPath(name): |
| 195 if os.path.normpath(name) != name: | 195 if os.path.normpath(name) != name: |
| 196 raise Exception('Non-canonical zip path: %s' % name) | 196 raise Exception('Non-canonical zip path: %s' % name) |
| 197 if os.path.isabs(name): | 197 if os.path.isabs(name): |
| 198 raise Exception('Absolute zip path: %s' % name) | 198 raise Exception('Absolute zip path: %s' % name) |
| 199 | 199 |
| 200 | 200 |
| 201 def IsSymlink(zip_file, name): | |
| 202 zi = zip_file.getinfo(name) | |
| 203 symlink_attr = 0120000 << 16L | |
| 204 if zi.external_attr & symlink_attr == symlink_attr: | |
|
jbudorick
2016/01/30 01:52:56
does stat.S_ISLNK(zi.external_attr) work here?
Mostyn Bramley-Moore
2016/01/30 12:57:05
It works if you pass only the two high order bytes
| |
| 205 return True | |
| 206 return False | |
| 207 | |
| 208 | |
| 201 def ExtractAll(zip_path, path=None, no_clobber=True, pattern=None, | 209 def ExtractAll(zip_path, path=None, no_clobber=True, pattern=None, |
| 202 predicate=None): | 210 predicate=None): |
| 203 if path is None: | 211 if path is None: |
| 204 path = os.getcwd() | 212 path = os.getcwd() |
| 205 elif not os.path.exists(path): | 213 elif not os.path.exists(path): |
| 206 MakeDirectory(path) | 214 MakeDirectory(path) |
| 207 | 215 |
| 208 with zipfile.ZipFile(zip_path) as z: | 216 with zipfile.ZipFile(zip_path) as z: |
| 209 for name in z.namelist(): | 217 for name in z.namelist(): |
| 210 if name.endswith('/'): | 218 if name.endswith('/'): |
| 211 continue | 219 continue |
| 212 if pattern is not None: | 220 if pattern is not None: |
| 213 if not fnmatch.fnmatch(name, pattern): | 221 if not fnmatch.fnmatch(name, pattern): |
| 214 continue | 222 continue |
| 215 if predicate and not predicate(name): | 223 if predicate and not predicate(name): |
| 216 continue | 224 continue |
| 217 CheckZipPath(name) | 225 CheckZipPath(name) |
| 218 if no_clobber: | 226 if no_clobber: |
| 219 output_path = os.path.join(path, name) | 227 output_path = os.path.join(path, name) |
| 220 if os.path.exists(output_path): | 228 if os.path.exists(output_path): |
| 221 raise Exception( | 229 raise Exception( |
| 222 'Path already exists from zip: %s %s %s' | 230 'Path already exists from zip: %s %s %s' |
| 223 % (zip_path, name, output_path)) | 231 % (zip_path, name, output_path)) |
| 224 z.extract(name, path) | 232 if IsSymlink(z, name): |
| 233 dest = os.path.join(path, name) | |
| 234 MakeDirectory(os.path.dirname(dest)) | |
| 235 os.symlink(z.read(name), dest) | |
| 236 else: | |
| 237 z.extract(name, path) | |
| 225 | 238 |
| 226 | 239 |
| 227 def AddToZipHermetic(zip_file, zip_path, src_path=None, data=None, | 240 def AddToZipHermetic(zip_file, zip_path, src_path=None, data=None, |
| 228 compress=None): | 241 compress=None): |
| 229 """Adds a file to the given ZipFile with a hard-coded modified time. | 242 """Adds a file to the given ZipFile with a hard-coded modified time. |
| 230 | 243 |
| 231 Args: | 244 Args: |
| 232 zip_file: ZipFile instance to add the file to. | 245 zip_file: ZipFile instance to add the file to. |
| 233 zip_path: Destination path within the zip file. | 246 zip_path: Destination path within the zip file. |
| 234 src_path: Path of the source file. Mutually exclusive with |data|. | 247 src_path: Path of the source file. Mutually exclusive with |data|. |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 476 | 489 |
| 477 md5_check.CallAndRecordIfStale( | 490 md5_check.CallAndRecordIfStale( |
| 478 on_stale_md5, | 491 on_stale_md5, |
| 479 record_path=record_path, | 492 record_path=record_path, |
| 480 input_paths=input_paths, | 493 input_paths=input_paths, |
| 481 input_strings=input_strings, | 494 input_strings=input_strings, |
| 482 output_paths=output_paths, | 495 output_paths=output_paths, |
| 483 force=force, | 496 force=force, |
| 484 pass_changes=True) | 497 pass_changes=True) |
| 485 | 498 |
| OLD | NEW |