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 4/5] vcs-snapshot.eclass: Detect and report invalid directory structure
Date: Thu, 25 Jul 2019 06:26:25
Message-Id: 20190725062504.30140-4-mgorny@gentoo.org
In Reply to: [gentoo-dev] [PATCH 1/5] vcs-snapshot.eclass: Allow EAPI 7 by "Michał Górny"
1 Detect when the archive does not contain a single top-level directory,
2 and abort in that case. Otherwise, --strip-components would result
3 in unpredictable mess.
4
5 Signed-off-by: Michał Górny <mgorny@g.o>
6 ---
7 eclass/vcs-snapshot.eclass | 16 ++++++++++++++--
8 1 file changed, 14 insertions(+), 2 deletions(-)
9
10 diff --git a/eclass/vcs-snapshot.eclass b/eclass/vcs-snapshot.eclass
11 index 312e9a4611e1..dbca6fd586d2 100644
12 --- a/eclass/vcs-snapshot.eclass
13 +++ b/eclass/vcs-snapshot.eclass
14 @@ -68,8 +68,20 @@ vcs-snapshot_src_unpack() {
15
16 debug-print "${FUNCNAME}: unpacking ${f} to ${destdir}"
17
18 - # XXX: check whether the directory structure inside is
19 - # fine? i.e. if the tarball has actually a parent dir.
20 + local topdirs=()
21 + readarray -t topdirs \
22 + < <(tar -t -f "${DISTDIR}/${f}" | cut -d/ -f1 | sort -u)
23 + if [[ ${#topdirs[@]} -gt 1 ]]; then
24 + eerror "The archive ${f} contains multiple or no top directory."
25 + eerror "It is impossible for vcs-snapshot to unpack this correctly."
26 + eerror "Top directories found:"
27 + local d
28 + for d in "${topdirs[@]}"; do
29 + eerror " ${d}"
30 + done
31 + die "${FUNCNAME}: Invalid directory structure in archive ${f}"
32 + fi
33 +
34 mkdir "${destdir}" || die
35 # -o (--no-same-owner) to avoid restoring original owner
36 einfo "Unpacking ${f}"
37 --
38 2.22.0

Replies