[Reproducible-commits] [dpkg] 06/54: u-a: Merge all action handling into a single if-else-if block

Mattia Rizzolo mattia at debian.org
Fri Jan 15 18:53:58 UTC 2016


This is an automated email from the git hooks/post-receive script.

mattia pushed a commit to branch pu/reproducible_builds
in repository dpkg.

commit 9c311e1a445868630f8c8e4600d7539599e49ce5
Author: Guillem Jover <guillem at debian.org>
Date:   Wed Oct 21 16:48:47 2015 +0200

    u-a: Merge all action handling into a single if-else-if block
    
    Introduce two boolean variables to track when to log the command-line
    arguments when modifying anything on the system, and another one when
    modifying a single alternative to initialize and update it.
    
    This unifies the code, and will make it easier to switch it into a
    shared library in the future.
---
 debian/changelog            |  2 ++
 utils/update-alternatives.c | 45 ++++++++++++++++++++++++++++-----------------
 2 files changed, 30 insertions(+), 17 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index a153236..b1e5403 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -9,6 +9,8 @@ dpkg (1.18.4) UNRELEASED; urgency=low
     to «postinst configure», which might consider this a first install instead
     of an upgrade. Closes: #801156
   * Fix memory leaks in «dpkg --verify» and dpkg infodb format upgrade logic.
+  * Merge all update-alternatives action handling into a single if-else-if
+    block, to unify the code an allow a future switch into a shared library.
   * Build system:
     - Set PERL5LIB globally for the test suite to the local modules directory,
       to avoid using the system modules. Regression introduced in dpkg 1.17.8.
diff --git a/utils/update-alternatives.c b/utils/update-alternatives.c
index 5df722c..0ea5c81 100644
--- a/utils/update-alternatives.c
+++ b/utils/update-alternatives.c
@@ -2569,6 +2569,8 @@ main(int argc, char **argv)
 	char *path = NULL;
 	const char *current_choice = NULL;
 	const char *new_choice = NULL;
+	bool modifies_alt = false;
+	bool modifies_sys = false;
 	int i = 0;
 
 	setlocale(LC_ALL, "");
@@ -2720,6 +2722,21 @@ main(int argc, char **argv)
 		           "--config, --set, --set-selections, --install, "
 		           "--remove, --all, --remove-all or --auto"));
 
+	/* The following actions might modify the current alternative. */
+	if (strcmp(action, "set") == 0 ||
+	    strcmp(action, "auto") == 0 ||
+	    strcmp(action, "config") == 0 ||
+	    strcmp(action, "remove") == 0 ||
+	    strcmp(action, "remove-all") == 0 ||
+	    strcmp(action, "install") == 0)
+		modifies_alt = true;
+
+	/* The following actions might modify the system somehow. */
+	if (modifies_alt ||
+	    strcmp(action, "all") == 0 ||
+	    strcmp(action, "set-selections") == 0)
+		modifies_sys = true;
+
 	if (strcmp(action, "install") == 0)
 		alternative_check_install_args(inst_alt, fileset);
 
@@ -2746,35 +2763,28 @@ main(int argc, char **argv)
 		alternative_load(a, ALTDB_WARN_PARSER);
 	}
 
+	if (modifies_sys)
+		log_msg("run with %s", get_argv_string(argc, argv));
+
+	if (modifies_alt) {
+		current_choice = alternative_get_current(a);
+		alternative_select_mode(a, current_choice);
+	}
+
 	/* Handle actions. */
 	if (strcmp(action, "all") == 0) {
-		log_msg("run with %s", get_argv_string(argc, argv));
 		alternative_config_all();
-		exit(0);
 	} else if (strcmp(action, "get-selections") == 0) {
 		alternative_get_selections();
-		exit(0);
 	} else if (strcmp(action, "set-selections") == 0) {
-		log_msg("run with %s", get_argv_string(argc, argv));
 		alternative_set_selections(stdin, _("<standard input>"));
-		exit(0);
 	} else if (strcmp(action, "display") == 0) {
 		alternative_display_user(a);
-		exit(0);
 	} else if (strcmp(action, "query") == 0) {
 		alternative_display_query(a);
-		exit(0);
 	} else if (strcmp(action, "list") == 0) {
 		alternative_display_list(a);
-		exit(0);
-	}
-
-	/* Actions below might modify the system. */
-	log_msg("run with %s", get_argv_string(argc, argv));
-	current_choice = alternative_get_current(a);
-	alternative_select_mode(a, current_choice);
-
-	if (strcmp(action, "set") == 0) {
+	} else if (strcmp(action, "set") == 0) {
 		new_choice = alternative_set_manual(a, path);
 	} else if (strcmp(action, "auto") == 0) {
 		new_choice = alternative_set_auto(a);
@@ -2805,7 +2815,8 @@ main(int argc, char **argv)
 		}
 	}
 
-	alternative_update(a, current_choice, new_choice);
+	if (modifies_alt)
+		alternative_update(a, current_choice, new_choice);
 
 	return 0;
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/dpkg.git



More information about the Reproducible-commits mailing list