[pacman-dev] [PATCH] repo-add; add option to remove existing package files from disk

Dave Reisner d at falconindy.com
Thu May 30 11:23:29 EDT 2013


On Wed, May 29, 2013 at 09:13:26PM -0500, William Giokas wrote:
> On Thu, May 30, 2013 at 10:11:49AM +1000, Phillip Smith wrote:
> > From: Phillip Smith <fukawi2 at gmail.com>
> > 
> > when maintaining a custom repo, often it is undesirable to retain older
> > versions of packages. this patch adds the --remove option to remove the
> > current package file from disk before adding the new one to the
> > database.
> > 
> > Signed-off-by: Phillip Smith <fukawi2 at gmail.com>
> > ---
> >  scripts/repo-add.sh.in | 12 ++++++++++++
> >  1 file changed, 12 insertions(+)
> > 
> > diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in
> > index 4470dd0..2fdb165 100644
> > --- a/scripts/repo-add.sh.in
> > +++ b/scripts/repo-add.sh.in
> > @@ -31,6 +31,7 @@ declare -r confdir='@sysconfdir@'
> >  QUIET=0
> >  DELTA=0
> >  ONLYADDNEW=0
> > +RMEXISTING=0
> >  WITHFILES=0
> >  SIGN=0
> >  VERIFY=0
> > @@ -58,6 +59,7 @@ Multiple packages to add can be specified on the command line.\n")"
> >  		printf -- "$(gettext "Options:\n")"
> >  		printf -- "$(gettext "  -d, --delta       generate and add delta for package update\n")"
> >  		printf -- "$(gettext "  -n, --new         only add packages that are not already in the database\n")"
> > +		printf -- "$(gettext "  -R, --remove      remove any existing packages with the same name (eg, an older version)\n")"
> >  		printf -- "$(gettext "  -f, --files       update database's file list\n")"
> >  	elif [[ $cmd == "repo-remove" ]] ; then
> >  		printf -- "$(gettext "Usage: repo-remove [options] <path-to-db> <packagename|delta> ...\n")"
> > @@ -304,6 +306,15 @@ db_write_entry() {
> >  				local oldfilename=$(grep -A1 FILENAME "$pkgentry/desc" | tail -n1)
> >  				local oldfile="$(dirname "$1")/$oldfilename"
> >  			fi
> > +		elif (( RMEXISTING )); then
> > +			# only remove existing package if we're not doing deltas
> > +			pkgentry=$(find_pkgentry "$pkgname")
> > +			if [[ -n $pkgentry ]]; then
> > +				local oldfilename=$(grep -A1 FILENAME "$pkgentry/desc" | tail -n1)
> 
> Just one thing. Replace this with:
> 
>           local oldfilename="$(awk '/%FILENAME%/ {getline; print}')"

If you're going to go through the effort of "optimizing" this, then
there's 2 things wrong here:

- you're reading the entire output, when you only care a single line
- the execution time for sed is faster than awk in 99% of cases

so...
  oldfilename=$(sed -n '/^%FILENAME%$/ {n;p;q;}' "$pkgentry/desc")

I suppose if you wanted to stick with awk...

  oldfilename=$(awk '$0 == "%FILENAME%" { getline; print; exit; }' ...)

> 
> Yeah, the quotes aren't that important, but this way you save spawning a
> tail process when you could just do it with this. (I just had to do this
> to get pkgbase entries from db's in one of my pet scripts, so yeah)
> 
> > +				local oldfile="$(dirname "$1")/$oldfilename"
> > +				warning "$(gettext "Removed existing file '%s'")" "$oldfilename"
> > +				rm -f $oldfile
> > +			fi
> >  		fi
> >  	fi
> >  
> > @@ -611,6 +622,7 @@ while (( $# )); do
> >  		-q|--quiet) QUIET=1;;
> >  		-d|--delta) DELTA=1;;
> >  		-n|--new) ONLYADDNEW=1;;
> > +		-R|--remove) RMEXISTING=1;;
> >  		-f|--files) WITHFILES=1;;
> >  		--nocolor) USE_COLOR='n';;
> >  		-s|--sign)
> > -- 
> > 1.8.2.3
> > 
> > 
> 
> -- 
> William Giokas | KaiSforza
> GnuPG Key: 0x73CD09CF
> Fingerprint: F73F 50EF BBE2 9846 8306  E6B8 6902 06D8 73CD 09CF



> 



More information about the pacman-dev mailing list