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 -a' call.
Date: Fri, 04 Apr 2014 05:50:43
Message-Id: 1396590618-1402-1-git-send-email-mgorny@gentoo.org
In Reply to: Re: [gentoo-dev] [PATCH multibuild.eclass] multibuild_merge_root: use a more portable, simpler 'cp -PpR' call. by "Robin H. Johnson"
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 -a'
14 or 'cp -PpR' that should be POSIX-compliant. It also tries to use
15 '--reflink=auto' if 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 | 28 +++++++++++++---------------
22 1 file changed, 13 insertions(+), 15 deletions(-)
23
24 diff --git a/eclass/multibuild.eclass b/eclass/multibuild.eclass
25 index 0a2771e..be3ecf3 100644
26 --- a/eclass/multibuild.eclass
27 +++ b/eclass/multibuild.eclass
28 @@ -265,24 +265,22 @@ 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 + local cp_args=()
47 +
48 + if cp -a --version &>/dev/null; then
49 + cp_args+=( -a )
50 else
51 - die "Unsupported userland (${USERLAND}), please report."
52 + cp_args+=( -P -R -p )
53 + fi
54 +
55 + if cp --reflink=auto --version &>/dev/null; then
56 + # enable reflinking if possible to make this faster
57 + cp_args+=( --reflink=auto )
58 fi
59
60 + cp "${cp_args[@]}" "${src}"/. "${dest}"/
61 + ret=${?}
62 +
63 # Remove the lock.
64 rm "${lockfile}" || die
65
66 --
67 1.9.1

Replies