Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-dev@l.g.o
Cc: "Michał Górny" <mgorny@g.o>
Subject: [gentoo-dev] [PATCH multibuild.eclass] multibuild_merge_root: use a more portable, simpler 'cp -PpR' call.
Date: Thu, 03 Apr 2014 22:30:52
Message-Id: 1396564231-18436-1-git-send-email-mgorny@gentoo.org
1 In the original multibuild.eclass code I tried to somehow achieve very
2 fast merging via avoiding actually copying anything. I used the 'cp -al'
3 call that used hardlinks to avoid copying data but that actually made
4 copying non-clobbering and less portable (BSD used a tar fallback, for
5 example, due to some bugs at the time).
6
7 While the original solution worked and was quite good for its initial
8 use, the fact that it is non-clobbering is a bit confusing and resulted
9 in late breakage in llvm ebuild (where I assumed it will clobber). I
10 think it's time to replace it with something simpler, more portable (no
11 more userland checks) and fully clobbering.
12
13 For this reason, the patch replaces the old code with a plain 'cp -PpR'
14 that should be POSIX-compliant. It also tries to use '--reflink=auto' if
15 available to make use of btrfs CoW support.
16
17 I'd appreciate very much of someone could put the code into thorough
18 testing. The consumers include all distutils-r1 ebuilds, multilib
19 ebuilds, PyQt4 and the reverted version of llvm :).
20 ---
21 eclass/multibuild.eclass | 24 ++++++++----------------
22 1 file changed, 8 insertions(+), 16 deletions(-)
23
24 diff --git a/eclass/multibuild.eclass b/eclass/multibuild.eclass
25 index 0a2771e..e3e5e21 100644
26 --- a/eclass/multibuild.eclass
27 +++ b/eclass/multibuild.eclass
28 @@ -265,24 +265,16 @@ multibuild_merge_root() {
29 done
30 rm "${lockfile_l}" || die
31
32 - if use userland_BSD; then
33 - # 'cp -a -n' is broken:
34 - # http://www.freebsd.org/cgi/query-pr.cgi?pr=174489
35 - # using tar instead which is universal but terribly slow.
36 -
37 - tar -C "${src}" -f - -c . \
38 - | tar -x -f - -C "${dest}"
39 - [[ ${PIPESTATUS[*]} == '0 0' ]]
40 - ret=${?}
41 - elif use userland_GNU; then
42 - # cp works with '-a -n'.
43 -
44 - cp -a -l -n "${src}"/. "${dest}"/
45 - ret=${?}
46 - else
47 - die "Unsupported userland (${USERLAND}), please report."
48 + local cp_args=()
49 +
50 + if cp --reflink=auto --version &>/dev/null; then
51 + # enable reflinking if possible to make this faster
52 + cp_args+=( --reflink=auto )
53 fi
54
55 + cp -P -R -p "${cp_args[@]}" "${src}"/. "${dest}"/
56 + ret=${?}
57 +
58 # Remove the lock.
59 rm "${lockfile}" || die
60
61 --
62 1.9.1

Replies