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