Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1377)

Side by Side Diff: build/android/gyp/util/build_utils.py

Issue 1641703002: support symlinks in zip files in build_utils.ExtractAll (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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:
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 dest_dir = os.path.dirname(dest)
235 if not os.path.exists(dest_dir):
236 os.makedirs(dest_dir)
Mostyn Bramley-Moore 2016/01/28 21:20:41 I should use the MakeDirectory function here, I gu
237 os.symlink(z.read(name), dest)
238 else:
239 z.extract(name, path)
225 240
226 241
227 def AddToZipHermetic(zip_file, zip_path, src_path=None, data=None, 242 def AddToZipHermetic(zip_file, zip_path, src_path=None, data=None,
228 compress=None): 243 compress=None):
229 """Adds a file to the given ZipFile with a hard-coded modified time. 244 """Adds a file to the given ZipFile with a hard-coded modified time.
230 245
231 Args: 246 Args:
232 zip_file: ZipFile instance to add the file to. 247 zip_file: ZipFile instance to add the file to.
233 zip_path: Destination path within the zip file. 248 zip_path: Destination path within the zip file.
234 src_path: Path of the source file. Mutually exclusive with |data|. 249 src_path: Path of the source file. Mutually exclusive with |data|.
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 491
477 md5_check.CallAndRecordIfStale( 492 md5_check.CallAndRecordIfStale(
478 on_stale_md5, 493 on_stale_md5,
479 record_path=record_path, 494 record_path=record_path,
480 input_paths=input_paths, 495 input_paths=input_paths,
481 input_strings=input_strings, 496 input_strings=input_strings,
482 output_paths=output_paths, 497 output_paths=output_paths,
483 force=force, 498 force=force,
484 pass_changes=True) 499 pass_changes=True)
485 500
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698