Gentoo Archives: gentoo-commits

From: James Le Cuirot <chewi@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: eclass/
Date: Thu, 27 Apr 2017 21:42:28
Message-Id: 1493329284.8220a6a34dabb940f0b1998eabd27e763d66bb13.chewi@gentoo
1 commit: 8220a6a34dabb940f0b1998eabd27e763d66bb13
2 Author: James Le Cuirot <chewi <AT> gentoo <DOT> org>
3 AuthorDate: Sun Apr 16 11:43:08 2017 +0000
4 Commit: James Le Cuirot <chewi <AT> gentoo <DOT> org>
5 CommitDate: Thu Apr 27 21:41:24 2017 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=8220a6a3
7
8 cdrom.eclass: Make CD_ROOT less of a special case, fixes #195868
9
10 CD_ROOT was intended to be a power user feature so the eclass didn't
11 try very hard to check the validity of the given location. This
12 difference in behaviour ultimately made the eclass larger and more
13 confusing.
14
15 It now uses the same matching loop as the regular case, making it
16 simpler and more consistent. The only differences are that it doesn't
17 show information or prompts about inserting discs and it dies
18 immediately if a match cannot be found.
19
20 eclass/cdrom.eclass | 126 +++++++++++++++++++---------------------------------
21 1 file changed, 46 insertions(+), 80 deletions(-)
22
23 diff --git a/eclass/cdrom.eclass b/eclass/cdrom.eclass
24 index a56ec62b785..7d552f91996 100644
25 --- a/eclass/cdrom.eclass
26 +++ b/eclass/cdrom.eclass
27 @@ -48,44 +48,16 @@ fi
28 #
29 # For those multi cd ebuilds, see the cdrom_load_next_cd() function.
30 cdrom_get_cds() {
31 - # first we figure out how many cds we're dealing with by
32 - # the # of files they gave us
33 - local cdcnt=0
34 - local f=
35 - export CDROM_CURRENT_CD=1 CDROM_CHECKS=( "${@}" )
36 + unset CDROM_SET
37 + export CDROM_CURRENT_CD=0 CDROM_CHECKS=( "${@}" )
38
39 - # now we see if the user gave use CD_ROOT ...
40 - # if they did, let's just believe them that it's correct
41 + # If the user has set CD_ROOT or CD_ROOT_1, don't bother informing
42 + # them about which discs are needed as they presumably already know.
43 if [[ -n ${CD_ROOT}${CD_ROOT_1} ]] ; then
44 - local var=
45 - cdcnt=0
46 - while [[ ${cdcnt} -lt ${#} ]] ; do
47 - ((++cdcnt))
48 - var="CD_ROOT_${cdcnt}"
49 - [[ -z ${!var} ]] && var="CD_ROOT"
50 - if [[ -z ${!var} ]] ; then
51 - eerror "You must either use just the CD_ROOT"
52 - eerror "or specify ALL the CD_ROOT_X variables."
53 - eerror "In this case, you will need" \
54 - "${#} CD_ROOT_X variables."
55 - die "could not locate CD_ROOT_${cdcnt}"
56 - fi
57 - done
58 - export CDROM_ROOT=${CD_ROOT_1:-${CD_ROOT}}
59 - einfo "Found CD #${CDROM_CURRENT_CD} root at ${CDROM_ROOT}"
60 - export CDROM_SET=-1
61 - local IFS=:
62 - for f in ${CDROM_CHECKS[0]} ; do
63 - unset IFS
64 - ((++CDROM_SET))
65 - export CDROM_MATCH=$(_cdrom_glob_match "${CDROM_ROOT}" "${f}")
66 - [[ -n ${CDROM_MATCH} ]] && return
67 - done
68 - fi
69 + :
70
71 - # User didn't help us out so lets make sure they know they can
72 - # simplify the whole process ...
73 - if [[ ${#} -eq 1 ]] ; then
74 + # Single disc info.
75 + elif [[ ${#} -eq 1 ]] ; then
76 einfo "This ebuild will need the ${CDROM_NAME:-cdrom for ${PN}}"
77 echo
78 einfo "If you do not have the CD, but have the data files"
79 @@ -96,6 +68,8 @@ cdrom_get_cds() {
80 einfo "For example:"
81 einfo "export CD_ROOT=/mnt/cdrom"
82 echo
83 +
84 + # Multi disc info.
85 else
86 _cdrom_set_names
87 einfo "This package may need access to ${#} cds."
88 @@ -120,8 +94,7 @@ cdrom_get_cds() {
89 echo
90 fi
91
92 - export CDROM_SET=""
93 - export CDROM_CURRENT_CD=0
94 + # Scan for the first disc.
95 cdrom_load_next_cd
96 }
97
98 @@ -135,57 +108,48 @@ cdrom_get_cds() {
99 # in the CD list, so make sure you only call this function when you're
100 # done using the current CD.
101 cdrom_load_next_cd() {
102 - local var
103 - ((++CDROM_CURRENT_CD))
104 -
105 - _cdrom_set_names
106 + local showedmsg=0 showjolietmsg=0
107
108 unset CDROM_ROOT
109 - var=CD_ROOT_${CDROM_CURRENT_CD}
110 - [[ -z ${!var} ]] && var="CD_ROOT"
111 - if [[ -z ${!var} ]] ; then
112 - _cdrom_locate_file_on_cd "${CDROM_CHECKS[${CDROM_CURRENT_CD}]}"
113 - else
114 - export CDROM_ROOT=${!var}
115 - fi
116 -
117 - einfo "Found CD #${CDROM_CURRENT_CD} root at ${CDROM_ROOT}"
118 -}
119 -
120 -# this is used internally by the cdrom_get_cds() and cdrom_load_next_cd()
121 -# functions. this should *never* be called from an ebuild.
122 -# all it does is try to locate a give file on a cd ... if the cd isn't
123 -# found, then a message asking for the user to insert the cdrom will be
124 -# displayed and we'll hang out here until:
125 -# (1) the file is found on a mounted cdrom
126 -# (2) the user hits CTRL+C
127 -_cdrom_locate_file_on_cd() {
128 - local mline=""
129 - local showedmsg=0 showjolietmsg=0
130 + ((++CDROM_CURRENT_CD))
131
132 - while [[ -z ${CDROM_ROOT} ]] ; do
133 - local i=0 cdset
134 - IFS=: read -r -a cdset -d "" <<< "${*}"
135 + _cdrom_set_names
136
137 - if [[ -n ${CDROM_SET} ]] ; then
138 - cdset=( "${cdset[${CDROM_SET}]}" )
139 - fi
140 + while true ; do
141 + local i cdset
142 + : CD_ROOT_${CDROM_CURRENT_CD}
143 + export CDROM_ROOT=${CD_ROOT:-${!_}}
144 + IFS=: read -r -a cdset -d "" <<< "${CDROM_CHECKS[$((${CDROM_CURRENT_CD} - 1))]}"
145 +
146 + for i in $(seq ${CDROM_SET:-0} ${CDROM_SET:-$((${#cdset[@]} - 1))}); do
147 + local f=${cdset[${i}]} point= node= fs= opts=
148 +
149 + if [[ -z ${CDROM_ROOT} ]] ; then
150 + while read point node fs opts ; do
151 + has "${fs}" cd9660 iso9660 udf || continue
152 + point=${point//\040/ }
153 + export CDROM_MATCH=$(_cdrom_glob_match "${point}" "${f}")
154 + [[ -z ${CDROM_MATCH} ]] && continue
155 + export CDROM_ROOT=${point}
156 + done <<< "$(get_mounts)"
157 + else
158 + export CDROM_MATCH=$(_cdrom_glob_match "${CDROM_ROOT}" "${f}")
159 + fi
160
161 - while [[ -n ${cdset[${i}]} ]] ; do
162 - local point= node= fs= foo=
163 - while read point node fs foo ; do
164 - [[ " cd9660 iso9660 udf " != *" ${fs} "* ]] && continue
165 - point=${point//\040/ }
166 - export CDROM_MATCH=$(_cdrom_glob_match "${point}" "${cdset[${i}]}")
167 - [[ -z ${CDROM_MATCH} ]] && continue
168 - export CDROM_ROOT=${point}
169 + if [[ -n ${CDROM_MATCH} ]] ; then
170 + export CDROM_ABSMATCH=${CDROM_ROOT}/${CDROM_MATCH}
171 export CDROM_SET=${i}
172 - return
173 - done <<< "$(get_mounts)"
174 -
175 - ((++i))
176 + break 2
177 + fi
178 done
179
180 + # If we get here then we were unable to locate a match. If
181 + # CDROM_ROOT is non-empty then this implies that a CD_ROOT
182 + # variable was given and we should therefore abort immediately.
183 + if [[ -n ${CDROM_ROOT} ]] ; then
184 + die "unable to locate CD #${CDROM_CURRENT_CD} root at ${CDROM_ROOT}"
185 + fi
186 +
187 echo
188 if [[ ${showedmsg} -eq 0 ]] ; then
189 if [[ ${#CDROM_CHECKS[@]} -eq 1 ]] ; then
190 @@ -218,6 +182,8 @@ _cdrom_locate_file_on_cd() {
191 fi
192 read || die "something is screwed with your system"
193 done
194 +
195 + einfo "Found CD #${CDROM_CURRENT_CD} root at ${CDROM_ROOT}"
196 }
197
198 # @FUNCTION: _cdrom_glob_match