From: Ian Jackson Date: Wed, 6 May 2020 21:58:53 +0000 (+0100) Subject: nailing-cargo: Fixes etc. X-Git-Tag: nailing-cargo/1.0.0~228 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=907c1941399390b1f528cfb3f5704d67c46096bd;p=nailing-cargo.git nailing-cargo: Fixes etc. Signed-off-by: Ian Jackson --- diff --git a/nailing-cargo b/nailing-cargo index bca8177..afb457d 100755 --- a/nailing-cargo +++ b/nailing-cargo @@ -96,6 +96,8 @@ sub getcfg ($$) { return $def; } +sub unlink_or_enoent ($) { unlink $_[0] or $!==ENOENT; } + sub takelock () { for (;;) { open LOCK, ">", $lockfile or die "$self: open/create $lockfile: $!\n"; @@ -198,24 +200,18 @@ sub calculate () { 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"; @@ -228,7 +224,7 @@ END { if ($want_uninstall) { local ($?); foreach my $mf (keys %manifests) { - eval { uninstall1($mf, 0); 1; } or warn "$@"; + eval { uninstall1($mf,1); 1; } or warn "$@"; } } } @@ -240,10 +236,16 @@ sub makebackups () { } } +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) { @@ -261,7 +263,7 @@ sub install () { $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; } } @@ -286,11 +288,13 @@ sub uninstall1 ($$) { 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); } } @@ -335,7 +339,9 @@ install(); my $estatus = invoke(); +print STDERR "INVOKED\n"; uninstall(); +print STDERR "UNINSTALLED\n"; $want_uninstall = 1; exit $estatus;