1 |
Use the apply_recursive_permissions function to minimize the number of |
2 |
chmod calls. |
3 |
|
4 |
Also, fix an UnboundLocalError triggered in portage.data._get_global |
5 |
by chmod-lite. |
6 |
|
7 |
X-Gentoo-Bug: 554084 |
8 |
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=554084 |
9 |
--- |
10 |
bin/chmod-lite | 10 ++++++++++ |
11 |
bin/chmod-lite.py | 30 ++++++++++++++++++++++++++++++ |
12 |
bin/phase-helpers.sh | 2 +- |
13 |
pym/portage/data.py | 2 +- |
14 |
4 files changed, 42 insertions(+), 2 deletions(-) |
15 |
create mode 100755 bin/chmod-lite |
16 |
create mode 100755 bin/chmod-lite.py |
17 |
|
18 |
diff --git a/bin/chmod-lite b/bin/chmod-lite |
19 |
new file mode 100755 |
20 |
index 0000000..ffa8d4d |
21 |
--- /dev/null |
22 |
+++ b/bin/chmod-lite |
23 |
@@ -0,0 +1,10 @@ |
24 |
+#!/bin/bash |
25 |
+# Copyright 2015 Gentoo Foundation |
26 |
+# Distributed under the terms of the GNU General Public License v2 |
27 |
+ |
28 |
+export __PORTAGE_HELPER_CWD=${PWD} |
29 |
+ |
30 |
+# Use safe cwd, avoiding unsafe import for bug #469338. |
31 |
+cd "${PORTAGE_PYM_PATH}" || exit 1 |
32 |
+PYTHONPATH=${PORTAGE_PYTHONPATH:-${PORTAGE_PYM_PATH}} \ |
33 |
+ exec "${PORTAGE_PYTHON:-/usr/bin/python}" "$PORTAGE_BIN_PATH/chmod-lite.py" "$@" |
34 |
diff --git a/bin/chmod-lite.py b/bin/chmod-lite.py |
35 |
new file mode 100755 |
36 |
index 0000000..697cf77 |
37 |
--- /dev/null |
38 |
+++ b/bin/chmod-lite.py |
39 |
@@ -0,0 +1,30 @@ |
40 |
+#!/usr/bin/python -b |
41 |
+# Copyright 2015 Gentoo Foundation |
42 |
+# Distributed under the terms of the GNU General Public License v2 |
43 |
+ |
44 |
+import os |
45 |
+import sys |
46 |
+ |
47 |
+from portage.util import apply_recursive_permissions |
48 |
+ |
49 |
+# Change back to original cwd _after_ all imports (bug #469338). |
50 |
+os.chdir(os.environ["__PORTAGE_HELPER_CWD"]) |
51 |
+ |
52 |
+def main(files): |
53 |
+ |
54 |
+ if sys.hexversion >= 0x3000000: |
55 |
+ # We can't trust that the filesystem encoding (locale dependent) |
56 |
+ # correctly matches the arguments, so use surrogateescape to |
57 |
+ # pass through the original argv bytes for Python 3. |
58 |
+ fs_encoding = sys.getfilesystemencoding() |
59 |
+ files = [x.encode(fs_encoding, 'surrogateescape') for x in files] |
60 |
+ |
61 |
+ for filename in files: |
62 |
+ # Emulate 'chmod -fR a+rX,u+w,g-w,o-w' with mininal chmod calls. |
63 |
+ apply_recursive_permissions(filename, filemode=0o644, |
64 |
+ filemask=0o002, dirmode=0o755, dirmask=0o002) |
65 |
+ |
66 |
+ return os.EX_OK |
67 |
+ |
68 |
+if __name__ == "__main__": |
69 |
+ sys.exit(main(sys.argv[1:])) |
70 |
diff --git a/bin/phase-helpers.sh b/bin/phase-helpers.sh |
71 |
index efd2cfa..0c25ffe 100644 |
72 |
--- a/bin/phase-helpers.sh |
73 |
+++ b/bin/phase-helpers.sh |
74 |
@@ -532,7 +532,7 @@ unpack() { |
75 |
# Do not chmod '.' since it's probably ${WORKDIR} and PORTAGE_WORKDIR_MODE |
76 |
# should be preserved. |
77 |
find . -mindepth 1 -maxdepth 1 ! -type l -print0 | \ |
78 |
- ${XARGS} -0 chmod -fR a+rX,u+w,g-w,o-w |
79 |
+ ${XARGS} -0 "${PORTAGE_BIN_PATH}/chmod-lite" |
80 |
} |
81 |
|
82 |
econf() { |
83 |
diff --git a/pym/portage/data.py b/pym/portage/data.py |
84 |
index 2fd287d..2c99548 100644 |
85 |
--- a/pym/portage/data.py |
86 |
+++ b/pym/portage/data.py |
87 |
@@ -139,7 +139,7 @@ def _get_global(k): |
88 |
v = 2 |
89 |
elif unprivileged: |
90 |
v = 2 |
91 |
- elif portage_gid in os.getgroups(): |
92 |
+ elif _get_global('portage_gid') in os.getgroups(): |
93 |
v = 1 |
94 |
|
95 |
elif k in ('portage_gid', 'portage_uid'): |
96 |
-- |
97 |
2.4.6 |