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
--- 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