Bug 1382697 - Clean up I/O code in nsinstall.py; r=glandium draft
authorGregory Szorc <gps@mozilla.com>
Thu, 20 Jul 2017 16:24:09 -0700
changeset 613682 8c3e68e7b356cd9cac3f1852d319e7d5458f1f3d
parent 613681 482975a0142fb8ac06f54a4aa8d48f0dc4ea76d8
child 613683 bd64d5cb56abdfbb48e278c03f8fe85edb4c0b04
push id69832
push usergszorc@mozilla.com
push dateSat, 22 Jul 2017 06:27:51 +0000
reviewersglandium
bugs1382697
milestone56.0a1
Bug 1382697 - Clean up I/O code in nsinstall.py; r=glandium Avoid testing for path existence before calling mkdir(). Always use mozfile.remove(). It handles missing files properly and works on all platforms. MozReview-Commit-ID: H74eFr7Wzam
config/nsinstall.py
--- a/config/nsinstall.py
+++ b/config/nsinstall.py
@@ -7,16 +7,17 @@
 # available, and doesn't intend to be fully equivalent.
 # Its major use is for l10n repackaging on systems that don't have
 # a full build environment set up.
 # The basic limitation is, it doesn't even try to link and ignores
 # all related options.
 from __future__ import print_function
 
 from optparse import OptionParser
+import errno
 import os
 import sys
 import shutil
 
 import mozfile
 
 
 def _nsinstall_internal(argv):
@@ -103,30 +104,31 @@ def _nsinstall_internal(argv):
         # we're supposed to create directories
         def handleTarget(srcpath, targetpath):
             # target directory was already created, just use mkdir
             os.mkdir(targetpath)
     else:
         # we're supposed to copy files
         def handleTarget(srcpath, targetpath):
             if os.path.isdir(srcpath):
-                if not os.path.exists(targetpath):
+                try:
                     os.mkdir(targetpath)
+                except OSError as e:
+                    if e.errno != errno.EEXIST:
+                        raise
+
                 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:
-                if os.path.exists(targetpath):
-                    if sys.platform == "win32":
-                        mozfile.remove(targetpath)
-                    else:
-                        os.remove(targetpath)
+                mozfile.remove(targetpath)
+
                 if options.t:
                     shutil.copy2(srcpath, targetpath)
                 else:
                     shutil.copy(srcpath, targetpath)
 
     # the last argument is the target directory
     target = args.pop()
     # ensure target directory (importantly, we do not apply a mode to the directory