public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Zac Medico" <zmedico@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/portage:master commit in: lib/portage/package/ebuild/
Date: Sat, 15 Feb 2020 20:28:58 +0000 (UTC)	[thread overview]
Message-ID: <1581798334.9b07545003fed649b1a0a8a9e5cb69d5e2fa4951.zmedico@gentoo> (raw)

commit:     9b07545003fed649b1a0a8a9e5cb69d5e2fa4951
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sat Feb 15 20:23:23 2020 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sat Feb 15 20:25:34 2020 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=9b075450

fetch: split out _ensure_distdir function (bug 601252)

Split out an _ensure_distdir function which will have to be
called earlier if the fetch function is called with dropped
privileges as discussed in bug 601252.

Bug: https://bugs.gentoo.org/601252
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>

 lib/portage/package/ebuild/fetch.py | 102 +++++++++++++++++++-----------------
 1 file changed, 55 insertions(+), 47 deletions(-)

diff --git a/lib/portage/package/ebuild/fetch.py b/lib/portage/package/ebuild/fetch.py
index 7ab054874..e0260829b 100644
--- a/lib/portage/package/ebuild/fetch.py
+++ b/lib/portage/package/ebuild/fetch.py
@@ -152,6 +152,59 @@ def _userpriv_test_write_file(settings, file_path):
 	_userpriv_test_write_file_cache[file_path] = rval
 	return rval
 
