summaryrefslogtreecommitdiff
path: root/eclass
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2019-07-25 08:16:42 +0200
committerMichał Górny <mgorny@gentoo.org>2019-07-27 11:49:49 +0200
commitb5be6cf9e6ac618c9ba413192486dedede9da3e1 (patch)
treec7a812ce117068f00c56615bb01bcb94c9e679f7 /eclass
parentvcs-snapshot.eclass: Add verbose einfo for unpacking (diff)
downloadgentoo-b5be6cf9e6ac618c9ba413192486dedede9da3e1.tar.gz
gentoo-b5be6cf9e6ac618c9ba413192486dedede9da3e1.tar.bz2
gentoo-b5be6cf9e6ac618c9ba413192486dedede9da3e1.zip
vcs-snapshot.eclass: Detect and report invalid directory structure
Detect when the archive does not contain a single top-level directory, and abort in that case. Otherwise, --strip-components would result in unpredictable mess. Signed-off-by: Michał Górny <mgorny@gentoo.org>
Diffstat (limited to 'eclass')
-rw-r--r--eclass/vcs-snapshot.eclass17
1 files changed, 15 insertions, 2 deletions
diff --git a/eclass/vcs-snapshot.eclass b/eclass/vcs-snapshot.eclass
index 312e9a4611e1..d3f7025fbb35 100644
--- a/eclass/vcs-snapshot.eclass
+++ b/eclass/vcs-snapshot.eclass
@@ -68,8 +68,21 @@ vcs-snapshot_src_unpack() {
debug-print "${FUNCNAME}: unpacking ${f} to ${destdir}"
- # XXX: check whether the directory structure inside is
- # fine? i.e. if the tarball has actually a parent dir.
+ local l topdirs=()
+ while read -r l; do
+ topdirs+=( "${l}" )
+ done < <(tar -t -f "${DISTDIR}/${f}" | cut -d/ -f1 | sort -u)
+ if [[ ${#topdirs[@]} -gt 1 ]]; then
+ eerror "The archive ${f} contains multiple or no top directory."
+ eerror "It is impossible for vcs-snapshot to unpack this correctly."
+ eerror "Top directories found:"
+ local d
+ for d in "${topdirs[@]}"; do
+ eerror " ${d}"
+ done
+ die "${FUNCNAME}: Invalid directory structure in archive ${f}"
+ fi
+
mkdir "${destdir}" || die
# -o (--no-same-owner) to avoid restoring original owner
einfo "Unpacking ${f}"