aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2015-10-02 00:09:31 -0700
committerZac Medico <zmedico@gentoo.org>2015-10-03 10:03:33 -0700
commitb7baeeec3ab6d1e944a2d1f9ab5d4d6ccebd97e8 (patch)
tree559a3f5241b282ac9d0a5c2e0c4d0daab904e8a6 /bin/chmod-lite.py
parentchecksum._open_file: fix BytesWarning (diff)
downloadportage-b7baeeec3ab6d1e944a2d1f9ab5d4d6ccebd97e8.tar.gz
portage-b7baeeec3ab6d1e944a2d1f9ab5d4d6ccebd97e8.tar.bz2
portage-b7baeeec3ab6d1e944a2d1f9ab5d4d6ccebd97e8.zip
unpack: use chmod-lite helper for bug 554084
Use the apply_recursive_permissions function to minimize the number of chmod calls. Also, fix an UnboundLocalError triggered in portage.data._get_global by chmod-lite. X-Gentoo-Bug: 554084 X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=554084 Acked-by: Brian Dolbec <dolsen@gentoo.org>
Diffstat (limited to 'bin/chmod-lite.py')
-rwxr-xr-xbin/chmod-lite.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/bin/chmod-lite.py b/bin/chmod-lite.py
new file mode 100755
index 000000000..177be7eab
--- /dev/null
+++ b/bin/chmod-lite.py
@@ -0,0 +1,30 @@
+#!/usr/bin/python -b
+# Copyright 2015 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+import os
+import sys
+
+from portage.util import apply_recursive_permissions
+
+# Change back to original cwd _after_ all imports (bug #469338).
+os.chdir(os.environ["__PORTAGE_HELPER_CWD"])
+
+def main(files):
+
+ if sys.hexversion >= 0x3000000:
+ # We can't trust that the filesystem encoding (locale dependent)
+ # correctly matches the arguments, so use surrogateescape to
+ # pass through the original argv bytes for Python 3.
+ fs_encoding = sys.getfilesystemencoding()
+ files = [x.encode(fs_encoding, 'surrogateescape') for x in files]
+
+ for filename in files:
+ # Emulate 'chmod -fR a+rX,u+w,g-w,o-w' with minimal chmod calls.
+ apply_recursive_permissions(filename, filemode=0o644,
+ filemask=0o022, dirmode=0o755, dirmask=0o022)
+
+ return os.EX_OK
+
+if __name__ == "__main__":
+ sys.exit(main(sys.argv[1:]))