return $def;
}
+sub unlink_or_enoent ($) { unlink $_[0] or $!==ENOENT; }
+
sub takelock () {
for (;;) {
open LOCK, ">", $lockfile or die "$self: open/create $lockfile: $!\n";
foreach my $mf (keys %manifests) {
my $toml = $manifests{$mf};
foreach my $k (qw(dependencies build-dependencies dev-dependencies)) {
-print STDERR "CHECKING $mf $k\n";
my $deps = $toml->{$k};
next unless $deps;
-use Data::Dumper;
-print STDERR "CHECKING $mf $k GOT ".Dumper($deps);
foreach my $p (keys %packagemap) {
-print STDERR "CHECKING $mf $k -- $p\n";
my $info = $deps->{$p};
next unless defined $info;
-print STDERR "CHECKING $mf $k -- $p = $info\n";
$deps->{$p} = $info = { } unless ref $info;
delete $info->{version};
$info->{path} = $worksphere.'/'.$packagemap{$p};
-print STDERR "CHECKING $mf $k -- $p UPDATED ", Dumper($deps);
}
}
my $nailing = "$mf.nailing~";
- unlink $nailing or $!==ENOENT or die "$self: remove old $nailing: $!\n";
+ unlink_or_enoent $nailing or die "$self: remove old $nailing: $!\n";
open N, '>', $nailing or die "$self: create new $nailing: $!\n";
print N to_toml($toml) or die "$self: write new $nailing: $!\n";
close N or die "$self: close new $nailing: $!\n";
if ($want_uninstall) {
local ($?);
foreach my $mf (keys %manifests) {
- eval { uninstall1($mf, 0); 1; } or warn "$@";
+ eval { uninstall1($mf,1); 1; } or warn "$@";
}
}
}
}
}
+sub nailed ($) {
+ my ($mf) = @_;
+ my $nailed = "$mf.nailed~"; $nailed =~ s{/([^/]+)$}{/.$1} or die;
+ $nailed;
+}
+
sub install () {
foreach my $mf (keys %manifests) {
my $nailing = "$mf.nailing~";
- my $nailed = "$mf.nailed~"; $nailed =~ s{/([^/]+)$}{/.$1} or die;
+ my $nailed = nailed($mf);
my ($use, $rm);
my $diff;
if (open NN, '<', $nailed) {
$rm = $nailing;
}
rename $use, $mf or die "$self: install nailed $use: $!\n";
- unlink $rm or $!==ENOENT or die "$self: remove old $rm: $!\n";
+ unlink_or_enoent $rm or die "$self: remove old $rm: $!\n";
print STDERR "Nailed $mf\n" if $verbose>=2;
}
}
my ($mf, $enoentok) = @_;
my $unnailed = "$mf.unnailed";
rename $unnailed, $mf or ($enoentok && $!==ENOENT)
- or die "$self: failed to revert: rename $unnailed back to $mf: $!\n";
+ or die "$self: failed to restore: rename $unnailed back to $mf: $!\n";
}
sub uninstall () {
foreach my $mf (keys %manifests) {
+ my $nailed = nailed($mf);
+ link $mf, $nailed or die "$self: preserve (link) $mf as $nailed: $!\n";
uninstall1($mf,0);
}
}
my $estatus = invoke();
+print STDERR "INVOKED\n";
uninstall();
+print STDERR "UNINSTALLED\n";
$want_uninstall = 1;
exit $estatus;