Procházet zdrojové kódy

u-a: Reimplement --all as a fully built-in command

Do not execute itself with --config for each alternative to configure,
just handle them all in-process.
Guillem Jover před 11 roky
rodič
revize
c9c7a4e39b
2 změnil soubory, kde provedl 27 přidání a 14 odebrání
  1. 2 0
      debian/changelog
  2. 25 14
      utils/update-alternatives.c

+ 2 - 0
debian/changelog

@@ -6,6 +6,8 @@ dpkg (1.18.3) UNRELEASED; urgency=low
   * Print the master and slave links in «update-alternatives --display».
   * Print the current best alternative in the head instead of the trail
     in «update-alternatives --display», with a two space indentation.
+  * Reimplement «update-alternatives --all» as a fully built-in command
+    instead of executing itself with --config per subtask.
   * Perl modules:
     - Only warn on invalid week days instead of aborting in
       Dpkg::Changelog::Entry::Debian. Regression introduced in dpkg 1.18.2.

+ 25 - 14
utils/update-alternatives.c

@@ -1677,20 +1677,6 @@ alternative_config(struct alternative *a, const char *current_choice)
 	return new_choice;
 }
 
-static void
-alternative_config_all(void)
-{
-	struct dirent **table;
-	int i, count;
-
-	count = altdb_get_namelist(&table);
-	for (i = 0; i < count; i++) {
-		subcall(prog_path, "--config", table[i]->d_name, NULL);
-		printf("\n");
-	}
-	altdb_free_namelist(table, count);
-}
-
 static void
 alternative_add_commit_op(struct alternative *a, enum opcode opcode,
                           const char *arg_a, const char *arg_b)
@@ -2342,6 +2328,30 @@ alternative_update(struct alternative *a,
 	alternative_commit(a);
 }
 
+static void
+alternative_config_all(void)
+{
+	struct alternative_map *alt_map_obj;
+	struct alternative_map *am;
+
+	alt_map_obj = alternative_map_new(NULL, NULL);
+	alternative_map_load_names(alt_map_obj);
+
+	for (am = alt_map_obj; am && am->item; am = am->next) {
+		const char *current_choice;
+		const char *new_choice;
+
+		current_choice = alternative_get_current(am->item);
+		alternative_select_mode(am->item, current_choice);
+
+		new_choice = alternative_config(am->item, current_choice);
+
+		alternative_update(am->item, current_choice, new_choice);
+	}
+
+	alternative_map_free(alt_map_obj);
+}
+
 static void
 alternative_get_selections(void)
 {
@@ -2790,6 +2800,7 @@ main(int argc, char **argv)
 
 	/* 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) {