[pacman-dev] [PATCH 7/9] repo-add: avoid using ls to check for presence of files

Dave Reisner d at falconindy.com
Fri Jun 24 00:34:53 EDT 2011


On Thu, Jun 23, 2011 at 11:06:45PM -0500, Dan McGee wrote:
> On Wed, Jun 22, 2011 at 7:38 PM, Dave Reisner <d at falconindy.com> wrote:
> 
> I agree with the commit message, but damn is this ugly. Can't we drop
> the whole nullglob bit and just do something like:
> 
> contents=*
> if [[ $contents = "*" ]]; then
> 
> ?
> 

The * won't expand when assigned to a variable, only to an array. So, in
theory:

contents=(*)
if [[ $contents = "*" ]]; then

But the nullglob is safer. I'm pretty sure almost _anything_ that's
considered best practice in Bash is going to be ugly by your standards.

d

> > Signed-off-by: Dave Reisner <d at falconindy.com>
> > ---
> >  scripts/repo-add.sh.in |    2 +-
> >  1 files changed, 1 insertions(+), 1 deletions(-)
> >
> > diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in
> > index 029e17d..e75055f 100644
> > --- a/scripts/repo-add.sh.in
> > +++ b/scripts/repo-add.sh.in
> > @@ -593,7 +593,7 @@ if (( success )); then
> >        filename=${REPO_DB_FILE##*/}
> >
> >        pushd "$tmpdir" >/dev/null
> > -       if [[ -n $(ls) ]]; then
> > +       if ( shopt -s nullglob; files=(*); (( ${#files[*]} )) ); then
> >                bsdtar -c${TAR_OPT}f "$filename" *
> >        else
> >                # we have no packages remaining? zip up some emptyness
> > --
> > 1.7.5.4
> >
> >
> >
> 


More information about the pacman-dev mailing list