[pacman-dev] [PATCH] pacdiff - implement default search using local pacman db

Andrew Gregory andrew.gregory.8 at gmail.com
Sun Jun 30 23:22:24 EDT 2013


On 07/01/13 at 11:56am, Allan McRae wrote:
> On 19/06/13 15:55, Andrew Gregory wrote:
> > On 06/02/13 at 03:39pm, John Frazier wrote:
> >> Use pacman local db to find pacnews based on active configs. Relegate
> >> find to an option. Rename DIFFSEARCHPATH to DIFFFINDPATH to clarify use.
> >> Add quit option to prompts. Clarify help.
> >>
> >> ---
> >>  contrib/pacdiff.sh.in | 65 +++++++++++++++++++++++++++++++++++++--------------
> >>  1 file changed, 47 insertions(+), 18 deletions(-)
> >>
> >> diff --git a/contrib/pacdiff.sh.in b/contrib/pacdiff.sh.in
> >> index 47779d6..25c3fd6 100644
> >> --- a/contrib/pacdiff.sh.in
> >> +++ b/contrib/pacdiff.sh.in
> >> @@ -22,8 +22,8 @@ declare -r myname='pacdiff'
> >>  declare -r myver='@PACKAGE_VERSION@'
> >>  
> >>  diffprog=${DIFFPROG:-vimdiff}
> >> -diffsearchpath=${DIFFSEARCHPATH:-/etc}
> >> -locate=0
> >> +difffindpath=${DIFFFINDPATH:-/etc}
> >> +diffpacmandb=${DIFFPACMANDB:-/var/lib/pacman}
> > 
> > Check our other scripts.  They parse DBPath from pacman.conf
> > 
> >>  USE_COLOR='y'
> >>  
> >>  m4_include(../scripts/library/output_format.sh)
> >> @@ -32,11 +32,21 @@ m4_include(../scripts/library/term_colors.sh)
> >>  
> >>  usage() {
> >>  	echo "$myname : a simple pacnew/pacorig/pacsave updater"
> >> -	echo "Usage : $myname [-l]"
> >> -	echo "  -l/--locate makes $myname use locate rather than find"
> >> -	echo "  DIFFPROG variable allows to override the default vimdiff"
> >> -	echo "  DIFFSEARCHPATH allows to override the default /etc path"
> >> -	echo "Example : DIFFPROG=meld DIFFSEARCHPATH=\"/boot /etc /usr\" $myname"
> >> +	echo ""
> >> +	echo "Usage : $myname [-lf]"
> >> +	echo "  -l/--locate makes $myname search using locate"
> >> +	echo "  -f/--find   makes $myname search using find"
> >> +	echo ""
> >> +	echo "Note: the default search looks for backup files in the local pacman db"
> >> +	echo "      this generally will not find *.pacsave files"
> >> +	echo ""
> >> +	echo "  DIFFPROG variable will override the default editor: vimdiff"
> >> +	echo "  DIFFFINDPATH will override the default path when using --find"
> >> +	echo "  DIFFPACMANDB will override the default pacman db for the "
> >> +	echo "    default search type"
> >> +	echo ""
> >> +	echo "Example : DDIFFPROG=meld DIFFPACMANDB=/mnt/var/lib/pacman/ $myname"
> >> +	echo "Example : DIFFFINDPATH=\"/boot /etc /usr\" $myname"
> >>  }
> >>  
> >>  version() {
> >> @@ -45,18 +55,12 @@ version() {
> >>  	echo 'Copyright (C) 2013 Pacman Development Team <pacman-dev at archlinux.org>'
> >>  }
> >>  
> >> -cmd() {
> >> -	if [ $locate -eq 1 ]; then
> >> -		locate -0 -e -b \*.pacnew \*.pacorig \*.pacsave
> >> -	else
> >> -		find $diffsearchpath \( -name \*.pacnew -o -name \*.pacorig -o -name \*.pacsave \) -print0
> >> -	fi
> >> -}
> >> -
> >>  if [ $# -gt 0 ]; then
> >>  	case $1 in
> >>  		-l|--locate)
> >> -		locate=1;;
> >> +			locate=$(type -P locate);;
> >> +		-f|--find)
> >> +			find=$(type -P find);;
> >>  		-V|--version)
> >>  		version; exit 0;;
> >>  		-h|--help)
> >> @@ -66,6 +70,30 @@ if [ $# -gt 0 ]; then
> >>  	esac
> >>  fi
> >>  
> >> +check_backup() {
> >> +  [[ -f $1 ]] && printf "$1"'\0'
> >> +}
> >> +
> >> +cmd() {
> >> +	if [[ -n $locate ]]; then
> >> +		locate -0 -e -b \*.pacnew \*.pacorig \*.pacsave
> >> +	elif [[ -n $find ]]; then
> >> +		find "${difffindpath}" \( -name \*.pacnew -o -name \*.pacorig -o -name \*.pacsave \) -print0 2> /dev/null
> >> +	else
> >> +		# parse local pacman db for backup files and look for pac* based on them
> >> +		awk '/^%BACKUP%$/ {
> >> +			while (getline) {
> >> +				if (/^$/) { nextfile }
> >> +				print $1
> >> +			}
> >> +		}' "${diffpacmandb}"/local/*/files | while read -r bkup; do
> >> +			check_backup "/$bkup.pacnew"
> >> +			check_backup "/$bkup.pacorig"
> >> +			check_backup "/$bkup.pacsave"
> > 
> > I'm not sure checking for exact matches is the best solution here.
> > Pacman can save multiple .pacsave files with an increasing extension
> > which this (and our existing searches) will miss.
> > 
> 
> I missed this comment before.  Correct me if I am wrong, but the latest
> file is always .pacsave, and older ones are renamed .pacsave.1
> .pacsave.2 ...
> 
> So we should just be looking at .pacsave here?
> 
> Allan
> 

Since we consider .pacsave's important enough to keep previous
versions, I would expect this to deal with older versions as well, or
at least mention that they exist.  You're right though that .pacsave
is generally going to be the most important one, so it would be okay
to look at just it.

apg


More information about the pacman-dev mailing list