Bug 1147760 - In mozpack.files.FileCopier.copy, remove files after copying. r=gps, a=sledru
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 26 Mar 2015 15:40:08 +0900
changeset 258291 2bc3aac3094b
parent 258290 088cbfb10079
child 258292 882dd82e8af0
push id4637
push userryanvm@gmail.com
push date2015-04-06 19:04 +0000
treeherdermozilla-beta@882dd82e8af0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgps, sledru
bugs1147760
milestone38.0
Bug 1147760 - In mozpack.files.FileCopier.copy, remove files after copying. r=gps, a=sledru Some file types, such as XPTFile, read their associated data during the copy. In the case of XPTFiles, several original files are linked together in one destination file. When a FileCopier is used in-place, those original files are removed before XPTFile.copy is invoked, so XPTFile.copy fails. Generally speaking, there are many other reasons why FileCopier can fail in-place, but the only active use of this mode is l10n repack code, which actually doesn't do much of the dangerous uses. However, it can end up linking XPTFiles for some reason, which fails for the reasons given above.
python/mozbuild/mozpack/copier.py
--- a/python/mozbuild/mozpack/copier.py
+++ b/python/mozbuild/mozpack/copier.py
@@ -310,36 +310,36 @@ class FileCopier(FileRegistry):
             for d in dirs:
                 existing_dirs.add(os.path.normpath(os.path.join(root, d)))
 
             for f in files:
                 existing_files.add(os.path.normpath(os.path.join(root, f)))
 
         # Now we reconcile the state of the world against what we want.
 
+        # Install files.
+        for p, f in self:
+            destfile = os.path.normpath(os.path.join(destination, p))
+            if f.copy(destfile, skip_if_older):
+                result.updated_files.add(destfile)
+            else:
+                result.existing_files.add(destfile)
+
         # Remove files no longer accounted for.
         if remove_unaccounted:
             for f in existing_files - dest_files:
                 # Windows requires write access to remove files.
                 if os.name == 'nt' and not os.access(f, os.W_OK):
                     # It doesn't matter what we set permissions to since we
                     # will remove this file shortly.
                     os.chmod(f, 0600)
 
                 os.remove(f)
                 result.removed_files.add(f)
 
-        # Install files.
-        for p, f in self:
-            destfile = os.path.normpath(os.path.join(destination, p))
-            if f.copy(destfile, skip_if_older):
-                result.updated_files.add(destfile)
-            else:
-                result.existing_files.add(destfile)
-
         if not remove_empty_directories:
             return result
 
         # Figure out which directories can be removed. This is complicated
         # by the fact we optionally remove existing files. This would be easy
         # if we walked the directory tree after installing files. But, we're
         # trying to minimize system calls.