public inbox for gentoo-portage-dev@lists.gentoo.org
 help / color / mirror / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download: 
* [gentoo-portage-dev] [PATCH] unpack: use chmod-lite helper for bug 554084
@ 2015-10-02  7:22 99% Zac Medico
  0 siblings, 0 replies; 1+ results
From: Zac Medico @ 2015-10-02  7:22 UTC (permalink / raw
  To: gentoo-portage-dev; +Cc: Zac Medico

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
---
 bin/chmod-lite       | 10 ++++++++++
 bin/chmod-lite.py    | 30 ++++++++++++++++++++++++++++++
 bin/phase-helpers.sh |  2 +-
 pym/portage/data.py  |  2 +-
 4 files changed, 42 insertions(+), 2 deletions(-)
 create mode 100755 bin/chmod-lite
 create mode 100755 bin/chmod-lite.py

diff --git a/bin/chmod-lite b/bin/chmod-lite
new file mode 100755
index 0000000..ffa8d4d
--- /dev/null
+++ b/bin/chmod-lite
@@ -0,0 +1,10 @@
+#!/bin/bash
+# Copyright 2015 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+export __PORTAGE_HELPER_CWD=${PWD}
+
+# Use safe cwd, avoiding unsafe import for bug #469338.
+cd "${PORTAGE_PYM_PATH}" || exit 1
+PYTHONPATH=${PORTAGE_PYTHONPATH:-${PORTAGE_PYM_PATH}} \
+	exec "${PORTAGE_PYTHON:-/usr/bin/python}" "$PORTAGE_BIN_PATH/chmod-lite.py" "$@"
diff --git a/bin/chmod-lite.py b/bin/chmod-lite.py
new file mode 100755
index 0000000..697cf77
--- /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 mininal chmod calls.
+		apply_recursive_permissions(filename, filemode=0o644,
+			filemask=0o002, dirmode=0o755, dirmask=0o002)
+
+	return os.EX_OK
+
+if __name__ == "__main__":
+	sys.exit(main(sys.argv[1:]))
diff --git a/bin/phase-helpers.sh b/bin/phase-helpers.sh
index efd2cfa..0c25ffe 100644
--- a/bin/phase-helpers.sh
+++ b/bin/phase-helpers.sh
@@ -532,7 +532,7 @@ unpack() {
 	# Do not chmod '.' since it's probably ${WORKDIR} and PORTAGE_WORKDIR_MODE
 	# should be preserved.
 	find . -mindepth 1 -maxdepth 1 ! -type l -print0 | \
-		${XARGS} -0 chmod -fR a+rX,u+w,g-w,o-w
+		${XARGS} -0 "${PORTAGE_BIN_PATH}/chmod-lite"
 }
 
 econf() {
diff --git a/pym/portage/data.py b/pym/portage/data.py
index 2fd287d..2c99548 100644
--- a/pym/portage/data.py
+++ b/pym/portage/data.py
@@ -139,7 +139,7 @@ def _get_global(k):
 			v = 2
 		elif unprivileged:
 			v = 2
-		elif portage_gid in os.getgroups():
+		elif _get_global('portage_gid') in os.getgroups():
 			v = 1
 
 	elif k in ('portage_gid', 'portage_uid'):
-- 
2.4.6



^ permalink raw reply related	[relevance 99%]

Results 1-1 of 1 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2015-10-02  7:22 99% [gentoo-portage-dev] [PATCH] unpack: use chmod-lite helper for bug 554084 Zac Medico

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox