Gentoo Archives: gentoo-dev

From: Alec Warner <antarus@g.o>
To: gentoo-dev@l.g.o
Cc: "Michał Górny" <mgorny@g.o>
Subject: Re: [gentoo-dev] [PATCH 1/2] Introduce multibuild_merge_root() to merge interim installs.
Date: Sat, 23 Mar 2013 17:45:05
Message-Id: CAAr7Pr9L2vk5+gFNNhQw8AJ9B72Z-tDV8UKWyuqvESdUaiGDnQ@mail.gmail.com
In Reply to: [gentoo-dev] [PATCH 1/2] Introduce multibuild_merge_root() to merge interim installs. by "Michał Górny"
1 On Sat, Mar 23, 2013 at 9:26 AM, Michał Górny <mgorny@g.o> wrote:
2 > This is mostly a copy from distutils-r1. The function does copy all the
3 > files from one location onto another, preserving whatever possible. It
4 > can be run in parallel too without the risk of race conditions.
5 > ---
6 > gx86/eclass/distutils-r1.eclass | 41 +------------------------------------
7 > gx86/eclass/multibuild.eclass | 45 +++++++++++++++++++++++++++++++++++++++++
8 > 2 files changed, 46 insertions(+), 40 deletions(-)
9 >
10 > diff --git a/gx86/eclass/distutils-r1.eclass b/gx86/eclass/distutils-r1.eclass
11 > index 0982e6c..3c21741 100644
12 > --- a/gx86/eclass/distutils-r1.eclass
13 > +++ b/gx86/eclass/distutils-r1.eclass
14 > @@ -449,49 +449,10 @@ distutils-r1_python_install() {
15 >
16 > if [[ ! ${DISTUTILS_SINGLE_IMPL} ]]; then
17 > _distutils-r1_rename_scripts "${root}"
18 > - _distutils-r1_merge_root "${root}" "${D}"
19 > + multibuild_merge_root "${root}" "${D}"
20 > fi
21 > }
22 >
23 > -# @FUNCTION: distutils-r1_merge_root
24 > -# @USAGE: <src-root> <dest-root>
25 > -# @INTERNAL
26 > -# @DESCRIPTION:
27 > -# Merge the directory tree from <src-root> to <dest-root>, removing
28 > -# the <src-root> in the process.
29 > -_distutils-r1_merge_root() {
30 > - local src=${1}
31 > - local dest=${2}
32 > -
33 > - local lockfile=${T}/distutils-r1-merge-lock
34 > -
35 > - if type -P lockf &>/dev/null; then
36 > - # On BSD, we have 'lockf' wrapper.
37 > - tar -C "${src}" -f - -c . \
38 > - | lockf "${lockfile}" tar -x -f - -C "${dest}"
39 > - else
40 > - local lock_fd
41 > - if type -P flock &>/dev/null; then
42 > - # On Linux, we have 'flock' which can lock fd.
43 > - redirect_alloc_fd lock_fd "${lockfile}" '>>'
44 > - flock ${lock_fd}
45 > - else
46 > - ewarn "distutils-r1: no locking service found, please report."
47 > - fi
48 > -
49 > - cp -a -l -n "${src}"/. "${dest}"/
50 > -
51 > - if [[ ${lock_fd} ]]; then
52 > - # Close the lock file when we are done with it.
53 > - # Prevents deadlock if we aren't in a subshell.
54 > - eval "exec ${lock_fd}>&-"
55 > - fi
56 > - fi
57 > - [[ ${?} == 0 ]] || die "Merging ${EPYTHON} image failed."
58 > -
59 > - rm -rf "${src}"
60 > -}
61 > -
62 > # @FUNCTION: distutils-r1_python_install_all
63 > # @DESCRIPTION:
64 > # The default python_install_all(). It installs the documentation.
65 > diff --git a/gx86/eclass/multibuild.eclass b/gx86/eclass/multibuild.eclass
66 > index a3f1402..ed837d3 100644
67 > --- a/gx86/eclass/multibuild.eclass
68 > +++ b/gx86/eclass/multibuild.eclass
69 > @@ -238,5 +238,50 @@ run_in_build_dir() {
70 > return ${ret}
71 > }
72 >
73 > +# @FUNCTION: multibuild_merge_root
74 > +# @USAGE: <src-root> <dest-root>
75 > +# @DESCRIPTION:
76 > +# Merge the directory tree (fake root) from <src-root> to <dest-root>
77 > +# (the real root). Both directories have to be real, absolute paths
78 > +# (i.e. including ${D}). Source root will be removed.
79 > +#
80 > +# This functions uses locking to support merging during parallel
81 > +# installs.
82 > +multibuild_merge_root() {
83 > + local src=${1}
84 > + local dest=${2}
85 > +
86 > + local lockfile=${T}/multibuild_merge_lock
87 > +
88 > + if type -P lockf &>/dev/null; then
89 > + # On BSD, we have 'lockf' wrapper.
90 > + tar -C "${src}" -f - -c . \
91 > + | lockf "${lockfile}" tar -x -f - -C "${dest}"
92 > + else
93 > + local lock_fd
94 > + if type -P flock &>/dev/null; then
95 > + # On Linux, we have 'flock' which can lock fd.
96 > + redirect_alloc_fd lock_fd "${lockfile}" '>>'
97 > + flock ${lock_fd}
98 > + else
99 > + ewarn "multibuild: no locking service found, please report."
100 > + fi
101 > +
102 > + cp -a -l -n "${src}"/. "${dest}"/
103 > +
104 > + if [[ ${lock_fd} ]]; then
105 > + # Close the lock file when we are done with it.
106 > + # Prevents deadlock if we aren't in a subshell.
107 > + eval "exec ${lock_fd}>&-"
108
109 Not following this bit.
110
111 The bash manpage says N>&DIGIT- redirects fd DIGIT to fd N. N may be
112 unspecified and defaults to 1.
113
114 It doesn't say what happens if DIGIT is unspecified. Nor does it say
115 it closes any file descriptors.
116
117 -A
118
119 > + fi
120 > + fi
121 > +
122 > + if [[ ${?} -ne 0 ]]; then
123 > + die "${MULTIBUILD_VARIANT:-(unknown)}: merging image failed."
124 > + fi
125 > +
126 > + rm -rf "${src}"
127 > +}
128 > +
129 > _MULTIBUILD=1
130 > fi
131 > --
132 > 1.8.1.5
133 >
134 >

Replies