commit:     2fa008aae8571d525af1f5ca7cf4cce90d835826
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Sun Sep 26 07:07:32 2021 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Sun Sep 26 10:19:39 2021 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=2fa008aa

Copy files/* into the work tree instead of symlinking it

Symlinking FILESDIR into the work tree has the unintended consequence
of preserving all original file metadata, including system-specific ACLs
and so on.  When these files are installed, this could lead to
unintentionally copying this metadata to the system and/or binary
packages.

Let's copy all files instead and drop metadata in the process.  Since
FILESDIR is expected to be small by design, this shouldn't cause any
major trouble.  It is also easier and less likely to cause regressions
than making sure stuff is not preserved when installing.

Unfortunately, a similar problem applies to DISTDIR.  However,
installing files from DISTDIR is rarer than from FILESDIR, so I guess
we'll cross that bridge when we get to it.

Bug: https://bugs.gentoo.org/814857
Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>

 bin/phase-functions.sh                           |  2 +-
 lib/portage/package/ebuild/prepare_build_dirs.py | 19 +++++++++----------
 2 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/bin/phase-functions.sh b/bin/phase-functions.sh
index d3221993d..9a4c97b16 100644
--- a/bin/phase-functions.sh
+++ b/bin/phase-functions.sh
@@ -296,7 +296,7 @@ __dyn_clean() {
 
                rm -rf "${PORTAGE_BUILDDIR}/build-info"
                rm -rf "${WORKDIR}"
-               rm -f "${PORTAGE_BUILDDIR}/files"
+               rm -rf "${PORTAGE_BUILDDIR}/files"
        fi
 
        if [ -f "${PORTAGE_BUILDDIR}/.unpacked" ]; then

diff --git a/lib/portage/package/ebuild/prepare_build_dirs.py 
b/lib/portage/package/ebuild/prepare_build_dirs.py
index 659198905..2e2ef73f4 100644
--- a/lib/portage/package/ebuild/prepare_build_dirs.py
+++ b/lib/portage/package/ebuild/prepare_build_dirs.py
@@ -1,4 +1,4 @@
-# Copyright 2010-2020 Gentoo Authors
+# Copyright 2010-2021 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 __all__ = ["prepare_build_dirs"]
@@ -27,6 +27,7 @@ from portage.util import (
     normalize_path,
     writemsg,
 )
+from portage.util.file_copy import copyfile
 from portage.util.install_mask import _raise_exc
 
 
@@ -478,16 +479,14 @@ def _ensure_log_subdirs(logdir, subdir):
 
 def _prepare_fake_filesdir(settings):
     real_filesdir = settings["O"] + "/files"
-    symlink_path = settings["FILESDIR"]
+    filesdir = settings["FILESDIR"]
+    portage.util.ensure_dirs(filesdir, mode=0o755)
 
-    try:
-        link_target = os.readlink(symlink_path)
-    except OSError:
-        os.symlink(real_filesdir, symlink_path)
-    else:
-        if link_target != real_filesdir:
-            os.unlink(symlink_path)
-            os.symlink(real_filesdir, symlink_path)
+    # Copy files from real directory to ebuild directory (without metadata).
+    if os.path.isdir(real_filesdir):
+        shutil.copytree(
+            real_filesdir, filesdir, copy_function=copyfile, dirs_exist_ok=True
+        )
 
 
 def _prepare_fake_distdir(settings, alist):

Reply via email to