commit:     d55d415a4f68b0d2b0c4dca00cce2d9aee934faa
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sat Mar  9 22:01:18 2024 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sat Mar  9 22:49:03 2024 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=d55d415a

EbuildPhase/EbuildBinpkg: Ensure PKGDIR subdirectory permissions

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

 bin/misc-functions.sh        |  8 ++++++--
 lib/_emerge/EbuildBinpkg.py  |  3 ++-
 lib/_emerge/EbuildPhase.py   |  3 +++
 lib/portage/dbapi/bintree.py | 18 +++++++++++++-----
 4 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/bin/misc-functions.sh b/bin/misc-functions.sh
index 4ce3acbfdc..696f2a6133 100755
--- a/bin/misc-functions.sh
+++ b/bin/misc-functions.sh
@@ -1,5 +1,5 @@
 #!/usr/bin/env bash
-# Copyright 1999-2023 Gentoo Authors
+# Copyright 1999-2024 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 #
 # Miscellaneous shell functions that make use of the ebuild env but don't need
@@ -511,7 +511,11 @@ __dyn_package() {
        export SANDBOX_ON="0"
        [[ -z "${PORTAGE_BINPKG_TMPFILE}" ]] && \
                die "PORTAGE_BINPKG_TMPFILE is unset"
-       mkdir -p "${PORTAGE_BINPKG_TMPFILE%/*}" || die "mkdir failed"
+       if [[ ! -d ${PORTAGE_BINPKG_TMPFILE%/*} ]]; then
+               # Warn because we don't set PKGDIR directory permissions here.
+               ewarn "__dyn_package: Creating PORTAGE_BINPKG_TMPFILE parent 
dir: ${PORTAGE_BINPKG_TMPFILE%/*}"
+               mkdir -p "${PORTAGE_BINPKG_TMPFILE%/*}" || die "mkdir failed"
+       fi
 
        if [[ ! -z "${BUILD_ID}" ]]; then
                echo -n "${BUILD_ID}" > 
"${PORTAGE_BUILDDIR}"/build-info/BUILD_ID

diff --git a/lib/_emerge/EbuildBinpkg.py b/lib/_emerge/EbuildBinpkg.py
index 97b69ae018..26d828e4d2 100644
--- a/lib/_emerge/EbuildBinpkg.py
+++ b/lib/_emerge/EbuildBinpkg.py
@@ -1,4 +1,4 @@
-# Copyright 1999-2023 Gentoo Authors
+# Copyright 1999-2024 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 import io
@@ -29,6 +29,7 @@ class EbuildBinpkg(CompositeTask):
         pkg_allocated_path, build_id = bintree.getname_build_id(
             pkg.cpv, allocate_new=True
         )
+        bintree._ensure_dir(os.path.dirname(pkg_allocated_path))
 
         self.pkg_allocated_path = pkg_allocated_path
         self._binpkg_tmpfile = self.pkg_allocated_path + "." + 
str(portage.getpid())

diff --git a/lib/_emerge/EbuildPhase.py b/lib/_emerge/EbuildPhase.py
index 86a64be78e..73c284fe41 100644
--- a/lib/_emerge/EbuildPhase.py
+++ b/lib/_emerge/EbuildPhase.py
@@ -254,6 +254,9 @@ class EbuildPhase(CompositeTask):
                     )
                 else:
                     raise InvalidBinaryPackageFormat(binpkg_format)
+                self.settings.mycpv._db.bintree._ensure_dir(
+                    os.path.dirname(self.settings["PORTAGE_BINPKG_TMPFILE"])
+                )
 
     def _async_start_exit(self, task):
         task.future.cancelled() or task.future.result()

diff --git a/lib/portage/dbapi/bintree.py b/lib/portage/dbapi/bintree.py
index 4ba1407cda..7bc1f60f6d 100644
--- a/lib/portage/dbapi/bintree.py
+++ b/lib/portage/dbapi/bintree.py
@@ -72,6 +72,7 @@ import traceback
 import warnings
 from gzip import GzipFile
 from itertools import chain
+from pathlib import PurePath
 from urllib.parse import urlparse
 
 
@@ -839,11 +840,18 @@ class binarytree:
             return
         pkgdir_gid = pkgdir_st.st_gid
         pkgdir_grp_mode = 0o2070 & pkgdir_st.st_mode
-        try:
-            ensure_dirs(path, gid=pkgdir_gid, mode=pkgdir_grp_mode, mask=0)
-        except PortageException:
-            if not os.path.isdir(path):
-                raise
+
+        components = []
+        for component in PurePath(path).relative_to(self.pkgdir).parts:
+            components.append(component)
+            component_path = os.path.join(self.pkgdir, *components)
+            try:
+                ensure_dirs(
+                    component_path, gid=pkgdir_gid, mode=pkgdir_grp_mode, 
mask=0
+                )
+            except PortageException:
+                if not os.path.isdir(component_path):
+                    raise
 
     def _file_permissions(self, path):
         try:

Reply via email to