Bug 1382697 - Change chmod() logic; r=glandium draft
authorGregory Szorc <gps@mozilla.com>
Thu, 20 Jul 2017 18:15:43 -0700
changeset 613683 bd64d5cb56abdfbb48e278c03f8fe85edb4c0b04
parent 613682 8c3e68e7b356cd9cac3f1852d319e7d5458f1f3d
child 613684 7d780ef4062536589cf48639d6923da628fe0566
push id69832
push usergszorc@mozilla.com
push dateSat, 22 Jul 2017 06:27:51 +0000
reviewersglandium
bugs1382697
milestone56.0a1
Bug 1382697 - Change chmod() logic; r=glandium copy_all_entries() and handleTarget() recursively call each other. Both functions were calling chmod() and handling time updates as needed. Since handleTarget() is called for each file and directory, it is the only thing that needs to update metadata. The redundant call in copy_all_entries() has been removed. The call in handleTarget() has been moved ahead of copy_all_entries() to ensure the target directory has proper permissions before copy_all_entries() is called and that directory is operated on. And the call in copy_all_entries() was redundant with the one from maybe_create_dir() in the case where the call didn't come from handleTarget(). MozReview-Commit-ID: ECXo7MeAxsR
config/nsinstall.py
--- a/config/nsinstall.py
+++ b/config/nsinstall.py
@@ -91,18 +91,16 @@ def _nsinstall_internal(argv):
         for e in entries:
             e = os.path.abspath(e)
             if options.X and e in options.X:
                 continue
 
             dest = os.path.join(target, os.path.basename(e))
             dest = os.path.abspath(dest)
             handleTarget(e, dest)
-            if options.m:
-                os.chmod(dest, options.m)
 
     # set up handler
     if options.d:
         # we're supposed to create directories
         def handleTarget(srcpath, targetpath):
             # target directory was already created, just use mkdir
             os.mkdir(targetpath)
     else:
@@ -110,22 +108,23 @@ def _nsinstall_internal(argv):
         def handleTarget(srcpath, targetpath):
             if os.path.isdir(srcpath):
                 try:
                     os.mkdir(targetpath)
                 except OSError as e:
                     if e.errno != errno.EEXIST:
                         raise
 
+                # options.t is not relevant for directories
+                if options.m:
+                    os.chmod(targetpath, options.m)
+
                 entries = [os.path.join(srcpath, e)
                            for e in os.listdir(srcpath)]
                 copy_all_entries(entries, targetpath)
-                # options.t is not relevant for directories
-                if options.m:
-                    os.chmod(targetpath, options.m)
             else:
                 mozfile.remove(targetpath)
 
                 if options.t:
                     shutil.copy2(srcpath, targetpath)
                 else:
                     shutil.copy(srcpath, targetpath)