[pacman-dev] [PATCH 1/2] pacdiff: Search and give warnings for older pacsave.[0-9] files
Signed-off-by: Jonathan Frazier <eyeswide@gmail.com> --- contrib/pacdiff.sh.in | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/contrib/pacdiff.sh.in b/contrib/pacdiff.sh.in index 47779d6..1c24804 100644 --- a/contrib/pacdiff.sh.in +++ b/contrib/pacdiff.sh.in @@ -47,9 +47,9 @@ version() { cmd() { if [ $locate -eq 1 ]; then - locate -0 -e -b \*.pacnew \*.pacorig \*.pacsave + locate -0 -e -b \*.pacnew \*.pacorig \*.pacsave '*.pacsave.[0-9]' else - find $diffsearchpath \( -name \*.pacnew -o -name \*.pacorig -o -name \*.pacsave \) -print0 + find $diffsearchpath \( -name \*.pacnew -o -name \*.pacorig -o -name \*.pacsave '*.pacsave.[0-9]' \) -print0 fi } @@ -97,6 +97,8 @@ while IFS= read -u 3 -r -d '' pacfile; do fi done 3< <(cmd) +(( ${#oldsaves[@]} > 0 )) && warning "Ignoring %s" "${oldsaves[@]}" + exit 0 # vim: set ts=2 sw=2 noet: -- 1.8.3.2
Signed-off-by: Jonathan Frazier <eyeswide@gmail.com> --- contrib/pacdiff.sh.in | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/contrib/pacdiff.sh.in b/contrib/pacdiff.sh.in index 1c24804..a2327c8 100644 --- a/contrib/pacdiff.sh.in +++ b/contrib/pacdiff.sh.in @@ -82,16 +82,17 @@ while IFS= read -u 3 -r -d '' pacfile; do msg2 "Files are identical, removing..." rm -v "$pacfile" else - ask "(V)iew, (S)kip, (R)emove %s, (O)verwrite with %s: [v/s/r/o] " "$file_type" "$file_type" + ask "(V)iew, (S)kip, (R)emove %s, (O)verwrite with %s, (Q)uit: [v/s/r/o/q] " "$file_type" "$file_type" while read c; do case $c in + q|Q) exit 0;; r|R) rm -v "$pacfile"; break ;; o|O) mv -v "$pacfile" "$file"; break ;; v|V) $diffprog "$pacfile" "$file" rm -iv "$pacfile"; break ;; s|S) break ;; - *) ask "Invalid answer. Try again: [v/s/r/o] "; continue ;; + *) ask "Invalid answer. Try again: [v/s/r/o/q] "; continue ;; esac done fi -- 1.8.3.2
On Thu, Jul 11, 2013 at 01:03:35PM -0400, Jonathan Frazier wrote:
Signed-off-by: Jonathan Frazier <eyeswide@gmail.com> --- contrib/pacdiff.sh.in | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/contrib/pacdiff.sh.in b/contrib/pacdiff.sh.in index 47779d6..1c24804 100644 --- a/contrib/pacdiff.sh.in +++ b/contrib/pacdiff.sh.in @@ -47,9 +47,9 @@ version() {
cmd() { if [ $locate -eq 1 ]; then - locate -0 -e -b \*.pacnew \*.pacorig \*.pacsave + locate -0 -e -b \*.pacnew \*.pacorig \*.pacsave '*.pacsave.[0-9]' else - find $diffsearchpath \( -name \*.pacnew -o -name \*.pacorig -o -name \*.pacsave \) -print0 + find $diffsearchpath \( -name \*.pacnew -o -name \*.pacorig -o -name \*.pacsave '*.pacsave.[0-9]' \) -print0
Please test your work. This is a syntax error.
fi }
@@ -97,6 +97,8 @@ while IFS= read -u 3 -r -d '' pacfile; do fi done 3< <(cmd)
+(( ${#oldsaves[@]} > 0 )) && warning "Ignoring %s" "${oldsaves[@]}" + exit 0
# vim: set ts=2 sw=2 noet: -- 1.8.3.2
Signed-off-by: Jonathan Frazier <eyeswide@gmail.com> --- contrib/pacdiff.sh.in | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/contrib/pacdiff.sh.in b/contrib/pacdiff.sh.in index 47779d6..1c413c1 100644 --- a/contrib/pacdiff.sh.in +++ b/contrib/pacdiff.sh.in @@ -47,9 +47,9 @@ version() { cmd() { if [ $locate -eq 1 ]; then - locate -0 -e -b \*.pacnew \*.pacorig \*.pacsave + locate -0 -e -b \*.pacnew \*.pacorig \*.pacsave '*.pacsave.[0-9]' else - find $diffsearchpath \( -name \*.pacnew -o -name \*.pacorig -o -name \*.pacsave \) -print0 + find $diffsearchpath \( -name \*.pacnew -o -name \*.pacorig -o -name \*.pacsave -o -name '*.pacsave.[0-9]' \) -print0 fi } @@ -71,6 +71,12 @@ while IFS= read -u 3 -r -d '' pacfile; do file="${pacfile%.pac*}" file_type="pac${pacfile##*.pac}" + # add matches for pacsave.N to oldsaves array, do not prompt + if [ "${file_type%%[[:digit:]]*}" == "pacsave." ]; then + oldsaves+=("$pacfile") + continue + fi + msg "%s file found for %s" "$file_type" "$file" if [ ! -f "$file" ]; then warning "$file does not exist" @@ -97,6 +103,8 @@ while IFS= read -u 3 -r -d '' pacfile; do fi done 3< <(cmd) +(( ${#oldsaves[@]} > 0 )) && warning "Ignoring %s" "${oldsaves[@]}" + exit 0 # vim: set ts=2 sw=2 noet: -- 1.8.3.2
On Thu, Jul 11, 2013 at 01:47:41PM -0400, Jonathan Frazier wrote:
Signed-off-by: Jonathan Frazier <eyeswide@gmail.com> --- contrib/pacdiff.sh.in | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/contrib/pacdiff.sh.in b/contrib/pacdiff.sh.in index 47779d6..1c413c1 100644 --- a/contrib/pacdiff.sh.in +++ b/contrib/pacdiff.sh.in @@ -47,9 +47,9 @@ version() {
cmd() { if [ $locate -eq 1 ]; then - locate -0 -e -b \*.pacnew \*.pacorig \*.pacsave + locate -0 -e -b \*.pacnew \*.pacorig \*.pacsave '*.pacsave.[0-9]' else - find $diffsearchpath \( -name \*.pacnew -o -name \*.pacorig -o -name \*.pacsave \) -print0 + find $diffsearchpath \( -name \*.pacnew -o -name \*.pacorig -o -name \*.pacsave -o -name '*.pacsave.[0-9]' \) -print0 fi }
@@ -71,6 +71,12 @@ while IFS= read -u 3 -r -d '' pacfile; do file="${pacfile%.pac*}" file_type="pac${pacfile##*.pac}"
+ # add matches for pacsave.N to oldsaves array, do not prompt + if [ "${file_type%%[[:digit:]]*}" == "pacsave." ]; then
If you used a bash test here, you could write this as: if [[ $file_type = pacsave.+([0-9]) ]]; then ...which I think is much more readable, and accurate.
+ oldsaves+=("$pacfile") + continue + fi + msg "%s file found for %s" "$file_type" "$file" if [ ! -f "$file" ]; then warning "$file does not exist" @@ -97,6 +103,8 @@ while IFS= read -u 3 -r -d '' pacfile; do fi done 3< <(cmd)
+(( ${#oldsaves[@]} > 0 )) && warning "Ignoring %s" "${oldsaves[@]}" + exit 0
# vim: set ts=2 sw=2 noet: -- 1.8.3.2
Signed-off-by: Jonathan Frazier <eyeswide@gmail.com> --- contrib/pacdiff.sh.in | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/contrib/pacdiff.sh.in b/contrib/pacdiff.sh.in index 47779d6..a2c9cad 100644 --- a/contrib/pacdiff.sh.in +++ b/contrib/pacdiff.sh.in @@ -47,9 +47,9 @@ version() { cmd() { if [ $locate -eq 1 ]; then - locate -0 -e -b \*.pacnew \*.pacorig \*.pacsave + locate -0 -e -b \*.pacnew \*.pacorig \*.pacsave '*.pacsave.[0-9]' else - find $diffsearchpath \( -name \*.pacnew -o -name \*.pacorig -o -name \*.pacsave \) -print0 + find $diffsearchpath \( -name \*.pacnew -o -name \*.pacorig -o -name \*.pacsave -o -name '*.pacsave.[0-9]' \) -print0 fi } @@ -71,6 +71,12 @@ while IFS= read -u 3 -r -d '' pacfile; do file="${pacfile%.pac*}" file_type="pac${pacfile##*.pac}" + # add matches for pacsave.N to oldsaves array, do not prompt + if [[ $file_type = pacsave.+([0-9]) ]]; then + oldsaves+=("$pacfile") + continue + fi + msg "%s file found for %s" "$file_type" "$file" if [ ! -f "$file" ]; then warning "$file does not exist" @@ -97,6 +103,8 @@ while IFS= read -u 3 -r -d '' pacfile; do fi done 3< <(cmd) +(( ${#oldsaves[@]} > 0 )) && warning "Ignoring %s" "${oldsaves[@]}" + exit 0 # vim: set ts=2 sw=2 noet: -- 1.8.3.2
On 07/11/13 at 02:15pm, Jonathan Frazier wrote:
Signed-off-by: Jonathan Frazier <eyeswide@gmail.com> --- contrib/pacdiff.sh.in | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/contrib/pacdiff.sh.in b/contrib/pacdiff.sh.in index 47779d6..a2c9cad 100644 --- a/contrib/pacdiff.sh.in +++ b/contrib/pacdiff.sh.in @@ -47,9 +47,9 @@ version() {
cmd() { if [ $locate -eq 1 ]; then - locate -0 -e -b \*.pacnew \*.pacorig \*.pacsave + locate -0 -e -b \*.pacnew \*.pacorig \*.pacsave '*.pacsave.[0-9]' else - find $diffsearchpath \( -name \*.pacnew -o -name \*.pacorig -o -name \*.pacsave \) -print0 + find $diffsearchpath \( -name \*.pacnew -o -name \*.pacorig -o -name \*.pacsave -o -name '*.pacsave.[0-9]' \) -print0 fi }
@@ -71,6 +71,12 @@ while IFS= read -u 3 -r -d '' pacfile; do file="${pacfile%.pac*}" file_type="pac${pacfile##*.pac}"
+ # add matches for pacsave.N to oldsaves array, do not prompt
You've got a tab in the middle there.
+ if [[ $file_type = pacsave.+([0-9]) ]]; then
Need to indent that with a tab instead of spaces.
+ oldsaves+=("$pacfile")
Is there any reason not to just go ahead and print the "Ignoring..." warning here instead of saving them?
+ continue + fi + msg "%s file found for %s" "$file_type" "$file" if [ ! -f "$file" ]; then warning "$file does not exist" @@ -97,6 +103,8 @@ while IFS= read -u 3 -r -d '' pacfile; do fi done 3< <(cmd)
+(( ${#oldsaves[@]} > 0 )) && warning "Ignoring %s" "${oldsaves[@]}" + exit 0
# vim: set ts=2 sw=2 noet: -- 1.8.3.2
On 07/11/13 at 02:30pm, Andrew Gregory wrote:
On 07/11/13 at 02:15pm, Jonathan Frazier wrote:
Signed-off-by: Jonathan Frazier <eyeswide@gmail.com> --- contrib/pacdiff.sh.in | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/contrib/pacdiff.sh.in b/contrib/pacdiff.sh.in index 47779d6..a2c9cad 100644 --- a/contrib/pacdiff.sh.in +++ b/contrib/pacdiff.sh.in @@ -47,9 +47,9 @@ version() {
cmd() { if [ $locate -eq 1 ]; then - locate -0 -e -b \*.pacnew \*.pacorig \*.pacsave + locate -0 -e -b \*.pacnew \*.pacorig \*.pacsave '*.pacsave.[0-9]' else - find $diffsearchpath \( -name \*.pacnew -o -name \*.pacorig -o -name \*.pacsave \) -print0 + find $diffsearchpath \( -name \*.pacnew -o -name \*.pacorig -o -name \*.pacsave -o -name '*.pacsave.[0-9]' \) -print0 fi }
@@ -71,6 +71,12 @@ while IFS= read -u 3 -r -d '' pacfile; do file="${pacfile%.pac*}" file_type="pac${pacfile##*.pac}"
+ # add matches for pacsave.N to oldsaves array, do not prompt
You've got a tab in the middle there.
+ if [[ $file_type = pacsave.+([0-9]) ]]; then
Need to indent that with a tab instead of spaces.
+ oldsaves+=("$pacfile")
Is there any reason not to just go ahead and print the "Ignoring..." warning here instead of saving them?
It is neater, and at some point I wanted to do something better than just printing a warning for each them. whether it is showing n found instead of all of them. or some merging magic rather than just merging the latest pacnew.
+ continue + fi + msg "%s file found for %s" "$file_type" "$file" if [ ! -f "$file" ]; then warning "$file does not exist" @@ -97,6 +103,8 @@ while IFS= read -u 3 -r -d '' pacfile; do fi done 3< <(cmd)
+(( ${#oldsaves[@]} > 0 )) && warning "Ignoring %s" "${oldsaves[@]}" + exit 0
# vim: set ts=2 sw=2 noet: -- 1.8.3.2
Signed-off-by: Jonathan Frazier <eyeswide@gmail.com> --- contrib/pacdiff.sh.in | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/contrib/pacdiff.sh.in b/contrib/pacdiff.sh.in index 47779d6..a2c9cad 100644 --- a/contrib/pacdiff.sh.in +++ b/contrib/pacdiff.sh.in @@ -47,9 +47,9 @@ version() { cmd() { if [ $locate -eq 1 ]; then - locate -0 -e -b \*.pacnew \*.pacorig \*.pacsave + locate -0 -e -b \*.pacnew \*.pacorig \*.pacsave '*.pacsave.[0-9]' else - find $diffsearchpath \( -name \*.pacnew -o -name \*.pacorig -o -name \*.pacsave \) -print0 + find $diffsearchpath \( -name \*.pacnew -o -name \*.pacorig -o -name \*.pacsave -o -name '*.pacsave.[0-9]' \) -print0 fi } @@ -71,6 +71,12 @@ while IFS= read -u 3 -r -d '' pacfile; do file="${pacfile%.pac*}" file_type="pac${pacfile##*.pac}" + # add matches for pacsave.N to oldsaves array, do not prompt + if [[ $file_type = pacsave.+([0-9]) ]]; then + oldsaves+=("$pacfile") + continue + fi + msg "%s file found for %s" "$file_type" "$file" if [ ! -f "$file" ]; then warning "$file does not exist" @@ -97,6 +103,8 @@ while IFS= read -u 3 -r -d '' pacfile; do fi done 3< <(cmd) +(( ${#oldsaves[@]} > 0 )) && warning "Ignoring %s" "${oldsaves[@]}" + exit 0 # vim: set ts=2 sw=2 noet: -- 1.8.3.2
ignore this one... On 07/11/13 at 06:08pm, Jonathan Frazier wrote:
Signed-off-by: Jonathan Frazier <eyeswide@gmail.com> --- contrib/pacdiff.sh.in | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/contrib/pacdiff.sh.in b/contrib/pacdiff.sh.in index 47779d6..a2c9cad 100644 --- a/contrib/pacdiff.sh.in +++ b/contrib/pacdiff.sh.in @@ -47,9 +47,9 @@ version() {
cmd() { if [ $locate -eq 1 ]; then - locate -0 -e -b \*.pacnew \*.pacorig \*.pacsave + locate -0 -e -b \*.pacnew \*.pacorig \*.pacsave '*.pacsave.[0-9]' else - find $diffsearchpath \( -name \*.pacnew -o -name \*.pacorig -o -name \*.pacsave \) -print0 + find $diffsearchpath \( -name \*.pacnew -o -name \*.pacorig -o -name \*.pacsave -o -name '*.pacsave.[0-9]' \) -print0 fi }
@@ -71,6 +71,12 @@ while IFS= read -u 3 -r -d '' pacfile; do file="${pacfile%.pac*}" file_type="pac${pacfile##*.pac}"
+ # add matches for pacsave.N to oldsaves array, do not prompt + if [[ $file_type = pacsave.+([0-9]) ]]; then + oldsaves+=("$pacfile") + continue + fi + msg "%s file found for %s" "$file_type" "$file" if [ ! -f "$file" ]; then warning "$file does not exist" @@ -97,6 +103,8 @@ while IFS= read -u 3 -r -d '' pacfile; do fi done 3< <(cmd)
+(( ${#oldsaves[@]} > 0 )) && warning "Ignoring %s" "${oldsaves[@]}" + exit 0
# vim: set ts=2 sw=2 noet: -- 1.8.3.2
On Thu, Jul 11, 2013 at 5:08 PM, Jonathan Frazier <eyeswide@gmail.com> wrote:
Signed-off-by: Jonathan Frazier <eyeswide@gmail.com> --- contrib/pacdiff.sh.in | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
I'm hoping I'm reading this wrong or haven't had enough coffee yet since it got Ack-ed by Allan, but doesn't this totally fail when pacsave files roll over from foo.conf.9 to foo.conf.10? This is 100% supported by the match and move behavior in libalpm's code in remove.c.
diff --git a/contrib/pacdiff.sh.in b/contrib/pacdiff.sh.in index 47779d6..a2c9cad 100644 --- a/contrib/pacdiff.sh.in +++ b/contrib/pacdiff.sh.in @@ -47,9 +47,9 @@ version() {
cmd() { if [ $locate -eq 1 ]; then - locate -0 -e -b \*.pacnew \*.pacorig \*.pacsave + locate -0 -e -b \*.pacnew \*.pacorig \*.pacsave '*.pacsave.[0-9]' else - find $diffsearchpath \( -name \*.pacnew -o -name \*.pacorig -o -name \*.pacsave \) -print0 + find $diffsearchpath \( -name \*.pacnew -o -name \*.pacorig -o -name \*.pacsave -o -name '*.pacsave.[0-9]' \) -print0 fi }
@@ -71,6 +71,12 @@ while IFS= read -u 3 -r -d '' pacfile; do file="${pacfile%.pac*}" file_type="pac${pacfile##*.pac}"
+ # add matches for pacsave.N to oldsaves array, do not prompt + if [[ $file_type = pacsave.+([0-9]) ]]; then + oldsaves+=("$pacfile") + continue + fi + msg "%s file found for %s" "$file_type" "$file" if [ ! -f "$file" ]; then warning "$file does not exist" @@ -97,6 +103,8 @@ while IFS= read -u 3 -r -d '' pacfile; do fi done 3< <(cmd)
+(( ${#oldsaves[@]} > 0 )) && warning "Ignoring %s" "${oldsaves[@]}" + exit 0
# vim: set ts=2 sw=2 noet: -- 1.8.3.2
On Mon, Jul 15, 2013 at 09:35:09AM -0500, Dan McGee wrote:
On Thu, Jul 11, 2013 at 5:08 PM, Jonathan Frazier <eyeswide@gmail.com> wrote:
Signed-off-by: Jonathan Frazier <eyeswide@gmail.com> --- contrib/pacdiff.sh.in | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
I'm hoping I'm reading this wrong or haven't had enough coffee yet since it got Ack-ed by Allan, but doesn't this totally fail when pacsave files roll over from foo.conf.9 to foo.conf.10? This is 100% supported by the match and move behavior in libalpm's code in remove.c.
Nope, you're correct. I was thinking about suggesting that we simply switch to using find -regex here if we want to be truly accurate about it. Otherwise, -name '*.pacsave.[0-9]*' is sufficient to cover it.
diff --git a/contrib/pacdiff.sh.in b/contrib/pacdiff.sh.in index 47779d6..a2c9cad 100644 --- a/contrib/pacdiff.sh.in +++ b/contrib/pacdiff.sh.in @@ -47,9 +47,9 @@ version() {
cmd() { if [ $locate -eq 1 ]; then - locate -0 -e -b \*.pacnew \*.pacorig \*.pacsave + locate -0 -e -b \*.pacnew \*.pacorig \*.pacsave '*.pacsave.[0-9]' else - find $diffsearchpath \( -name \*.pacnew -o -name \*.pacorig -o -name \*.pacsave \) -print0 + find $diffsearchpath \( -name \*.pacnew -o -name \*.pacorig -o -name \*.pacsave -o -name '*.pacsave.[0-9]' \) -print0 fi }
@@ -71,6 +71,12 @@ while IFS= read -u 3 -r -d '' pacfile; do file="${pacfile%.pac*}" file_type="pac${pacfile##*.pac}"
+ # add matches for pacsave.N to oldsaves array, do not prompt + if [[ $file_type = pacsave.+([0-9]) ]]; then + oldsaves+=("$pacfile") + continue + fi + msg "%s file found for %s" "$file_type" "$file" if [ ! -f "$file" ]; then warning "$file does not exist" @@ -97,6 +103,8 @@ while IFS= read -u 3 -r -d '' pacfile; do fi done 3< <(cmd)
+(( ${#oldsaves[@]} > 0 )) && warning "Ignoring %s" "${oldsaves[@]}" + exit 0
# vim: set ts=2 sw=2 noet: -- 1.8.3.2
On 16/07/13 02:56, Dave Reisner wrote:
On Mon, Jul 15, 2013 at 09:35:09AM -0500, Dan McGee wrote:
On Thu, Jul 11, 2013 at 5:08 PM, Jonathan Frazier <eyeswide@gmail.com> wrote:
Signed-off-by: Jonathan Frazier <eyeswide@gmail.com> --- contrib/pacdiff.sh.in | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
I'm hoping I'm reading this wrong or haven't had enough coffee yet since it got Ack-ed by Allan, but doesn't this totally fail when pacsave files roll over from foo.conf.9 to foo.conf.10? This is 100% supported by the match and move behavior in libalpm's code in remove.c.
Nope, you're correct. I was thinking about suggesting that we simply switch to using find -regex here if we want to be truly accurate about it. Otherwise, -name '*.pacsave.[0-9]*' is sufficient to cover it.
I was ignoring that possibility because '*.pacsave.[0-9]*' will match too much and who has that many pacsave files? That would require installing, adjusting the configuration, uninstalling, repeat 10x. Allan
Signed-off-by: Jonathan Frazier <eyeswide@gmail.com> --- contrib/pacdiff.sh.in | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/contrib/pacdiff.sh.in b/contrib/pacdiff.sh.in index 47779d6..e9be606 100644 --- a/contrib/pacdiff.sh.in +++ b/contrib/pacdiff.sh.in @@ -47,9 +47,9 @@ version() { cmd() { if [ $locate -eq 1 ]; then - locate -0 -e -b \*.pacnew \*.pacorig \*.pacsave + locate -0 -e -b \*.pacnew \*.pacorig \*.pacsave '*.pacsave.[0-9]' else - find $diffsearchpath \( -name \*.pacnew -o -name \*.pacorig -o -name \*.pacsave \) -print0 + find $diffsearchpath \( -name \*.pacnew -o -name \*.pacorig -o -name \*.pacsave -o -name '*.pacsave.[0-9]' \) -print0 fi } @@ -71,6 +71,12 @@ while IFS= read -u 3 -r -d '' pacfile; do file="${pacfile%.pac*}" file_type="pac${pacfile##*.pac}" + # add matches for pacsave.N to oldsaves array, do not prompt + if [[ $file_type = pacsave.+([0-9]) ]]; then + oldsaves+=("$pacfile") + continue + fi + msg "%s file found for %s" "$file_type" "$file" if [ ! -f "$file" ]; then warning "$file does not exist" @@ -97,6 +103,8 @@ while IFS= read -u 3 -r -d '' pacfile; do fi done 3< <(cmd) +(( ${#oldsaves[@]} > 0 )) && warning "Ignoring %s" "${oldsaves[@]}" + exit 0 # vim: set ts=2 sw=2 noet: -- 1.8.3.2
On 12/07/13 08:14, Jonathan Frazier wrote:
Signed-off-by: Jonathan Frazier <eyeswide@gmail.com> ---
I have no preference whether to print the .pacsave.n files as they are found or at the end. So: Ack. Allan
These are a few patches to improve help, option handling, and prepare for extending the search types. These do not change the existing (external) behavior or defaults beyond adding additional options. The patches are fairly independent, but may not apply cleanly out of order.
Clean up and reword --help get rid of all the echos to make it easier to read in source. Signed-off-by: Jonathan Frazier <eyeswide@gmail.com> --- contrib/pacdiff.sh.in | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/contrib/pacdiff.sh.in b/contrib/pacdiff.sh.in index 4bc4385..830e852 100644 --- a/contrib/pacdiff.sh.in +++ b/contrib/pacdiff.sh.in @@ -31,12 +31,22 @@ m4_include(../scripts/library/output_format.sh) 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" + cat <<EOF +$myname is a simple pacnew/pacorig/pacsave updater. + +Usage: $myname [-l] + +Options: + -l/--locate scan using locate (default: find) + +Enviroment Variables: + DIFFPROG override the merge program: (default: vimdiff) + DIFFSEARCHPATH override the search path. (only when using find) + (default: /etc) + +Example: DIFFPROG=meld DIFFSEARCHPATH="/boot /etc /usr" $myname + +EOF } version() { -- 1.8.3.2
loop over arguments, this will allow adding options such as --nocolor Signed-off-by: Jonathan Frazier <eyeswide@gmail.com> --- contrib/pacdiff.sh.in | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/contrib/pacdiff.sh.in b/contrib/pacdiff.sh.in index 830e852..52a2e7e 100644 --- a/contrib/pacdiff.sh.in +++ b/contrib/pacdiff.sh.in @@ -63,8 +63,8 @@ cmd() { fi } -if [ $# -gt 0 ]; then - case $1 in +while [[ -n "$1" ]]; do + case "$1" in -l|--locate) locate=1;; -V|--version) @@ -74,7 +74,8 @@ if [ $# -gt 0 ]; then *) usage; exit 1;; esac -fi + shift +done # see http://mywiki.wooledge.org/BashFAQ/020 while IFS= read -u 3 -r -d '' pacfile; do -- 1.8.3.2
Allow colors to be disabled for use on broken/serial terminals. Signed-off-by: Jonathan Frazier <eyeswide@gmail.com> --- contrib/pacdiff.sh.in | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/contrib/pacdiff.sh.in b/contrib/pacdiff.sh.in index 52a2e7e..a39a02a 100644 --- a/contrib/pacdiff.sh.in +++ b/contrib/pacdiff.sh.in @@ -28,8 +28,6 @@ USE_COLOR='y' m4_include(../scripts/library/output_format.sh) -m4_include(../scripts/library/term_colors.sh) - usage() { cat <<EOF $myname is a simple pacnew/pacorig/pacsave updater. @@ -38,6 +36,7 @@ Usage: $myname [-l] Options: -l/--locate scan using locate (default: find) + --nocolor remove colors from output Enviroment Variables: DIFFPROG override the merge program: (default: vimdiff) @@ -67,6 +66,8 @@ while [[ -n "$1" ]]; do case "$1" in -l|--locate) locate=1;; + --nocolor) + USE_COLOR='n' ;; -V|--version) version; exit 0;; -h|--help) @@ -77,6 +78,8 @@ while [[ -n "$1" ]]; do shift done +m4_include(../scripts/library/term_colors.sh) + # see http://mywiki.wooledge.org/BashFAQ/020 while IFS= read -u 3 -r -d '' pacfile; do file="${pacfile%.pac*}" -- 1.8.3.2
change cmd tests to if (( $find ))... as it is cleaner. All search cmds have an option and a variable initialized to zero. the active option should be set to 1. Add a switch to exclude multiple search options. set the default when all are equal to zero. Signed-off-by: Jonathan Frazier <eyeswide@gmail.com> --- contrib/pacdiff.sh.in | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/contrib/pacdiff.sh.in b/contrib/pacdiff.sh.in index a39a02a..c12e9d5 100644 --- a/contrib/pacdiff.sh.in +++ b/contrib/pacdiff.sh.in @@ -23,19 +23,23 @@ declare -r myver='@PACKAGE_VERSION@' diffprog=${DIFFPROG:-vimdiff} diffsearchpath=${DIFFSEARCHPATH:-/etc} -locate=0 USE_COLOR='y' +declare -i findActive=0 locateActive=0 + m4_include(../scripts/library/output_format.sh) usage() { cat <<EOF $myname is a simple pacnew/pacorig/pacsave updater. -Usage: $myname [-l] +Usage: $myname [-l | -f] [--nocolor] + +Search Options: select one, default: find + -l/--locate scan using locate + -f/--find scan using find -Options: - -l/--locate scan using locate (default: find) +General Options: --nocolor remove colors from output Enviroment Variables: @@ -55,9 +59,9 @@ version() { } cmd() { - if [ $locate -eq 1 ]; then + if (( $locateActive )); then locate -0 -e -b \*.pacnew \*.pacorig \*.pacsave '*.pacsave.[0-9]' - else + elif (( $findActive )); then find $diffsearchpath \( -name \*.pacnew -o -name \*.pacorig -o -name \*.pacsave -o -name '*.pacsave.[0-9]' \) -print0 fi } @@ -65,7 +69,9 @@ cmd() { while [[ -n "$1" ]]; do case "$1" in -l|--locate) - locate=1;; + locateActive=1;; + -f|--find) + findActive=1;; --nocolor) USE_COLOR='n' ;; -V|--version) @@ -80,6 +86,12 @@ done m4_include(../scripts/library/term_colors.sh) +case $(( findActive+locateActive )) in + 0) findActive=1;; # set the default search option + [^1]) error "Only one search option may be used at a time" + usage; exit 1;; +esac + # see http://mywiki.wooledge.org/BashFAQ/020 while IFS= read -u 3 -r -d '' pacfile; do file="${pacfile%.pac*}" -- 1.8.3.2
On 17/07/13 04:00, Jonathan Frazier wrote:
change cmd tests to if (( $find ))... as it is cleaner. All search cmds have an option and a variable initialized to zero. the active option should be set to 1. Add a switch to exclude multiple search options. set the default when all are equal to zero.
Signed-off-by: Jonathan Frazier <eyeswide@gmail.com> --- contrib/pacdiff.sh.in | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)
diff --git a/contrib/pacdiff.sh.in b/contrib/pacdiff.sh.in index a39a02a..c12e9d5 100644 --- a/contrib/pacdiff.sh.in +++ b/contrib/pacdiff.sh.in @@ -23,19 +23,23 @@ declare -r myver='@PACKAGE_VERSION@'
diffprog=${DIFFPROG:-vimdiff} diffsearchpath=${DIFFSEARCHPATH:-/etc} -locate=0 USE_COLOR='y'
+declare -i findActive=0 locateActive=0 + m4_include(../scripts/library/output_format.sh)
usage() { cat <<EOF $myname is a simple pacnew/pacorig/pacsave updater.
-Usage: $myname [-l] +Usage: $myname [-l | -f] [--nocolor] + +Search Options: select one, default: find + -l/--locate scan using locate + -f/--find scan using find
-Options: - -l/--locate scan using locate (default: find) +General Options: --nocolor remove colors from output
Enviroment Variables: @@ -55,9 +59,9 @@ version() { }
cmd() { - if [ $locate -eq 1 ]; then + if (( $locateActive )); then locate -0 -e -b \*.pacnew \*.pacorig \*.pacsave '*.pacsave.[0-9]' - else + elif (( $findActive )); then find $diffsearchpath \( -name \*.pacnew -o -name \*.pacorig -o -name \*.pacsave -o -name '*.pacsave.[0-9]' \) -print0 fi } @@ -65,7 +69,9 @@ cmd() { while [[ -n "$1" ]]; do case "$1" in -l|--locate) - locate=1;; + locateActive=1;;
Can you fix the indentation here too? Extra tabs needed.
+ -f|--find) + findActive=1;; --nocolor) USE_COLOR='n' ;; -V|--version) @@ -80,6 +86,12 @@ done
m4_include(../scripts/library/term_colors.sh)
+case $(( findActive+locateActive )) in + 0) findActive=1;; # set the default search option + [^1]) error "Only one search option may be used at a time" + usage; exit 1;; +esac + # see http://mywiki.wooledge.org/BashFAQ/020 while IFS= read -u 3 -r -d '' pacfile; do file="${pacfile%.pac*}"
On 17/07/13 04:00, Jonathan Frazier wrote:
change cmd tests to if (( $find ))... as it is cleaner. All search cmds have an option and a variable initialized to zero. the active option should be set to 1. Add a switch to exclude multiple search options. set the default when all are equal to zero.
Signed-off-by: Jonathan Frazier <eyeswide@gmail.com> --- contrib/pacdiff.sh.in | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)
diff --git a/contrib/pacdiff.sh.in b/contrib/pacdiff.sh.in index a39a02a..c12e9d5 100644 --- a/contrib/pacdiff.sh.in +++ b/contrib/pacdiff.sh.in @@ -23,19 +23,23 @@ declare -r myver='@PACKAGE_VERSION@'
diffprog=${DIFFPROG:-vimdiff} diffsearchpath=${DIFFSEARCHPATH:-/etc} -locate=0 USE_COLOR='y'
+declare -i findActive=0 locateActive=0 + m4_include(../scripts/library/output_format.sh)
usage() { cat <<EOF $myname is a simple pacnew/pacorig/pacsave updater.
-Usage: $myname [-l] +Usage: $myname [-l | -f] [--nocolor] + +Search Options: select one, default: find + -l/--locate scan using locate + -f/--find scan using find
-Options: - -l/--locate scan using locate (default: find) +General Options: --nocolor remove colors from output
Enviroment Variables: @@ -55,9 +59,9 @@ version() { }
cmd() { - if [ $locate -eq 1 ]; then + if (( $locateActive )); then locate -0 -e -b \*.pacnew \*.pacorig \*.pacsave '*.pacsave.[0-9]' - else + elif (( $findActive )); then find $diffsearchpath \( -name \*.pacnew -o -name \*.pacorig -o -name \*.pacsave -o -name '*.pacsave.[0-9]' \) -print0 fi } @@ -65,7 +69,9 @@ cmd() { while [[ -n "$1" ]]; do case "$1" in -l|--locate) - locate=1;; + locateActive=1;;
We tend to use variables in all capitals for things like this. I.e. LOCATE and FIND.
+ -f|--find) + findActive=1;; --nocolor) USE_COLOR='n' ;; -V|--version) @@ -80,6 +86,12 @@ done
m4_include(../scripts/library/term_colors.sh)
+case $(( findActive+locateActive )) in
I know these default to zero, but if you are going to add them I'd like them to be explicitly set to zero at the top of the script. See what we do in makepkg and pacman-key for example.
+ 0) findActive=1;; # set the default search option + [^1]) error "Only one search option may be used at a time" + usage; exit 1;; +esac + # see http://mywiki.wooledge.org/BashFAQ/020 while IFS= read -u 3 -r -d '' pacfile; do file="${pacfile%.pac*}"
Signed-off-by: Jonathan Frazier <eyeswide@gmail.com> --- contrib/pacdiff.sh.in | 1 + 1 file changed, 1 insertion(+) diff --git a/contrib/pacdiff.sh.in b/contrib/pacdiff.sh.in index c12e9d5..7a2db2c 100644 --- a/contrib/pacdiff.sh.in +++ b/contrib/pacdiff.sh.in @@ -26,6 +26,7 @@ diffsearchpath=${DIFFSEARCHPATH:-/etc} USE_COLOR='y' declare -i findActive=0 locateActive=0 +declare -a oldsaves m4_include(../scripts/library/output_format.sh) -- 1.8.3.2
On 17/07/13 04:00, Jonathan Frazier wrote:
Signed-off-by: Jonathan Frazier <eyeswide@gmail.com> --- contrib/pacdiff.sh.in | 1 + 1 file changed, 1 insertion(+)
diff --git a/contrib/pacdiff.sh.in b/contrib/pacdiff.sh.in index c12e9d5..7a2db2c 100644 --- a/contrib/pacdiff.sh.in +++ b/contrib/pacdiff.sh.in @@ -26,6 +26,7 @@ diffsearchpath=${DIFFSEARCHPATH:-/etc} USE_COLOR='y'
declare -i findActive=0 locateActive=0 +declare -a oldsaves
m4_include(../scripts/library/output_format.sh)
Best to merge this back in the oldsaves patch. Allan
participants (5)
-
Allan McRae
-
Andrew Gregory
-
Dan McGee
-
Dave Reisner
-
Jonathan Frazier