chiark / gitweb /
nailing-cargo: Remainder converted to Perl..., runs, broken
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 3 May 2020 21:10:43 +0000 (22:10 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 3 May 2020 21:10:43 +0000 (22:10 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
nailing-cargo

index 4d3d0f7d4e6590a758f7bb7964cf095cfb1862a8..95377fea56d81c31e770dc6c5f07ca55e173d433 100755 (executable)
@@ -28,6 +28,7 @@
 #  https://stackoverflow.com/questions/33025887/how-to-use-a-local-unpublished-crate
 #  https://github.com/rust-lang/cargo/issues/1481
 
+# Needs libtoml-perl
 
 #: Cargo.nail:
 #
@@ -188,7 +189,7 @@ sub readorigs () {
 
 sub calculate () {
     foreach my $mf (keys %manifests) {
-       my $toml = $manifest{$mf};
+       my $toml = $manifests{$mf};
        foreach my $k (qw(dependencies build-dependencies dev-dependencies)) {
            my $deps = $toml->{$k};
            next unless $deps;
@@ -203,11 +204,13 @@ sub calculate () {
        my $nailing = "$mf.nailing~";
        unlink $nailing or $!==ENOENT or die "$0: remove old $nailing: $!\n";
        open N, '>', $nailing or die "$0: create new $nailing: $!\n";
-       print N, to_toml($toml) or die "$0: write new $nailing: $!\n";
+       print N to_toml($toml) or die "$0: write new $nailing: $!\n";
        close N or die "$0: close new $nailing: $!\n";
     }
 }
 
+our $want_uninstall;
+
 END {
     if ($want_uninstall) {
        local ($?);
@@ -230,8 +233,14 @@ sub install () {
        my $nailing = "$mf.nailing~";
        my $nailed  = "$mf.nailed~";
        my ($use, $rm);
-       my $diff = compare($nailing, $nailed);
-       die "$0: compare $nailing and $nailed: $!" if $diff<0;
+       my $diff;
+       if (open NN, '<', $nailed) {
+           $diff = compare($nailing, \*NN);
+           die "$0: compare $nailing and $nailed: $!" if $diff<0;
+       } else {
+           $!==ENOENT or die "$0: check previous $nailed: $!\n";
+           $diff = 1;
+       }
        if ($diff) {
            $use = $nailing;
            $rm  = $nailed;
@@ -264,7 +273,7 @@ sub uninstall1 ($$) {
     my ($mf, $enoentok) = @_;
     my $unnailed = "$mf.unnailed";
     rename $unnailed, $mf or ($enoentok && $!==ENOENT)
-       die "$0: rename $unnailed back to $mf: $!\n";
+       or die "$0: rename $unnailed back to $mf: $!\n";
 }
 
 sub uninstall () {