chiark / gitweb /
Provide --no-lock option
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 12 Sep 2020 11:32:18 +0000 (12:32 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 12 Sep 2020 11:46:25 +0000 (12:46 +0100)
This will have a more common sane use case in a moment...

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
README.md
nailing-cargo

index 4798d401bab264dc54ba8b809142942a6529a132..fbba6988335daa52772193162ba5d8aa6bb37264 100644 (file)
--- a/README.md
+++ b/README.md
@@ -379,6 +379,12 @@ Options
      `.Cargo.toml.nailed~`, so you only need this if you want to run
     cargo by hand or something.
 
+  * `--no-lock` | `--lock` (default): Whether to take the
+    nailing-cargo lock.  Some kind of protection against concurrent
+    operation is necessary to prevent multiple instances of
+    nailing-cargo trashing each others' work, and possibly mangling
+    your `Cargo.toml`s.
+
   * `-h` | `--help`: Print usage summary.
 
   * `--man` | `--manual`: Format this manual into html using `pandoc`
index cf13b6d24b6a226aaa2de180118af604ab4e62d1..b2f1f8c0268615d69b219998f1f699ce7a7bc503 100755 (executable)
@@ -28,6 +28,7 @@ options:
   --man --manual                  Display complete manual (in w3m)
   --leave-nailed                  Leave the nailed Cargo.toml in place
   --just-linkfarm | --clean-linkfarm | --keep-linkfarm (default)
+  --no-lock                       Do not take the lock.
 
   -s<subcommand>                  Treat command as `cargo <subcommand>`
   --subcommand-props=<prop>,...   Override command props (see docs)
@@ -90,6 +91,7 @@ our $online;
 our $just_linkfarm;
 our $leave_nailed;
 our $oot_clean;
+our $do_lock=1;
 
 #
 our %subcmd_props = (
@@ -177,6 +179,8 @@ sub same_file ($$) {
 }
 
 sub takelock () {
+  return unless $do_lock;
+
   for (;;) {
     open LOCK, ">", $lockfile or die "$self: open/create $lockfile: $!\n";
     flock LOCK, LOCK_EX or die "$self: lock $lockfile: $!\n";
@@ -496,6 +500,8 @@ sub calculate () {
     print STDERR "$self: package $p in $packagemap{$p}[0]\n" if $verbose>=2;
   }
   foreach my $mf (keys %manifests) {
+    die "internal error" if $do_nail; # belt and braces
+
     my ($toml, $mf_org_subdir) = @{ $manifests{$mf} };
     foreach my $deps (get_dependency_tables $toml) {
       next unless $deps;
@@ -934,6 +940,8 @@ sub parse_args () {
       $cargo_lock_update= 1;
     } elsif (m{^--(clean|keep)-linkfarm$}) {
       $oot_clean = $1 eq 'clean';
+    } elsif (m{^--(no)?-lock$}) {
+      $do_lock = !$1;
     } elsif (m{^--leave-nailed$}) {
       $leave_nailed = 1;
     } elsif (s{^--subcommand-props=}{}) {