badusage(sprintf(_g("two commands specified: %s and --%s"), $_, $action));
}
+sub checked_rm($)
+{
+ my ($f) = @_;
+ unlink($f) || $! == ENOENT ||
+ quit(sprintf(_g("unable to remove %s: %s"), $f, $!));
+}
#
# Main program
if ($action eq 'auto') {
&pr(sprintf(_g("Setting up automatic selection of %s."), $name))
if $verbosemode > 0;
- unlink("$altdir/$name.dpkg-tmp") || $! == &ENOENT ||
- &quit(sprintf(_g("unable to remove %s: %s"), "$altdir/$name.dpkg-tmp", $!));
- unlink("$altdir/$name") || $! == &ENOENT ||
- &quit(sprintf(_g("unable to remove %s: %s"), "$altdir/$name", $!));
+ checked_rm("$altdir/$name.dpkg-tmp");
+ checked_rm("$altdir/$name");
$state= 'nonexistent';
$mode = 'auto';
}
if ($i > $#versions) {
&pr(sprintf(_g("Discarding obsolete slave link %s (%s)."), $slavenames[$j], $slavelinks[$j]))
if $verbosemode > 0;
- unlink("$altdir/$slavenames[$j]") || $! == &ENOENT ||
- &quit(sprintf(_g("unable to remove %s: %s"), "$altdir/$slavenames[$j]", $!));
- unlink($slavelinks[$j]) || $! == &ENOENT ||
- &quit(sprintf(_g("unable to remove %s: %s"), $slavelinks[$j], $!));
+ checked_rm("$altdir/$slavenames[$j]");
+ checked_rm($slavelinks[$j]);
my $k = $#slavenames;
$slavenum{$slavenames[$k]}= $j;
delete $slavenum{$slavenames[$j]};
if ($best eq '') {
&pr(sprintf(_g("Last package providing %s (%s) removed, deleting it."), $name, $link))
if $verbosemode > 0;
- unlink("$altdir/$name") || $! == &ENOENT ||
- &quit(sprintf(_g("unable to remove %s: %s"), "$altdir/$name", $!));
- unlink("$link") || $! == &ENOENT ||
- &quit(sprintf(_g("unable to remove %s: %s"), "$link", $!));
- unlink("$admindir/$name.dpkg-new") ||
- &quit(sprintf(_g("unable to remove %s: %s"), "$admindir/$name.dpkg-new", $!));
- unlink("$admindir/$name") || $! == &ENOENT ||
- &quit(sprintf(_g("unable to remove %s: %s"), "$admindir/$name", $!));
+ checked_rm("$altdir/$name");
+ checked_rm("$link");
+ checked_rm("$admindir/$name.dpkg-new");
+ checked_rm("$admindir/$name");
exit(0);
} else {
$linkname = readlink($link);
if $verbosemode > 0;
} elsif (!defined($linkname) ||
(defined($linkname) && $linkname ne "$altdir/$name")) {
- unlink("$link.dpkg-tmp") || $! == &ENOENT ||
- &quit(sprintf(_g("unable to ensure %s nonexistent: %s"), "$link.dpkg-tmp", $!));
+ checked_rm("$link.dpkg-tmp");
symlink("$altdir/$name","$link.dpkg-tmp") ||
&quit(sprintf(_g("unable to make %s a symlink to %s: %s"), "$link.dpkg-tmp", "$altdir/$name", $!));
rename_mv("$link.dpkg-tmp",$link) ||
&pr(sprintf(_g("Updating %s (%s) to point to %s."), $name, $link, $best))
if $verbosemode > 0;
}
- unlink("$altdir/$name.dpkg-tmp") || $! == &ENOENT ||
- &quit(sprintf(_g("unable to ensure %s nonexistent: %s"), "$altdir/$name.dpkg-tmp", $!));
+ checked_rm("$altdir/$name.dpkg-tmp");
symlink($best,"$altdir/$name.dpkg-tmp");
}
}
$sname= $slavenames[$j];
$slink= $slavelinks[$j];
$spath= $slavepath{$bestnum,$j};
- unlink("$altdir/$sname.dpkg-tmp") || $! == &ENOENT ||
- &quit(sprintf(_g("unable to ensure %s nonexistent: %s"), "$altdir/$sname.dpkg-tmp", $!));
+ checked_rm("$altdir/$sname.dpkg-tmp");
if ($spath eq '') {
&pr(sprintf(_g("Removing %s (%s), not appropriate with %s."), $sname, $slink, $best))
if $verbosemode > 0;
- unlink("$altdir/$sname") || $! == &ENOENT ||
- &quit(sprintf(_g("unable to remove %s: %s"), "$altdir/$sname", $!));
- unlink("$slink") || $! == &ENOENT ||
- &quit(sprintf(_g("unable to remove %s: %s"), $slink, $!));
+ checked_rm("$altdir/$sname");
+ checked_rm("$slink");
} else {
$linkname = readlink($slink);
if (!defined($linkname) && $! != ENOENT) {
if $verbosemode > 0;
} elsif (!defined($linkname) ||
(defined($linkname) && $linkname ne "$altdir/$sname")) {
- unlink("$slink.dpkg-tmp") || $! == ENOENT ||
- quit(sprintf(_g("unable to ensure %s nonexistent: %s"),
- "$slink.dpkg-tmp", $!));
+ checked_rm("$slink.dpkg-tmp");
symlink("$altdir/$sname","$slink.dpkg-tmp") ||
quit(sprintf(_g("unable to make %s a symlink to %s: %s"),
"$slink.dpkg-tmp", "$altdir/$sname", $!));
} else {
&pr(sprintf(_g("Removing %s (%s), not appropriate with %s."), $slave, $slavelinks[$slnum], $versions[$preferred]))
if $verbosemode > 0;
- unlink("$altdir/$slave") || $! == &ENOENT ||
- &quit(sprintf(_g("unable to remove %s: %s"), "$altdir/$slave", $!));
+ checked_rm("$altdir/$slave");
}
}
} else {
&pr(sprintf(_g("Removing %s (%s), not appropriate with %s."), $slave, $slavelinks[$slnum], $versions[$preferred]))
if $verbosemode > 0;
- unlink("$altdir/$slave") || $! == &ENOENT ||
- &quit(sprintf(_g("unable to remove %s: %s"), "$altdir/$slave", $!));
+ checked_rm("$altdir/$slave");
}
}
}