Forráskód Böngészése

update-alternatives: clarify role of --force concerning removal of links

Modify update-alternatives --remove-all to remove files installed in
place of links if --force is used. Add the corresponding non-regression
test.
Raphaël Hertzog 15 éve
szülő
commit
244ebc2122

+ 2 - 2
man/update-alternatives.8

@@ -335,8 +335,8 @@ Specifies the log file, when this is to be different from the default
 (/var/log/alternatives.log).
 .TP
 .BI \-\-force
-Let \fBupdate-alternatives\fR replace any real file that is installed
-where an alternative link has to be installed.
+Let \fBupdate-alternatives\fR replace or drop any real file that is installed
+where an alternative link has to be installed or removed.
 .TP
 .BI \-\-skip\-auto
 Skip configuration prompt for alternatives which are properly configured

+ 12 - 4
utils/t/100_update_alternatives.t

@@ -81,7 +81,7 @@ my @choices = (
 );
 my $nb_slaves = 4;
 plan tests => (4 * ($nb_slaves + 1) + 2) * 26 # number of check_choices
-               + 100;                         # rest
+               + 102;                         # rest
 
 sub cleanup {
     system("rm -rf $tmpdir && mkdir -p $admindir && mkdir -p $altdir");
@@ -119,13 +119,17 @@ sub install_choice {
 sub remove_choice {
     my ($id, %opts) = @_;
     my $alt = $choices[$id];
-    my @params = ("--remove", $main_name, $alt->{path});
+    my @params;
+    push @params, @{$opts{params}} if exists $opts{params};
+    push @params, "--remove", $main_name, $alt->{path};
     call_ua(\@params, %opts);
 }
 
 sub remove_all_choices {
     my (%opts) = @_;
-    my @params = ("--remove-all", $main_name);
+    my @params;
+    push @params, @{$opts{params}} if exists $opts{params};
+    push @params, "--remove-all", $main_name;
     call_ua(\@params, %opts);
 }
 
@@ -150,7 +154,9 @@ sub config_choice {
     $input .= "\n";
     $opts{from_string} = \$input;
     $opts{to_string} = \$output;
-    my @params = ("--config", $main_name);
+    my @params;
+    push @params, @{$opts{params}} if exists $opts{params};
+    push @params, "--config", $main_name;
     call_ua(\@params, %opts);
 }
 
@@ -466,6 +472,8 @@ ok(!-l $main_link, "auto switching preserves files that should be links");
 ok(!-l "$bindir/slave2", "auto switching preserves files that should be slave links");
 ok(-f $main_link, "auto switching keeps real file installed as master link");
 ok(-f "$bindir/slave2", "auto switching keeps real files installed as slave links");
+remove_all_choices(params => ["--force"]);
+ok(!-e "$bindir/slave2", "forced removeall drops real files installed as slave links");
 
 # test management of pre-existing files #3
 cleanup();

+ 2 - 3
utils/update-alternatives.c

@@ -1714,11 +1714,10 @@ alternative_prepare_install(struct alternative *a, const char *choice)
 static void
 alternative_remove(struct alternative *a)
 {
-	struct stat st;
 	struct slave_link *sl;
 
 	checked_rm_args("%s" DPKG_TMP_EXT, a->master_link);
-	if (lstat(a->master_link, &st) == 0 && S_ISLNK(st.st_mode))
+	if (alternative_can_replace_link(a->master_link))
 		checked_rm(a->master_link);
 
 	checked_rm_args("%s/%s" DPKG_TMP_EXT, altdir, a->master_name);
@@ -1726,7 +1725,7 @@ alternative_remove(struct alternative *a)
 
 	for (sl = a->slaves; sl; sl = sl->next) {
 		checked_rm_args("%s" DPKG_TMP_EXT, sl->link);
-		if (lstat(sl->link, &st) == 0 && S_ISLNK(st.st_mode))
+		if (alternative_can_replace_link(sl->link))
 			checked_rm(sl->link);
 
 		checked_rm_args("%s/%s" DPKG_TMP_EXT, altdir, sl->name);