+
+def _ensure_distdir(settings, distdir):
+	"""
+	Ensure that DISTDIR exists with appropriate permissions.
+
+	@param settings: portage config
+	@type settings: portage.package.ebuild.config.config
+	@param distdir: DISTDIR path
+	@type distdir: str
+	@raise PortageException: portage.exception wrapper exception
+	"""
+	global _userpriv_test_write_file_cache
+	dirmode  = 0o070
+	filemode =   0o60
+	modemask =    0o2
+	dir_gid = portage_gid
+	if "FAKED_MODE" in settings:
+		# When inside fakeroot, directories with portage's gid appear
+		# to have root's gid. Therefore, use root's gid instead of
+		# portage's gid to avoid spurrious permissions adjustments
+		# when inside fakeroot.
+		dir_gid = 0
+
+	userfetch = portage.data.secpass >= 2 and "userfetch" in settings.features
+	userpriv = portage.data.secpass >= 2 and "userpriv" in settings.features
+	write_test_file = os.path.join(distdir, ".__portage_test_write__")
+
+	try:
+		st = os.stat(distdir)
+	except OSError:
+		st = None
+
+	if st is not None and stat.S_ISDIR(st.st_mode):
+		if not (userfetch or userpriv):
+			return
+		if _userpriv_test_write_file(settings, write_test_file):
+			return
+
+	_userpriv_test_write_file_cache.pop(write_test_file, None)
+	if ensure_dirs(distdir, gid=dir_gid, mode=dirmode, mask=modemask):
+		if st is None:
+			# The directory has just been created
+			# and therefore it must be empty.
+			return
+		writemsg(_("Adjusting permissions recursively: '%s'\n") % distdir,
+			noiselevel=-1)
+		if not apply_recursive_permissions(distdir,
+			gid=dir_gid, dirmode=dirmode, dirmask=modemask,
+			filemode=filemode, filemask=modemask, onerror=_raise_exc):
+			raise OperationNotPermitted(
+				_("Failed to apply recursive permissions for the portage group."))
+
+
 def _checksum_failure_temp_file(settings, distdir, basename):
 	"""
 	First try to find a duplicate temp file with the same checksum and return
@@ -486,9 +539,7 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0,
 
 	features = mysettings.features
 	restrict = mysettings.get("PORTAGE_RESTRICT","").split()
-
-	userfetch = secpass >= 2 and "userfetch" in features
-	userpriv = secpass >= 2 and "userpriv" in features
+	userfetch = portage.data.secpass >= 2 and "userfetch" in features
 
 	# 'nomirror' is bad/negative logic. You Restrict mirroring, not no-mirroring.
 	restrict_mirror = "mirror" in restrict or "nomirror" in restrict
@@ -728,51 +779,8 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0,
 		can_fetch = False
 
 	if can_fetch and not fetch_to_ro:
-		global _userpriv_test_write_file_cache
-		dirmode  = 0o070
-		filemode =   0o60
-		modemask =    0o2
-		dir_gid = portage_gid
-		if "FAKED_MODE" in mysettings:
-			# When inside fakeroot, directories with portage's gid appear
-			# to have root's gid. Therefore, use root's gid instead of
-			# portage's gid to avoid spurrious permissions adjustments
-			# when inside fakeroot.
-			dir_gid = 0
-		distdir_dirs = [""]
 		try:
-			
-			for x in distdir_dirs:
-				mydir = os.path.join(mysettings["DISTDIR"], x)
-				write_test_file = os.path.join(
-					mydir, ".__portage_test_write__")
-
-				try:
-					st = os.stat(mydir)
-				except OSError:
-					st = None
-
-				if st is not None and stat.S_ISDIR(st.st_mode):
-					if not (userfetch or userpriv):
-						continue
-					if _userpriv_test_write_file(mysettings, write_test_file):
-						continue
-
-				_userpriv_test_write_file_cache.pop(write_test_file, None)
-				if ensure_dirs(mydir, gid=dir_gid, mode=dirmode, mask=modemask):
-					if st is None:
-						# The directory has just been created
-						# and therefore it must be empty.
-						continue
-					writemsg(_("Adjusting permissions recursively: '%s'\n") % mydir,
-						noiselevel=-1)
-					def onerror(e):
-						raise # bail out on the first error that occurs during recursion
-					if not apply_recursive_permissions(mydir,
-						gid=dir_gid, dirmode=dirmode, dirmask=modemask,
-						filemode=filemode, filemask=modemask, onerror=onerror):
-						raise OperationNotPermitted(
-							_("Failed to apply recursive permissions for the portage group."))
+			_ensure_distdir(mysettings, mysettings["DISTDIR"])
 		except PortageException as e:
 			if not os.path.isdir(mysettings["DISTDIR"]):
 				writemsg("!!! %s\n" % str(e), noiselevel=-1)


             reply	other threads:[~2020-02-15 20:29 UTC|newest]

Thread overview: 93+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-15 20:28 Zac Medico [this message]
  -- strict thread matches above, loose matches on Subject: below --
2024-08-07 14:39 [gentoo-commits] proj/portage:master commit in: lib/portage/package/ebuild/ Zac Medico
2024-07-19  5:41 Sam James
2024-06-17  0:25 Sam James
2024-06-17  0:20 Sam James
2024-03-24 22:20 Zac Medico
2023-12-20 14:04 Sam James
2023-12-20 14:04 Sam James
2023-12-20 14:04 Sam James
2023-12-10 22:01 Sam James
2023-10-22 22:46 Zac Medico
2023-10-16  5:15 Zac Medico
2023-10-13 10:33 Sam James
2023-10-13 10:19 Sam James
2023-10-13 10:19 Sam James
2023-08-19 15:05 Sam James
2023-06-14 19:23 Mike Gilbert
2023-06-14 19:23 Mike Gilbert
2023-02-17  0:53 Sam James
2023-01-27  8:38 Ulrich Müller
2023-01-02 20:45 Mike Gilbert
2022-07-12 23:33 Sam James
2022-06-12 18:25 Sam James
2021-12-11  2:54 Sam James
2021-12-11  2:54 Sam James
2021-11-15  8:34 Michał Górny
2021-11-08 22:37 Zac Medico
2021-10-28  5:00 Sam James
2021-10-28  4:52 Sam James
2021-10-03 19:31 Zac Medico
2021-09-28 11:25 Michał Górny
2021-09-28 11:19 Michał Górny
2021-09-28  7:21 Zac Medico
2021-09-27 20:51 Michał Górny
2021-09-08 10:17 Michał Górny
2021-08-05  8:47 Michał Górny
2021-06-20 18:54 Zac Medico
2021-06-05 18:08 Zac Medico
2021-06-05 18:08 Zac Medico
2021-05-31 19:54 Michał Górny
2021-05-24  5:25 Zac Medico
2021-02-25  9:33 Zac Medico
2021-02-24 15:14 Zac Medico
2021-02-22  5:32 Zac Medico
2021-01-17 13:15 Zac Medico
2021-01-10  3:24 Zac Medico
2020-11-02  1:34 Zac Medico
2020-09-14  7:23 Zac Medico
2020-08-03 21:42 Zac Medico
2020-08-03 21:42 Zac Medico
2020-08-03 19:30 Zac Medico
2020-08-03 19:30 Zac Medico
2020-08-03 19:30 Zac Medico
2020-05-31 23:58 Mike Gilbert
2020-05-31 21:17 Mike Gilbert
2020-05-31 20:34 Mike Gilbert
2020-05-18 19:23 Michał Górny
2020-05-06  6:37 Michał Górny
2020-03-23  1:49 Zac Medico
2020-03-23  1:40 Zac Medico
2020-03-15  1:24 Zac Medico
2020-03-02 16:53 Zac Medico
2020-03-02  4:48 Zac Medico
2020-02-15 20:44 Zac Medico
2019-12-09  7:03 Zac Medico
2019-10-29  1:17 Zac Medico
2019-10-24 19:31 Zac Medico
2019-10-21 17:49 Zac Medico
2019-10-20  9:26 Michał Górny
2019-10-19 23:52 Zac Medico
2019-10-14 20:45 Zac Medico
2019-10-14 20:35 Zac Medico
2019-10-14 20:13 Zac Medico
2019-10-13 19:50 Michał Górny
2019-09-03 15:36 Zac Medico
2019-09-02 20:13 Zac Medico
2019-08-20 23:43 Zac Medico
2019-08-14  1:40 Zac Medico
2019-07-30  7:09 Ulrich Müller
2019-06-18 17:14 Zac Medico
2019-06-10 19:01 Zac Medico
2019-01-21 22:20 Zac Medico
2019-01-01 20:58 Zac Medico
2018-12-20  4:29 Zac Medico
2018-12-07  0:41 Zac Medico
2018-11-19  6:43 Zac Medico
2018-11-09  3:22 Zac Medico
2018-10-10  7:58 Zac Medico
2018-10-08 21:41 Zac Medico
2018-08-20 23:11 Zac Medico
2018-08-17 22:35 Zac Medico
2018-08-12  2:31 Zac Medico
2018-08-11 21:06 Zac Medico

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1581798334.9b07545003fed649b1a0a8a9e5cb69d5e2fa4951.zmedico@gentoo \
    --to=zmedico@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox