File tree Expand file tree Collapse file tree 3 files changed +35
-14
lines changed Expand file tree Collapse file tree 3 files changed +35
-14
lines changed Original file line number Diff line number Diff line change @@ -205,7 +205,7 @@ let build =
205
205
state of the lock could otherwise change between checking it and taking
206
206
it. *)
207
207
match Dune_util.Global_lock. lock ~timeout: None with
208
- | Error () ->
208
+ | Error _lock_held_by ->
209
209
(* This case is reached if dune detects that another instance of dune
210
210
is already running. Rather than performing the build itself, the
211
211
current instance of dune will instruct the already-running instance to
Original file line number Diff line number Diff line change 66
66
67
67
let locked = ref false
68
68
69
+ module Lock_held_by = struct
70
+ type t =
71
+ | Pid_from_lockfile of string
72
+ | Unknown
73
+
74
+ let read_lock_file () =
75
+ match Io. read_file (Path. build lock_file) with
76
+ | exception _ -> Unknown
77
+ | pid -> Pid_from_lockfile pid
78
+ ;;
79
+
80
+ let message t =
81
+ Pp. textf
82
+ " A running dune%s instance has locked the build directory. If this is not the \
83
+ case, please delete %S."
84
+ (match t with
85
+ | Unknown -> " "
86
+ | Pid_from_lockfile pid -> sprintf " (pid: %s)" pid)
87
+ (Path.Build. to_string_maybe_quoted lock_file)
88
+ ;;
89
+ end
90
+
69
91
let lock ~timeout =
70
92
match Config. (get global_lock) with
71
93
| `Disabled -> Ok ()
@@ -90,22 +112,15 @@ let lock ~timeout =
90
112
| `Success ->
91
113
locked := true ;
92
114
Ok ()
93
- | `Failure -> Error () )
115
+ | `Failure ->
116
+ let lock_held_by = Lock_held_by. read_lock_file () in
117
+ Error lock_held_by)
94
118
;;
95
119
96
120
let lock_exn ~timeout =
97
121
match lock ~timeout with
98
122
| Ok () -> ()
99
- | Error () ->
100
- User_error. raise
101
- [ Pp. textf
102
- " A running dune%s instance has locked the build directory. If this is not the \
103
- case, please delete %s"
104
- (match Io. read_file (Path. build lock_file) with
105
- | exception _ -> " "
106
- | pid -> sprintf " (pid: %s)" pid)
107
- (Path.Build. to_string_maybe_quoted lock_file)
108
- ]
123
+ | Error lock_held_by -> User_error. raise [ Lock_held_by. message lock_held_by ]
109
124
;;
110
125
111
126
let unlock () =
Original file line number Diff line number Diff line change 2
2
3
3
Before starting rpc, writing to the build dir, this lock should be locked. *)
4
4
5
- (* * attempt to acquire a lock. once a lock is locked, subsequent locks always
5
+ module Lock_held_by : sig
6
+ type t
7
+
8
+ val message : t -> 'a Pp .t
9
+ end
10
+
11
+ (* * Attempt to acquire a lock. once a lock is locked, subsequent locks always
6
12
succeed. Returns [Ok ()] if the lock is acquired within [timeout] seconds,
7
13
and [Error ()] otherwise. *)
8
- val lock : timeout :float option -> (unit , unit ) result
14
+ val lock : timeout :float option -> (unit , Lock_held_by .t ) result
9
15
10
16
val lock_exn : timeout :float option -> unit
11
17
You can’t perform that action at this time.
0 commit comments