Explorar o código

u-a: Move alternative loading logic before handling any action

This moves all setup code before all actions are executed which will
allow further refactoring, no behaviour change should happen due to
this commit though.
Guillem Jover %!s(int64=14) %!d(string=hai) anos
pai
achega
3d5278b47b
Modificáronse 1 ficheiros con 23 adicións e 11 borrados
  1. 23 11
      utils/update-alternatives.c

+ 23 - 11
utils/update-alternatives.c

@@ -2587,6 +2587,29 @@ main(int argc, char **argv)
 	if (strcmp(action, "install") == 0)
 	if (strcmp(action, "install") == 0)
 		alternative_check_install_args(inst_alt, fileset);
 		alternative_check_install_args(inst_alt, fileset);
 
 
+	if (strcmp(action, "display") == 0 ||
+	    strcmp(action, "query") == 0 ||
+	    strcmp(action, "list") == 0 ||
+	    strcmp(action, "set") == 0 ||
+	    strcmp(action, "auto") == 0 ||
+	    strcmp(action, "config") == 0 ||
+	    strcmp(action, "remove-all") == 0) {
+		/* Load the alternative info, stop on failure. */
+		if (!alternative_load(a, false))
+			error(_("no alternatives for %s."), a->master_name);
+	} else if (strcmp(action, "remove") == 0) {
+		/* FIXME: Be consistent for now with the case when we
+		 * try to remove a non-existing path from an existing
+		 * link group file. */
+		if (!alternative_load(a, false)) {
+			verbose(_("no alternatives for %s."), a->master_name);
+			exit(0);
+		}
+	} else if (strcmp(action, "install") == 0) {
+		/* Load the alternative info, ignore failures. */
+		alternative_load(a, false);
+	}
+
 	/* Handle actions. */
 	/* Handle actions. */
 	if (strcmp(action, "all") == 0) {
 	if (strcmp(action, "all") == 0) {
 		config_all();
 		config_all();
@@ -2600,17 +2623,6 @@ main(int argc, char **argv)
 		exit(0);
 		exit(0);
 	}
 	}
 
 
-	/* Load the alternative info, stop on failure except for --install. */
-	if (!alternative_load(a, false) && strcmp(action, "install") != 0) {
-		/* FIXME: Be consistent for now with the case when we try to remove a
-		 * non-existing path from an existing link group file. */
-		if (strcmp(action, "remove") == 0) {
-			verbose(_("no alternatives for %s."), a->master_name);
-			exit(0);
-		}
-		error(_("no alternatives for %s."), a->master_name);
-	}
-
 	if (strcmp(action, "display") == 0) {
 	if (strcmp(action, "display") == 0) {
 		alternative_display_user(a);
 		alternative_display_user(a);
 		exit(0);
 		exit(0);