Skip to content

Commit

Permalink
vcs-snapshot.eclass: Detect and report invalid directory structure
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
mgorny committed Jul 27, 2019
1 parent 5e25faf commit b5be6cf
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions eclass/vcs-snapshot.eclass
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down

0 comments on commit b5be6cf

Please sign in to comment.