Skip to content

Commit

Permalink
fix: truncate lock file
Browse files Browse the repository at this point in the history
Truncate it after successful locks and before an unlock.

This makes sure that we aren't left with garbage from previous runs.

Signed-off-by: Rudi Grinberg <me@rgrinberg.com>

<!-- ps-id: 21d117de-b760-42a5-82b9-8b60517dce90 -->
  • Loading branch information
rgrinberg committed May 24, 2024
1 parent 426571f commit 0b41674
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/dune_util/global_lock.ml
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,16 @@ module Lock = struct
| `Failure -> ()
| `Success ->
let fd = Flock.fd t in
Unix.ftruncate fd 0;
write_pid fd);
res
;;

let unlock () = Lazy.force t |> Flock.unlock |> or_raise_unix ~name:"unlock"
let unlock () =
let lock = Lazy.force t in
Unix.ftruncate (Flock.fd lock) 0;
Flock.unlock lock |> or_raise_unix ~name:"unlock"
;;
end

let locked = ref false
Expand Down Expand Up @@ -103,3 +108,5 @@ let unlock () =
Lock.unlock ();
locked := false)
;;

let () = at_exit unlock

0 comments on commit 0b41674

Please sign in to comment.