Gentoo Archives: gentoo-portage-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-portage-dev@l.g.o
Cc: "Michał Górny" <mgorny@g.o>
Subject: [gentoo-portage-dev] [PATCH] Copy files/* into the work tree instead of symlinking it
Date: Sun, 26 Sep 2021 07:16:09
Message-Id: 20210926071601.325565-1-mgorny@gentoo.org
1 Symlinking FILESDIR into the work tree has the unintended consequence
2 of preserving all original file metadata, including system-specific ACLs
3 and so on. When these files are installed, this could lead to
4 unintentionally copying this metadata to the system and/or binary
5 packages.
6
7 Let's copy all files instead and drop metadata in the process. Since
8 FILESDIR is expected to be small by design, this shouldn't cause any
9 major trouble. It is also easier and less likely to cause regressions
10 than making sure stuff is not preserved when installing.
11
12 Unfortunately, a similar problem applies to DISTDIR. However,
13 installing files from DISTDIR is rarer than from FILESDIR, so I guess
14 we'll cross that bridge when we get to it.
15
16 Bug: https://bugs.gentoo.org/814857
17 Signed-off-by: Michał Górny <mgorny@g.o>
18 ---
19 bin/phase-functions.sh | 2 +-
20 lib/portage/package/ebuild/prepare_build_dirs.py | 15 ++++++---------
21 2 files changed, 7 insertions(+), 10 deletions(-)
22
23 diff --git a/bin/phase-functions.sh b/bin/phase-functions.sh
24 index d3221993d..9a4c97b16 100644
25 --- a/bin/phase-functions.sh
26 +++ b/bin/phase-functions.sh
27 @@ -296,7 +296,7 @@ __dyn_clean() {
28
29 rm -rf "${PORTAGE_BUILDDIR}/build-info"
30 rm -rf "${WORKDIR}"
31 - rm -f "${PORTAGE_BUILDDIR}/files"
32 + rm -rf "${PORTAGE_BUILDDIR}/files"
33 fi
34
35 if [ -f "${PORTAGE_BUILDDIR}/.unpacked" ]; then
36 diff --git a/lib/portage/package/ebuild/prepare_build_dirs.py b/lib/portage/package/ebuild/prepare_build_dirs.py
37 index 659198905..0e85ded8b 100644
38 --- a/lib/portage/package/ebuild/prepare_build_dirs.py
39 +++ b/lib/portage/package/ebuild/prepare_build_dirs.py
40 @@ -478,16 +478,13 @@ def _ensure_log_subdirs(logdir, subdir):
41
42 def _prepare_fake_filesdir(settings):
43 real_filesdir = settings["O"] + "/files"
44 - symlink_path = settings["FILESDIR"]
45 + filesdir = settings["FILESDIR"]
46 + portage.util.ensure_dirs(filesdir, mode=0o755)
47
48 - try:
49 - link_target = os.readlink(symlink_path)
50 - except OSError:
51 - os.symlink(real_filesdir, symlink_path)
52 - else:
53 - if link_target != real_filesdir:
54 - os.unlink(symlink_path)
55 - os.symlink(real_filesdir, symlink_path)
56 + # Copy files from real directory to ebuild directory (without metadata).
57 + shutil.copytree(
58 + real_filesdir, filesdir, copy_function=shutil.copyfile, dirs_exist_ok=True
59 + )
60
61
62 def _prepare_fake_distdir(settings, alist):
63 --
64 2.33.0