Bläddra i källkod

update-alternatives: handle dangling alternative symlink

update-alternatives did not properly handle when the
alternative symlink in /etc/alternatives was dangling
and pointing to a choice that does not exist currently.
Fix by switching the alternative to automatic mode so
that it's replaced by the best choice.
Raphael Hertzog 17 år sedan
förälder
incheckning
4690e08e95
2 ändrade filer med 9 tillägg och 1 borttagningar
  1. 2 0
      debian/changelog
  2. 7 1
      scripts/update-alternatives.pl

+ 2 - 0
debian/changelog

@@ -8,6 +8,8 @@ dpkg (1.15.3) UNRELEASED; urgency=low
     packages. Closes: #530860
   * Add cleanup of known invalid (master) alternatives in preinst script.
     Closes: #530633, #531611
+  * Let update-alternatives fix a manual alternative with a dangling symlink
+    by switching it to automatic mode. Closes: #529999
 
   [ Updated dpkg translations ]
   * Simplified Chinese (Deng Xiyue). Closes: #531387

+ 7 - 1
scripts/update-alternatives.pl

@@ -257,7 +257,11 @@ if ($alternative->has_current_link()) {
     $current_choice = $alternative->current();
     # Detect manually modified alternative, switch to manual
     if (not $alternative->has_choice($current_choice)) {
-        if ($alternative->status() ne "manual") {
+        if (not -e $current_choice) {
+            warning("%s is dangling, it will be updated with best choice.",
+                    "$altdir/" . $alternative->name());
+            $alternative->set_status('auto');
+        } elsif ($alternative->status() ne "manual") {
             warning(_g("%s has been changed (manually or by a script). " .
                     "Switching to manual updates only."),
                     "$altdir/" . $alternative->name());
@@ -989,6 +993,8 @@ sub prepare_install {
     my ($self, $choice) = @_;
     my ($link, $name) = ($self->link(), $self->name());
     my $fileset = $self->fileset($choice);
+    main::error("can't install unknown choice %s", $choice)
+        if not defined($choice);
     # Create link in /etc/alternatives
     main::checked_rm("$altdir/$name.dpkg-tmp");
     main::checked_symlink($choice, "$altdir/$name.dpkg-tmp");