On Tue, 18 Apr 2017 08:08:44 +0200 Michał Górny <[email protected]> wrote:
> On pon, 2017-04-17 at 22:53 +0100, James Le Cuirot wrote:
> > diff --git a/eclass/cdrom.eclass b/eclass/cdrom.eclass
> > index 41488d2446c2..de72f15563db 100644
> > --- a/eclass/cdrom.eclass
> > +++ b/eclass/cdrom.eclass
> > @@ -79,12 +79,13 @@ cdrom_get_cds() {
> > export CDROM_ROOT=${CD_ROOT_1:-${CD_ROOT}}
> > einfo "Found CD #${CDROM_CURRENT_CD} root at ${CDROM_ROOT}"
> > export CDROM_SET=-1
> > - for f in ${CDROM_CHECK_1//:/ } ; do
> > + IFS=:
>
> 'local', please.
This line disappears later in the series but I've amended it for the
history anyway.
> > @@ -181,28 +182,24 @@ _cdrom_locate_file_on_cd() {
> > local showedmsg=0 showjolietmsg=0
> >
> > while [[ -z ${CDROM_ROOT} ]] ; do
> > - local i=0
> > - local -a cdset=(${*//:/ })
> > + local i=0 cdset
> > + IFS=: read -a cdset <<< "${*}"
>
> -r to avoid handling escapes; -d '' to avoid finishing on newline.
Good call.
> > @@ -243,4 +240,27 @@ _cdrom_locate_file_on_cd() {
> > done
> > }
> >
> > +# @FUNCTION: _cdrom_glob_match
> > +# @USAGE: <root directory> <path>
> > +# @INTERNAL
> > +# @DESCRIPTION:
> > +# Locates the given path ($2) within the given root directory ($1)
> > +# case-insensitively and returns the first actual matching path. This
> > +# eclass previously used "find -iname" but it only checked the file
> > +# case-insensitively and not the directories. There is "find -ipath" but
> > +# this does not intelligently skip non-matching paths, making it
> > +# slow. Case-insensitive matching can only be applied to patterns so
> > +# extended globbing is used to turn regular strings into patterns. All
> > +# special characters are escaped so don't worry about breaking this. The
> > +# first person to make this work without an eval wins a cookie.
> > +_cdrom_glob_match() {
> > + local p=\?\($(sed -e 's:[^A-Za-z0-9/]:\\\0:g' -e 's:/:)/?(:g' <<< "$2"
> > || die)\)
>
> Explanatory comment needed, i.e. what gets converted into what, and why.
I'll add this:
# The following line turns this:
# foo*foo/bar bar/baz/file.zip
#
# Into this:
# ?(foo\*foo)/?(bar\ bar)/?(baz)/?(file\.zip)
#
# This turns every path component into an escaped extended glob
# pattern to allow case-insensitive matching. Globs cannot span
# directories so each component becomes an individual pattern.
--
James Le Cuirot (chewi)
Gentoo Linux Developer
pgpkMgCgMuOu9.pgp
Description: OpenPGP digital signature
