cdrom.eclass: Allow CDROM_NAMES changes before each cdrom_load_next_cd
authorJames Le Cuirot <chewi@gentoo.org>
Sun, 16 Apr 2017 09:56:09 +0000 (10:56 +0100)
committerJames Le Cuirot <chewi@gentoo.org>
Thu, 27 Apr 2017 21:41:22 +0000 (22:41 +0100)
This works around the lack of per-set disc names. Once the first disc
has been detected, ebuilds can adjust CDROM_NAMES to contain just the
names from the matched CDROM_SET.

eclass/cdrom.eclass

index 29418ecb1a86c4ddc41ff20634cff52e7c51a339..5e1fc23edfd9b72e3c278cfb8d18296e7141d5c1 100644 (file)
@@ -102,15 +102,7 @@ cdrom_get_cds() {
                einfo "export CD_ROOT=/mnt/cdrom"
                echo
        else
-               if [[ -n ${CDROM_NAMES} ]] ; then
-                       # Translate the CDROM_NAMES array into CDROM_NAME_#
-                       cdcnt=0
-                       while [[ ${cdcnt} -lt ${CDROM_TOTAL_CDS} ]] ; do
-                               ((++cdcnt))
-                               export CDROM_NAME_${cdcnt}="${CDROM_NAMES[$((${cdcnt}-1))]}"
-                       done
-               fi
-
+               _cdrom_set_names
                einfo "This package will need access to ${CDROM_TOTAL_CDS} cds."
                cdcnt=0
                while [[ ${cdcnt} -lt ${CDROM_TOTAL_CDS} ]] ; do
@@ -152,6 +144,8 @@ cdrom_load_next_cd() {
        local var
        ((++CDROM_CURRENT_CD))
 
+       _cdrom_set_names
+
        unset CDROM_ROOT
        var=CD_ROOT_${CDROM_CURRENT_CD}
        [[ -z ${!var} ]] && var="CD_ROOT"
@@ -268,4 +262,17 @@ _cdrom_glob_match() {
        )
 }
 
+# @FUNCTION: _cdrom_set_names
+# @INTERNAL
+# @DESCRIPTION:
+# Populate CDROM_NAME_# variables with the CDROM_NAMES array.
+_cdrom_set_names() {
+       if [[ -n ${CDROM_NAMES} ]] ; then
+               local i
+               for i in $(seq ${#CDROM_NAMES[@]}); do
+                       export CDROM_NAME_${i}="${CDROM_NAMES[$((${i} - 1))]}"
+               done
+       fi
+}
+
 fi