public inbox for gentoo-portage-dev@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Michał Górny" <mgorny@gentoo.org>
To: gentoo-portage-dev@lists.gentoo.org
Cc: "Michał Górny" <mgorny@gentoo.org>
Subject: [gentoo-portage-dev] [PATCH v2] Copy files/* into the work tree instead of symlinking it
Date: Sun, 26 Sep 2021 11:16:35 +0200	[thread overview]
Message-ID: <20210926091635.464632-1-mgorny@gentoo.org> (raw)

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@gentoo.org>
---
 bin/phase-functions.sh                           |  2 +-
 lib/portage/package/ebuild/prepare_build_dirs.py | 16 +++++++---------
 2 files changed, 8 insertions(+), 10 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..9d83bacad 100644
--- a/lib/portage/package/ebuild/prepare_build_dirs.py
+++ b/lib/portage/package/ebuild/prepare_build_dirs.py
@@ -478,16 +478,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=shutil.copyfile, dirs_exist_ok=True
+        )
 
 
 def _prepare_fake_distdir(settings, alist):
-- 
2.33.0



                 reply	other threads:[~2021-09-26  9:16 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20210926091635.464632-1-mgorny@gentoo.org \
    --to=mgorny@gentoo.org \
    --cc=gentoo-portage-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