From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 5314A139694 for ; Tue, 18 Apr 2017 21:31:59 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 97E39E0DFD; Tue, 18 Apr 2017 21:31:46 +0000 (UTC) Received: from smtp.gentoo.org (mail.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 3E648E0DF3 for ; Tue, 18 Apr 2017 21:31:46 +0000 (UTC) Received: from symphony.aura-online.co.uk (154.189.187.81.in-addr.arpa [81.187.189.154]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: chewi) by smtp.gentoo.org (Postfix) with ESMTPSA id 7FCA9341674 for ; Tue, 18 Apr 2017 21:31:44 +0000 (UTC) Date: Tue, 18 Apr 2017 22:31:31 +0100 From: James Le Cuirot To: gentoo-dev@lists.gentoo.org Subject: Re: [gentoo-dev] [PATCH 01/14] cdrom.eclass: Detect case-insensitively and handle special characters Message-ID: <20170418223131.0f657dc2@symphony.aura-online.co.uk> In-Reply-To: <1492495724.1167.1.camel@gentoo.org> References: <20170417215359.30641-1-chewi@gentoo.org> <20170417215359.30641-2-chewi@gentoo.org> <1492495724.1167.1.camel@gentoo.org> X-Mailer: Claws Mail 3.14.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-dev@lists.gentoo.org Reply-to: gentoo-dev@lists.gentoo.org MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; boundary="Sig_/tiZy_zE7nyBsAYF/ee258dA"; protocol="application/pgp-signature" X-Archives-Salt: 62b0fde4-c8a3-40e5-9638-fce20a0df7d7 X-Archives-Hash: 9b9e3a5d550dfc37c8b963bf62ec35a0 --Sig_/tiZy_zE7nyBsAYF/ee258dA Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Tue, 18 Apr 2017 08:08:44 +0200 Micha=C5=82 G=C3=B3rny 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=3D${CD_ROOT_1:-${CD_ROOT}} > > einfo "Found CD #${CDROM_CURRENT_CD} root at ${CDROM_ROOT}" > > export CDROM_SET=3D-1 > > - for f in ${CDROM_CHECK_1//:/ } ; do > > + IFS=3D: =20 >=20 > '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=3D0 showjolietmsg=3D0 > > =20 > > while [[ -z ${CDROM_ROOT} ]] ; do > > - local i=3D0 > > - local -a cdset=3D(${*//:/ }) > > + local i=3D0 cdset > > + IFS=3D: read -a cdset <<< "${*}" =20 >=20 > -r to avoid handling escapes; -d '' to avoid finishing on newline. Good call. > > @@ -243,4 +240,27 @@ _cdrom_locate_file_on_cd() { > > done > > } > > =20 > > +# @FUNCTION: _cdrom_glob_match > > +# @USAGE: > > +# @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" b= ut > > +# 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. T= he > > +# first person to make this work without an eval wins a cookie. > > +_cdrom_glob_match() { > > + local p=3D\?\($(sed -e 's:[^A-Za-z0-9/]:\\\0:g' -e 's:/:)/?(:g' <<< "= $2" || die)\) =20 >=20 > 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. --=20 James Le Cuirot (chewi) Gentoo Linux Developer --Sig_/tiZy_zE7nyBsAYF/ee258dA Content-Type: application/pgp-signature Content-Description: OpenPGP digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQKTBAEBCgB9FiEEUo3mvYaRpDkf2i7UIcYyEpxtfeQFAlj2hbNfFIAAAAAALgAo aXNzdWVyLWZwckBub3RhdGlvbnMub3BlbnBncC5maWZ0aGhvcnNlbWFuLm5ldDUy OERFNkJEODY5MUE0MzkxRkRBMkVENDIxQzYzMjEyOUM2RDdERTQACgkQIcYyEpxt feRIeA//Vd7NGzIKwNQPqUAn4DQT+aYlP4oyme9OzgbSa/FtS/V3dl9ygJg0yvAA owKuFYVTN1gPziD/SWEuc87HiwgsdDtmNwrj9bo5mb6lbxB6EwRmvEuT68SDbO63 BuMSWMGE0VUyI030gR5MNnSl5/kxStfzvxIsg+ZcloI4DmVycBjEyPAUOrQWEUT6 XQT/P0W12pDIL/bYGRuHQWvKUehCHvuKyLSLNO0fnJZjafRW9mgR5fpalK26lIz1 OH4x+MhcThugdMGEtdfGIrmgVM+3RvhvZVko8X2G14tFpQSo6n36UjjWqvx5ijWz CpGQmX+O+JL2N6ZoqjHjNDlBA8NCv6HTS+Y4cEWC8t00USKL/CneXc72ILIxE+8N Y06gXCIV6ipVjQ0BPajUh0p7f4f5uhMIFVWj5+wvCB423NLUKnFOpYy7FWZMPlNf XmqjGAjKyRk6A7VJfCPA7y7wwzowZEquaAwjuxAbE1TATLaYdOsoznUqQfJqQyaZ +E9DEsGKS7Ja35vYoAewpuUk4DeAkd0tok25L+rbcbTZZyw5bBQKoguayLaTgelK Lo39PtowAC0DU9gQp8Cm2/XVqIUHhn/i7n3mpkGxulOx2RQcB7MVhvkN93KzROY4 Ja1dIjcS3y6v3tdELUNMmdGAcz+npolYU3Ej6aoeyoYPzT9n9sY= =73iF -----END PGP SIGNATURE----- --Sig_/tiZy_zE7nyBsAYF/ee258dA--