Bug 1293234 - Use octal notation for permission modes in the build system; r=gps
As of Python 3, decimal notations of octal values for permission modes
are no longer permitted and will result in a `SyntaxError` exception
(`invalid token`).
Using the proper octal notation which is also Python 2.7 compatible will
fix this issue.
--- a/config/nsinstall.py
+++ b/config/nsinstall.py
@@ -36,17 +36,17 @@ def _nsinstall_internal(argv):
help="Link prefix (ignored)")
p.add_option('-X', action="append", metavar="file",
help="Ignore a file when installing a directory recursively.")
# The remaining arguments are not used in our tree, thus they're not
# implented.
def BadArg(option, opt, value, parser):
parser.error('option not supported: {0}'.format(opt))
-
+
p.add_option('-C', action="callback", metavar="CWD",
callback=BadArg,
help="NOT SUPPORTED")
p.add_option('-o', action="callback", callback=BadArg,
help="Set owner (NOT SUPPORTED)", metavar="owner")
p.add_option('-g', action="callback", callback=BadArg,
help="Set group (NOT SUPPORTED)", metavar="group")
--- a/config/tests/unit-nsinstall.py
+++ b/config/tests/unit-nsinstall.py
@@ -114,17 +114,17 @@ class TestNsinstall(unittest.TestCase):
self.assertEqual(os.stat(testfile).st_mtime,
os.stat(destfile).st_mtime)
if sys.platform != "win32":
# can't run this test on windows, don't have real file modes there
def test_nsinstall_m(self):
"Test that nsinstall -m works (set mode)"
testfile = self.touch("testfile")
- mode = 0600
+ mode = 0o600
os.chmod(testfile, mode)
testdir = self.mkdirs("testdir")
self.assertEqual(nsinstall(["-m", "{0:04o}"
.format(mode), testfile, testdir]), 0)
destfile = os.path.join(testdir, "testfile")
self.assert_(os.path.isfile(destfile))
self.assertEqual(os.stat(testfile).st_mode,
os.stat(destfile).st_mode)
--- a/configure.py
+++ b/configure.py
@@ -76,17 +76,17 @@ def config_status(config):
if __name__ == '__main__':
args = dict([(name, globals()[name]) for name in __all__])
from mozbuild.config_status import config_status
config_status(**args)
''')
# Other things than us are going to run this file, so we need to give it
# executable permissions.
- os.chmod('config.status', 0755)
+ os.chmod('config.status', 0o755)
if config.get('MOZ_BUILD_APP') != 'js' or config.get('JS_STANDALONE'):
os.environ['WRITE_MOZINFO'] = '1'
# Until we have access to the virtualenv from this script, execute
# config.status externally, with the virtualenv python.
return subprocess.call([config['PYTHON'], 'config.status'])
return 0
--- a/python/mozbuild/mozpack/copier.py
+++ b/python/mozbuild/mozpack/copier.py
@@ -319,19 +319,19 @@ class FileCopier(FileRegistry):
if stat.S_ISLNK(st.st_mode):
# While we have remove_unaccounted, it doesn't apply
# to directory symlinks because if it did, our behavior
# could be very wrong.
os.remove(d)
os.mkdir(d)
if not os.access(d, os.W_OK):
- umask = os.umask(0077)
+ umask = os.umask(0o077)
os.umask(umask)
- os.chmod(d, 0777 & ~umask)
+ os.chmod(d, 0o777 & ~umask)
if isinstance(remove_unaccounted, FileRegistry):
existing_files = set(os.path.normpath(os.path.join(destination, p))
for p in remove_unaccounted.paths())
existing_dirs = set(os.path.normpath(os.path.join(destination, p))
for p in remove_unaccounted
.required_directories())
existing_dirs |= {os.path.normpath(destination)}
@@ -407,17 +407,17 @@ class FileCopier(FileRegistry):
# 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.chmod(f, 0o600)
os.remove(f)
result.removed_files.add(f)
if not remove_empty_directories:
return result
# Figure out which directories can be removed. This is complicated
@@ -449,17 +449,17 @@ class FileCopier(FileRegistry):
for d in sorted(remove_dirs, key=len, reverse=True):
try:
try:
os.rmdir(d)
except OSError as e:
if e.errno in (errno.EPERM, errno.EACCES):
# Permissions may not allow deletion. So ensure write
# access is in place before attempting to rmdir again.
- os.chmod(d, 0700)
+ os.chmod(d, 0o700)
os.rmdir(d)
else:
raise
except OSError as e:
# If remove_unaccounted is a # FileRegistry, then we have a
# list of directories that may not be empty, so ignore rmdir
# ENOTEMPTY errors for them.
if (isinstance(remove_unaccounted, FileRegistry) and
--- a/python/mozbuild/mozpack/test/test_copier.py
+++ b/python/mozbuild/mozpack/test/test_copier.py
@@ -332,18 +332,18 @@ class TestFileCopier(TestWithTmpDir):
p = self.tmppath('no_perms')
with open(p, 'a'):
pass
# Make file and directory unwritable. Reminder: making a directory
# unwritable prevents modifications (including deletes) from the list
# of files in that directory.
- os.chmod(p, 0400)
- os.chmod(self.tmpdir, 0400)
+ os.chmod(p, 0o400)
+ os.chmod(self.tmpdir, 0o400)
copier = FileCopier()
copier.add('dummy', GeneratedFile('content'))
result = copier.copy(self.tmpdir)
self.assertEqual(result.removed_files_count, 1)
self.assertFalse(os.path.exists(p))
def test_no_remove(self):