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 | 17 +++++++++++++++-- |
8 |
1 file changed, 15 insertions(+), 2 deletions(-) |
9 |
|
10 |
diff --git a/eclass/vcs-snapshot.eclass b/eclass/vcs-snapshot.eclass |
11 |
index 312e9a4611e1..33abd9a7c190 100644 |
12 |
--- a/eclass/vcs-snapshot.eclass |
13 |
+++ b/eclass/vcs-snapshot.eclass |
14 |
@@ -1,87 +1,100 @@ |
15 |
# Copyright 1999-2019 Gentoo Authors |
16 |
# Distributed under the terms of the GNU General Public License v2 |
17 |
|
18 |
# @ECLASS: vcs-snapshot.eclass |
19 |
# @MAINTAINER: |
20 |
# mgorny@g.o |
21 |
# @SUPPORTED_EAPIS: 0 1 2 3 4 5 6 7 |
22 |
# @BLURB: support eclass for unpacking VCS snapshot tarballs |
23 |
# @DESCRIPTION: |
24 |
# THIS ECLASS IS NOT NECESSARY FOR MODERN GITHUB AND GITLAB SNAPSHOTS. |
25 |
# THEIR DIRECTORY STRUCTURE IS ENTIRELY PREDICTABLE, SO UPDATE YOUR |
26 |
# EBUILD TO USE /ARCHIVE/ URI AND SET S IF NECESSARY. |
27 |
# |
28 |
# This eclass provides a convenience src_unpack() which does unpack all |
29 |
# the tarballs in SRC_URI to locations matching their (local) names, |
30 |
# discarding the original parent directory. |
31 |
# |
32 |
# The typical use case are VCS tag snapshots coming from BitBucket |
33 |
# (but not GitHub or GitLab). They have hash appended to the directory |
34 |
# name which makes extracting them a painful experience. But if you are |
35 |
# using a SRC_URI arrow to rename them (which quite likely you have to |
36 |
# do anyway), vcs-snapshot will just extract them into matching |
37 |
# directories. |
38 |
# |
39 |
# Please note that this eclass handles only tarballs (.tar, .tar.gz, |
40 |
# .tar.bz2 & .tar.xz). For any other file format (or suffix) it will |
41 |
# fall back to regular unpack. Support for additional formats may be |
42 |
# added in the future if necessary. |
43 |
# |
44 |
# @EXAMPLE: |
45 |
# |
46 |
# @CODE |
47 |
# EAPI=7 |
48 |
# inherit vcs-snapshot |
49 |
# |
50 |
# SRC_URI=" |
51 |
# https://bitbucket.org/foo/bar/get/${PV}.tar.bz2 -> ${P}.tar.bz2 |
52 |
# https://bitbucket.org/foo/bar-otherstuff/get/${PV}.tar.bz2 |
53 |
# -> ${P}-otherstuff.tar.bz2" |
54 |
# @CODE |
55 |
# |
56 |
# and however the tarballs were originally packed, all files will appear |
57 |
# in ${WORKDIR}/${P} and ${WORKDIR}/${P}-otherstuff respectively. |
58 |
|
59 |
case ${EAPI:-0} in |
60 |
0|1|2|3|4|5|6|7) ;; |
61 |
*) die "vcs-snapshot.eclass API in EAPI ${EAPI} not yet established." |
62 |
esac |
63 |
|
64 |
EXPORT_FUNCTIONS src_unpack |
65 |
|
66 |
# @FUNCTION: vcs-snapshot_src_unpack |
67 |
# @DESCRIPTION: |
68 |
# Extract all the archives from ${A}. The .tar, .tar.gz, .tar.bz2 |
69 |
# and .tar.xz archives will be unpacked to directories matching their |
70 |
# local names. Other archive types will be passed down to regular |
71 |
# unpack. |
72 |
vcs-snapshot_src_unpack() { |
73 |
debug-print-function ${FUNCNAME} "${@}" |
74 |
|
75 |
local f |
76 |
|
77 |
for f in ${A} |
78 |
do |
79 |
case "${f}" in |
80 |
*.tar|*.tar.gz|*.tar.bz2|*.tar.xz) |
81 |
local destdir=${WORKDIR}/${f%.tar*} |
82 |
|
83 |
debug-print "${FUNCNAME}: unpacking ${f} to ${destdir}" |
84 |
|
85 |
- # XXX: check whether the directory structure inside is |
86 |
- # fine? i.e. if the tarball has actually a parent dir. |
87 |
+ local l topdirs=() |
88 |
+ while read l; do |
89 |
+ topdirs+=( "${l}" ) |
90 |
+ done < <(tar -t -f "${DISTDIR}/${f}" | cut -d/ -f1 | sort -u) |
91 |
+ if [[ ${#topdirs[@]} -gt 1 ]]; then |
92 |
+ eerror "The archive ${f} contains multiple or no top directory." |
93 |
+ eerror "It is impossible for vcs-snapshot to unpack this correctly." |
94 |
+ eerror "Top directories found:" |
95 |
+ local d |
96 |
+ for d in "${topdirs[@]}"; do |
97 |
+ eerror " ${d}" |
98 |
+ done |
99 |
+ die "${FUNCNAME}: Invalid directory structure in archive ${f}" |
100 |
+ fi |
101 |
+ |
102 |
mkdir "${destdir}" || die |
103 |
# -o (--no-same-owner) to avoid restoring original owner |
104 |
einfo "Unpacking ${f}" |
105 |
tar -C "${destdir}" -x -o --strip-components 1 \ |
106 |
-f "${DISTDIR}/${f}" || die |
107 |
;; |
108 |
*) |
109 |
debug-print "${FUNCNAME}: falling back to unpack for ${f}" |
110 |
|
111 |
# fall back to the default method |
112 |
unpack "${f}" |
113 |
;; |
114 |
esac |
115 |
done |
116 |
} |
117 |
-- |
118 |
2.22.0 |