Control: tags -1 patch

Marco,

Thanks for your patience with this.

On Mon, Jan 25, 2021 at 08:47:40AM +0100, Marco Schmidt wrote:
> 
> Package: ucf
> Version: all
> 
> Hello,
> 
> I see the sanity check for the conffold/conffnew setting as a bug.

I agree. I have a patch (attached) which reorders the configuration by category
(ucf.conf and environment). AFAICS, setting these options by commandline option
was not possible, so I have removed that redundant code.

Mark
>From 15be509cea45214260d50c11649170e1bcd4fc43 Mon Sep 17 00:00:00 2001
From: Mark Hindley <m...@hindley.org.uk>
Date: Tue, 31 Dec 2024 09:49:52 +0000
Subject: [PATCH] Handle force_conff{old,new} in parallel for config file and
 environment.

Closes: #980996
---
 ucf | 57 ++++++++++++++++++++++++++++++---------------------------
 1 file changed, 30 insertions(+), 27 deletions(-)

diff --git a/ucf b/ucf
index 310813a..a9cde0a 100755
--- a/ucf
+++ b/ucf
@@ -460,22 +460,32 @@ else
     statedir=$(vset '/var/lib/ucf'  "The State directory")
 fi
 
-# Env, config file, or default
-if [ "$UCF_FORCE_CONFFOLD" ]; then
-    force_conffold=$(vset "$UCF_FORCE_CONFFOLD" "Keep the old file")
-elif [ "$conf_force_conffold" ]; then
-    force_conffold=$(vset "$conf_force_conffold" "Keep the old file")
-else
-    force_conffold=''
+# Handle conffold and conffnew together. See #980996
+# Default
+force_conff=
+
+# Config file
+if [ "$conf_force_conffold" ]; then
+    if [ "$conf_force_conffnew" ]; then
+	echo >&2 "Error: Only one of conf_force_conffold and conf_force_conffnew should"
+	echo >&2 "       be set in the config file"
+	exit 1
+    fi
+    force_conff=$(vset "old" "Keep the old file")
+elif [ "$conf_force_conffnew" ]; then
+    force_conff=$(vset "new" "Replace the old file")
 fi
 
-# Env variable, config file, or default
-if [ "$UCF_FORCE_CONFFNEW" ]; then
-    force_conffnew=$(vset "$UCF_FORCE_CONFFNEW" "Replace the old file")
-elif [ "$conf_force_conffnew" ]; then
-    force_conffnew=$(vset "$conf_force_conffnew" "Replace the old file")
-else
-    force_conffnew=''
+# Environment
+if [ "$UCF_FORCE_CONFFOLD" ]; then
+    if [ "$UCF_FORCE_CONFFNEW" ]; then
+	echo >&2 "Error: Only one of UCF_FORCE_CONFFOLD and UCF_FORCE_CONFFNEW should"
+	echo >&2 "       be set in the environment"
+	exit 1
+    fi
+    force_conff=$(vset "old" "Keep the old file")
+elif [ "$UCF_FORCE_CONFFNEW" ]; then
+    force_conff=$(vset "new" "Replace the old file")
 fi
 
 # Env variable, config file, or default
@@ -505,19 +515,12 @@ fi
 ########               More Sanity checking                  #########
 ########                                                     #########
 ######################################################################
-if [ "$force_conffold" ] && [ "$force_conffnew" ]; then
-    echo >&2 "Error: Only one of force_conffold and force_conffnew should"
-    echo >&2 "       be set"
-    exit 1
-fi
 
 # VERBOSE of 0 is supposed to be the same as not setting VERBOSE
 if [ "$VERBOSE" = "0" ]; then
     VERBOSE=''
 fi
 
-
-#
 if [ -e "$statedir/hashfile" ] && [ ! -w "$statedir/hashfile" ]; then
     echo >&2 "ucf: do not have write privilege to the state data"
     if [ "$docmd" = "YES" ]; then
@@ -722,7 +725,7 @@ if [ -e "$dest_file" ]; then
 		for file in "${old_mdsum_dir}/"*; do
 		    oldsum="$(awk '{print $1}' "$file")"
 		    if [ "$oldsum" = "$destsum"  ]; then
-			if [ ! "$force_conffold" ]; then
+			if [ "$force_conff" != "old" ]; then
 #                           Bingo! replace, set the md5sum, and we are done
 			    [ "$VERBOSE" ] &&
 				echo >&2 \
@@ -740,7 +743,7 @@ if [ -e "$dest_file" ]; then
 		oldsum=$(grep -E "^${destsum}" "$old_mdsum_file" || true)
 		if [ "$oldsum" ]; then
 #                    Bingo
-		    if [ ! "$force_conffold" ]; then
+		    if [ "$force_conff" != old ]; then
 			[ "$VERBOSE" ] &&
 			    echo >&2 \
 				"Replacing config file $dest_file with new version"
@@ -831,7 +834,7 @@ else  # "$dest_file" does not exist
         else
             # Even though the user has deleted this file, they should
             # be asked now, unless specified otherwise.
-            if [ ! "$force_conffold" ]; then
+            if [ "$force_conff" != "old" ]; then
                 destsum='AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
             else
                 exit 0
@@ -855,7 +858,7 @@ fi
 #      a: If the md5sum of the dest file is the same as lastsum, replace the
 #         destfile, saying we are replacing old config files
 if [ "$destsum" = "$lastsum" ]; then
-    if [ ! "$force_conffold" ]; then
+    if [ "$force_conff" != old ]; then
 	echo >&2 "Replacing config file $dest_file with new version"
 	replace_conf_file
 	exit 0
@@ -867,7 +870,7 @@ if [ "$destsum" = "$lastsum" ]; then
 else
 #      b: If the md5sum of the dest file differs from lastsum, we need to ask
 #         the user what action to take.
-    if [ "$force_conffnew" ]; then
+    if [ "$force_conff" = "new" ]; then
 	echo >&2 "Replacing config file $dest_file with new version"
 	echo >&2 "since you asked for it."
         if [ "$destsum" = "$newsum" ]; then
@@ -878,7 +881,7 @@ else
 	replace_conf_file
 	exit 0
     fi
-    if [ "$force_conffold" ]; then
+    if [ "$force_conff" = "old" ]; then
 	replace_md5sum
 	cp -pf "$orig_new_file" "$dest_file.${DIST_SUFFIX}"
 	exit 0
-- 
2.39.5

Reply via email to