@@ -22,7 +22,7 @@ class PatchInfo:
22
22
archive_files = list of files to include in this patch
23
23
manifestv2 = set of manifest version 2 patch instructions
24
24
manifestv3 = set of manifest version 3 patch instructions
25
- file_exclusion_list =
25
+ file_exclusion_list =
26
26
files to exclude from this patch. names without slashes will be
27
27
excluded anywhere in the directory hiearchy. names with slashes
28
28
will only be excluded at that exact path
@@ -154,7 +154,7 @@ def build_marfile_entry_hash(self, root_path):
154
154
dirname_set .add (dirname )
155
155
156
156
return mar_entry_hash , filename_set , dirname_set
157
-
157
+
158
158
159
159
class MarFileEntry :
160
160
"""Represents a file inside a Mozilla Archive Format (MAR)
@@ -163,7 +163,7 @@ class MarFileEntry:
163
163
foo.mar/dir/bar.txt extracted into /tmp/foo:
164
164
abs_path=/tmp/foo/dir/bar.txt
165
165
name = dir/bar.txt
166
- """
166
+ """
167
167
def __init__ (self , root , name ):
168
168
"""root = path the the top of the mar
169
169
name = relative path within the mar"""
@@ -211,10 +211,10 @@ def bunzip_file(filename):
211
211
if not filename .endswith (".bz2" ):
212
212
os .rename (filename , filename + ".bz2" )
213
213
filename = filename + ".bz2"
214
- exec_shell_cmd ('bzip2 -d "' + filename + '"' )
214
+ exec_shell_cmd ('bzip2 -d "' + filename + '"' )
215
215
216
216
217
- def extract_mar (filename , work_dir ):
217
+ def extract_mar (filename , work_dir ):
218
218
""" Extracts the marfile intot he work_dir
219
219
assumes work_dir already exists otherwise will throw osError"""
220
220
print "Extracting " + filename + " to " + work_dir
@@ -280,7 +280,7 @@ def create_partial_patch_for_file(from_marfile_entry, to_marfile_entry, shas, pa
280
280
# Copy the pre-calculated file into our new patch work aread
281
281
copy_file (src_file_abs_path , os .path .join (patch_info .work_dir , file_in_manifest_name ))
282
282
patch_info .archive_files .append ('"' + file_in_manifest_name + '"' )
283
-
283
+
284
284
def create_add_patch_for_file (to_marfile_entry , patch_info ):
285
285
""" Copy the file to the working dir, add the add instruction, and add it to the list of archive files """
286
286
copy_file (to_marfile_entry .abs_path , os .path .join (patch_info .work_dir , to_marfile_entry .name ))
@@ -293,36 +293,28 @@ def create_add_if_not_patch_for_file(to_marfile_entry, patch_info):
293
293
patch_info .append_add_if_not_instruction (to_marfile_entry .name )
294
294
patch_info .archive_files .append ('"' + to_marfile_entry .name + '"' )
295
295
296
- def process_explicit_remove_files (dir_path , patch_info ):
296
+ def process_explicit_remove_files (dir_path , patch_info ):
297
297
""" Looks for a 'removed-files' file in the dir_path. If the removed-files does not exist
298
298
this will throw. If found adds the removed-files
299
299
found in that file to the patch_info"""
300
300
301
301
# Windows and linux have this file at the root of the dir
302
302
list_file_path = os .path .join (dir_path , "removed-files" )
303
- prefix = ""
304
303
if not os .path .exists (list_file_path ):
305
- # On Mac removed-files contains relative paths from Contents/MacOS/
306
- prefix = "Contents/MacOS"
307
- list_file_path = os .path .join (dir_path , prefix + "/removed-files" )
304
+ list_file_path = os .path .join (dir_path , "Contents/Resources/removed-files" )
308
305
309
306
if (os .path .exists (list_file_path )):
310
- list_file = bz2 . BZ2File (list_file_path ,"r" ) # throws if doesn't exist
307
+ list_file = open (list_file_path ,"r" ) # throws if doesn't exist
311
308
312
309
lines = []
313
310
for line in list_file :
314
311
lines .append (line .strip ())
312
+ list_file .close ()
315
313
316
314
lines .sort (reverse = True )
317
315
for line in lines :
318
316
# Exclude any blank and comment lines.
319
317
if line and not line .startswith ("#" ):
320
- if prefix != "" :
321
- if line .startswith ("../" ):
322
- line = line .replace ("../../" , "" )
323
- line = line .replace ("../" , "Contents/" )
324
- else :
325
- line = os .path .join (prefix ,line )
326
318
# Python on windows uses \ for path separators and the update
327
319
# manifests expects / for path separators on all platforms.
328
320
line = line .replace ("\\ " , "/" )
@@ -336,7 +328,7 @@ def create_partial_patch(from_dir_path, to_dir_path, patch_filename, shas, patch
336
328
# Create a hashtable of the from and to directories
337
329
from_dir_hash ,from_file_set ,from_dir_set = patch_info .build_marfile_entry_hash (from_dir_path )
338
330
to_dir_hash ,to_file_set ,to_dir_set = patch_info .build_marfile_entry_hash (to_dir_path )
339
- # Create a list of the forced updates
331
+ # Create a list of the forced updates
340
332
forced_list = forced_updates .strip ().split ('|' )
341
333
# Require that the precomplete file is included in the complete update
342
334
if "precomplete" not in to_file_set :
@@ -364,7 +356,7 @@ def create_partial_patch(from_dir_path, to_dir_path, patch_filename, shas, patch
364
356
print 'Forcing "' + filename + '"'
365
357
# This filename is in the forced list, explicitly add
366
358
create_add_patch_for_file (to_dir_hash [filename ], patch_info )
367
- else :
359
+ else :
368
360
if from_marfile_entry .sha () != to_marfile_entry .sha ():
369
361
# Not the same - calculate a patch
370
362
create_partial_patch_for_file (from_marfile_entry , to_marfile_entry , shas , patch_info )
@@ -404,27 +396,27 @@ def create_partial_patch(from_dir_path, to_dir_path, patch_filename, shas, patch
404
396
if not os .path .exists (patch_file_dir ):
405
397
os .makedirs (patch_file_dir )
406
398
shutil .copy2 (os .path .join (patch_info .work_dir ,"output.mar" ), patch_filename )
399
+
407
400
return patch_filename
408
401
409
402
def usage ():
410
403
print "-h for help"
411
404
print "-f for patchlist_file"
412
405
413
- def get_buildid (work_dir , platform ):
406
+ def get_buildid (work_dir ):
414
407
""" extracts buildid from MAR
415
- TODO: this should handle 1.8 branch too
416
408
"""
417
- if platform == 'mac' :
418
- ini = '%s/Contents/MacOS/application.ini' % work_dir
419
- else :
420
- ini = '%s/application.ini' % work_dir
409
+ ini = '%s/application.ini' % work_dir
421
410
if not os .path .exists (ini ):
422
- print 'WARNING: application.ini not found, cannot find build ID'
423
- return ''
411
+ ini = '%s/Contents/Resources/application.ini' % work_dir
412
+ if not os .path .exists (ini ):
413
+ print 'WARNING: application.ini not found, cannot find build ID'
414
+ return ''
415
+
424
416
file = bz2 .BZ2File (ini )
425
417
for line in file :
426
- if line .find ('BuildID' ) == 0 :
427
- return line .strip ().split ('=' )[1 ]
418
+ if line .find ('BuildID' ) == 0 :
419
+ return line .strip ().split ('=' )[1 ]
428
420
print 'WARNING: cannot find build ID in application.ini'
429
421
return ''
430
422
@@ -457,7 +449,7 @@ def create_partial_patches(patches):
457
449
try :
458
450
work_dir_root = tempfile .mkdtemp ('-fastmode' , 'tmp' , os .getcwd ())
459
451
print "Building patches using work dir: %s" % (work_dir_root )
460
-
452
+
461
453
# Iterate through every patch set in the patch file
462
454
patch_num = 1
463
455
for patch in patches :
@@ -475,7 +467,7 @@ def create_partial_patches(patches):
475
467
os .mkdir (work_dir_from )
476
468
extract_mar (from_filename ,work_dir_from )
477
469
from_decoded = decode_filename (from_filename )
478
- from_buildid = get_buildid (work_dir_from , from_decoded [ 'platform' ] )
470
+ from_buildid = get_buildid (work_dir_from )
479
471
from_shasum = sha .sha (open (from_filename ).read ()).hexdigest ()
480
472
from_size = str (os .path .getsize (to_filename ))
481
473
@@ -484,13 +476,13 @@ def create_partial_patches(patches):
484
476
os .mkdir (work_dir_to )
485
477
extract_mar (to_filename , work_dir_to )
486
478
to_decoded = decode_filename (from_filename )
487
- to_buildid = get_buildid (work_dir_to , to_decoded [ 'platform' ] )
479
+ to_buildid = get_buildid (work_dir_to )
488
480
to_shasum = sha .sha (open (to_filename ).read ()).hexdigest ()
489
481
to_size = str (os .path .getsize (to_filename ))
490
482
491
483
mar_extract_time = time .time ()
492
484
493
- partial_filename = create_partial_patch (work_dir_from , work_dir_to , patch_filename , shas , PatchInfo (work_dir , ['update.manifest' ,'updatev2.manifest' ,'updatev3.manifest' , 'removed-files' ],['/readme.txt' ]),forced_updates ,['channel-prefs.js' ,'update-settings.ini' ])
485
+ partial_filename = create_partial_patch (work_dir_from , work_dir_to , patch_filename , shas , PatchInfo (work_dir , ['update.manifest' ,'updatev2.manifest' ,'updatev3.manifest' ],[]),forced_updates ,['channel-prefs.js' ,'update-settings.ini' ])
494
486
partial_buildid = to_buildid
495
487
partial_shasum = sha .sha (open (partial_filename ).read ()).hexdigest ()
496
488
partial_size = str (os .path .getsize (partial_filename ))
@@ -499,11 +491,11 @@ def create_partial_patches(patches):
499
491
'to_filename' : os .path .basename (to_filename ),
500
492
'from_filename' : os .path .basename (from_filename ),
501
493
'partial_filename' : os .path .basename (partial_filename ),
502
- 'to_buildid' :to_buildid ,
503
- 'from_buildid' :from_buildid ,
504
- 'to_sha1sum' :to_shasum ,
505
- 'from_sha1sum' :from_shasum ,
506
- 'partial_sha1sum' :partial_shasum ,
494
+ 'to_buildid' :to_buildid ,
495
+ 'from_buildid' :from_buildid ,
496
+ 'to_sha1sum' :to_shasum ,
497
+ 'from_sha1sum' :from_shasum ,
498
+ 'partial_sha1sum' :partial_shasum ,
507
499
'to_size' :to_size ,
508
500
'from_size' :from_size ,
509
501
'partial_size' :partial_size ,
0 commit comments