@@ -38,9 +38,9 @@ let rec rdecons = function
38
38
| [] -> None
39
39
| [ x ] -> Some ([] , x)
40
40
| x :: xs -> (
41
- match rdecons xs with
42
- | None -> None
43
- | Some (xs , leaf ) -> Some (x :: xs, leaf) )
41
+ match rdecons xs with
42
+ | None -> None
43
+ | Some (xs , leaf ) -> Some (x :: xs, leaf) )
44
44
45
45
let ok x = Lwt. return (Ok x)
46
46
@@ -119,7 +119,7 @@ module Make (P9p : Protocol_9p.Client.S) = struct
119
119
type t = {
120
120
read : unit -> Cstruct .t result ;
121
121
mutable buffer : string ;
122
- mutable eof : bool
122
+ mutable eof : bool ;
123
123
}
124
124
125
125
let create read = { buffer = " " ; read; eof = false }
@@ -161,14 +161,14 @@ module Make (P9p : Protocol_9p.Client.S) = struct
161
161
match String. cut ~sep: " " line with
162
162
| None -> err " missing space"
163
163
| Some (op , path ) -> (
164
- match Path. of_string path with
165
- | Error e -> err e
166
- | Ok path -> (
167
- match op with
168
- | "+" -> `Added path :: acc
169
- | "-" -> `Removed path :: acc
170
- | "*" -> `Updated path :: acc
171
- | e -> err e ) ) )
164
+ match Path. of_string path with
165
+ | Error e -> err e
166
+ | Ok path -> (
167
+ match op with
168
+ | "+" -> `Added path :: acc
169
+ | "-" -> `Removed path :: acc
170
+ | "*" -> `Updated path :: acc
171
+ | e -> err e ) ))
172
172
[] lines
173
173
|> ok
174
174
with Err e -> bug " %s" e
@@ -181,7 +181,8 @@ module Make (P9p : Protocol_9p.Client.S) = struct
181
181
let with_file_full t path fn =
182
182
P9p. with_fid t.conn (fun newfid ->
183
183
P9p. walk_from_root t.conn newfid path > |= wrap_9p >> *= fn newfid
184
- > |= fun x -> Ok x )
184
+ > |= fun x ->
185
+ Ok x)
185
186
> |= function
186
187
| Ok x -> x (* Error or success from [fn] *)
187
188
| Error _ as e -> wrap_9p e
@@ -223,38 +224,39 @@ module Make (P9p : Protocol_9p.Client.S) = struct
223
224
> |= wrap_9p
224
225
>> *= fun _open ->
225
226
write_to_fid t fid ~offset: 0L data > |= wrap_9p >> *= fun _resp ->
226
- ok () )
227
+ ok () )
227
228
228
229
let create_symlink t ~dir leaf target =
229
230
Log. debug (fun f ->
230
- f " create_symlink %a -> %s" pp_path (dir / leaf) target );
231
+ f " create_symlink %a -> %s" pp_path (dir / leaf) target);
231
232
with_file t dir (fun fid ->
232
233
P9p.LowLevel. create ~extension: target t.conn fid leaf symlink
233
234
Protocol_9p.Types.OpenMode. write_only
234
235
> |= wrap_9p
235
- >> *= fun _resp -> ok () )
236
+ >> *= fun _resp ->
237
+ ok () )
236
238
237
239
let replace_file t path leaf data =
238
240
Log. debug (fun f ->
239
241
f " replace_file %a -> %S" pp_path (path / leaf)
240
- (Cstruct. to_string data) );
242
+ (Cstruct. to_string data));
241
243
with_file t (path / leaf) (fun fid ->
242
244
P9p.LowLevel. update ~length: 0L t.conn fid > |= wrap_9p >> *= fun () ->
243
245
P9p.LowLevel. openfid t.conn fid Protocol_9p.Types.OpenMode. write_only
244
246
> |= wrap_9p
245
247
>> *= fun _open ->
246
248
write_to_fid t fid ~offset: 0L data > |= wrap_9p >> *= fun _resp ->
247
- ok () )
249
+ ok () )
248
250
249
251
let write_stream t path data =
250
252
Log. debug (fun f ->
251
- f " write %S to %a" (Cstruct. to_string data) pp_path path );
253
+ f " write %S to %a" (Cstruct. to_string data) pp_path path);
252
254
with_file t path (fun fid ->
253
255
P9p.LowLevel. openfid t.conn fid Protocol_9p.Types.OpenMode. write_only
254
256
> |= wrap_9p
255
257
>> *= fun _open ->
256
258
write_to_fid t fid ~offset: 0L data > |= wrap_9p >> *= fun _resp ->
257
- ok () )
259
+ ok () )
258
260
259
261
(* TODO: limited to 2 GB files *)
260
262
let read_all t path =
@@ -270,7 +272,7 @@ module Make (P9p : Protocol_9p.Client.S) = struct
270
272
let truncate t path new_length =
271
273
Log. debug (fun f -> f " truncate %a to %Ld" pp_path path new_length);
272
274
with_file t path (fun fid ->
273
- P9p.LowLevel. update t.conn ~length: new_length fid > |= wrap_9p )
275
+ P9p.LowLevel. update t.conn ~length: new_length fid > |= wrap_9p)
274
276
275
277
let read_node_aux ~link ~file ~dir t path =
276
278
let open Protocol_9p.Types in
@@ -280,12 +282,15 @@ module Make (P9p : Protocol_9p.Client.S) = struct
280
282
| Some qid when List. mem Qid. Symlink qid.Qid. flags -> link t path
281
283
| Some qid when not (List. mem Qid. Directory qid.Qid. flags) ->
282
284
file t path
283
- | _ -> dir t path )
285
+ | _ -> dir t path)
284
286
285
287
let read_link_aux t path =
286
- read_all t path >> *= fun data -> ok (`Link (Cstruct. to_string data))
288
+ read_all t path >> *= fun data ->
289
+ ok (`Link (Cstruct. to_string data))
287
290
288
- let read_file_aux t path = read_all t path >> *= fun data -> ok (`File data)
291
+ let read_file_aux t path =
292
+ read_all t path >> *= fun data ->
293
+ ok (`File data)
289
294
290
295
let read_dir_aux t path =
291
296
P9p. readdir t.conn path > |= wrap_9p >> *= fun items ->
@@ -300,17 +305,20 @@ module Make (P9p : Protocol_9p.Client.S) = struct
300
305
let read_link t path =
301
306
let err _ _ = Lwt. return (Error `Not_symlink ) in
302
307
read_node_aux ~link: read_link_aux ~file: err ~dir: err t path
303
- > |*= fun (`Link l ) -> l
308
+ > |*= fun (`Link l ) ->
309
+ l
304
310
305
311
let read_file t path =
306
312
let err _ _ = Lwt. return (Error `Not_file ) in
307
313
read_node_aux ~link: err ~file: read_file_aux ~dir: err t path
308
- > |*= fun (`File l ) -> l
314
+ > |*= fun (`File l ) ->
315
+ l
309
316
310
317
let read_dir t path =
311
318
let err _ _ = Lwt. return (Error `Not_dir ) in
312
319
read_node_aux ~link: err ~file: err ~dir: read_dir_aux t path
313
- > |*= fun (`Dir l ) -> l
320
+ > |*= fun (`Dir l ) ->
321
+ l
314
322
315
323
let stat t path =
316
324
P9p. stat t.conn path > |= wrap_9p >> = function
@@ -342,7 +350,7 @@ module Make (P9p : Protocol_9p.Client.S) = struct
342
350
Log. debug (fun f -> f " set_executable %a to %b" pp_path path exec);
343
351
let mode = if exec then rwxr_xr_x else rw_r__r__ in
344
352
with_file t path (fun fid ->
345
- P9p.LowLevel. update t.conn ~mode fid > |= wrap_9p )
353
+ P9p.LowLevel. update t.conn ~mode fid > |= wrap_9p)
346
354
347
355
let random_subdir t parent =
348
356
let rec aux = function
@@ -377,7 +385,7 @@ module Make (P9p : Protocol_9p.Client.S) = struct
377
385
let th = ref (next () ) in
378
386
Lwt_switch. add_hook_or_exec switch (fun () ->
379
387
Lwt. cancel ! th;
380
- Lwt. return () )
388
+ Lwt. return () )
381
389
>> = fun () ->
382
390
let rec loop () =
383
391
abort_if_off switch @@ fun () ->
@@ -392,15 +400,17 @@ module Make (P9p : Protocol_9p.Client.S) = struct
392
400
loop () )
393
401
in
394
402
Lwt. catch loop (function
395
- | Lwt. Canceled as ex -> abort_if_off switch @@ fun () -> Lwt. fail ex
396
- | ex -> Lwt. fail ex )
403
+ | Lwt. Canceled as ex ->
404
+ abort_if_off switch @@ fun () ->
405
+ Lwt. fail ex
406
+ | ex -> Lwt. fail ex)
397
407
398
408
(* Ensure that [base @ path] exists (assuming that [base] already exists). *)
399
409
let make_dirs t ~base path =
400
410
let path = Path. unwrap path in
401
411
let rec aux user_path =
402
412
Log. debug (fun f ->
403
- f " make_dirs.aux(%a)" (Fmt.Dump. list String. dump) user_path );
413
+ f " make_dirs.aux(%a)" (Fmt.Dump. list String. dump) user_path);
404
414
match rdecons user_path with
405
415
| None -> ok ()
406
416
| Some (dir , leaf ) -> (
@@ -432,7 +442,7 @@ module Make (P9p : Protocol_9p.Client.S) = struct
432
442
fs : FS .t ;
433
443
path : string list ;
434
444
reads : value cache ;
435
- stats : stat option cache
445
+ stats : stat option cache ;
436
446
}
437
447
438
448
let find_cache c p = try Some (Path.Map. find p ! c) with Not_found -> None
@@ -588,13 +598,13 @@ module Make (P9p : Protocol_9p.Client.S) = struct
588
598
let rec aux = function
589
599
| [] -> Ok []
590
600
| x :: xs -> (
591
- match Path. of_string x with
592
- | Error e ->
593
- Error (`Internal (Fmt. strf " Invalid path in conflicts: %s" e))
594
- | Ok path -> (
595
- match aux xs with
596
- | Error _ as e -> e
597
- | Ok paths -> Ok (path :: paths) ) )
601
+ match Path. of_string x with
602
+ | Error e ->
603
+ Error (`Internal (Fmt. strf " Invalid path in conflicts: %s" e))
604
+ | Ok path -> (
605
+ match aux xs with
606
+ | Error _ as e -> e
607
+ | Ok paths -> Ok (path :: paths) ) )
598
608
in
599
609
Lwt. return (aux paths)
600
610
@@ -627,9 +637,9 @@ module Make (P9p : Protocol_9p.Client.S) = struct
627
637
>> = function
628
638
| Error e ->
629
639
Log. err (fun f ->
630
- f " Error aborting transaction %a: %a" pp_path t.path pp_error e
631
- );
640
+ f " Error aborting transaction %a: %a" pp_path t.path pp_error e);
632
641
t.closed < - true ;
642
+
633
643
(* Give up *)
634
644
Lwt. return (Ok () )
635
645
| Ok () ->
@@ -677,7 +687,8 @@ module Make (P9p : Protocol_9p.Client.S) = struct
677
687
let create fs name =
678
688
(* Note: DataKit returns success if the branch already exists too,
679
689
so no need to handle errors here. *)
680
- FS. create_dir fs ~dir: [ " branch" ] name > |*= fun () -> { fs; name }
690
+ FS. create_dir fs ~dir: [ " branch" ] name > |*= fun () ->
691
+ { fs; name }
681
692
682
693
let remove t = FS. remove t.fs (branch_dir t)
683
694
@@ -735,20 +746,20 @@ module Make (P9p : Protocol_9p.Client.S) = struct
735
746
(* Make sure the user doesn't think their transaction succeeded *)
736
747
failwith
737
748
" Transaction returned Ok without committing or aborting (so \
738
- forced abort)" )
749
+ forced abort)" )
739
750
(fun () ->
740
751
if tr.Transaction. closed then Lwt. return ()
741
752
else (
742
753
(* Just log, so we don't hide the underlying error *)
743
754
Log. info (fun f ->
744
755
f
745
756
" Transaction finished without committing or aborting (will \
746
- abort)" );
757
+ abort)" );
747
758
Transaction. abort tr > |= function
748
759
| Ok () -> ()
749
760
| Error e ->
750
761
Fmt. kstrf failwith " error while aborting the transaction: %a"
751
- pp_error e ) )
762
+ pp_error e ))
752
763
end
753
764
754
765
let branch t name = Branch. create t name
@@ -770,12 +781,12 @@ module Make (P9p : Protocol_9p.Client.S) = struct
770
781
>> *= fun () ->
771
782
FS. read_all t (path / " head" ) >> *= fun commit_id ->
772
783
let id = String. trim (Cstruct. to_string commit_id) in
773
- ok { Commit. fs = t; id } )
784
+ ok { Commit. fs = t; id })
774
785
(fun () ->
775
786
FS. remove t path > |= function
776
787
| Error e ->
777
788
Log. err (fun f -> f " Error removing remote %S: %a" id pp_error e)
778
- | Ok () -> () )
789
+ | Ok () -> () )
779
790
780
791
let commit t id : Commit.t result =
781
792
FS. read_all t ([ " commits" ] / id) >> *= fun _json ->
@@ -785,7 +796,9 @@ module Make (P9p : Protocol_9p.Client.S) = struct
785
796
786
797
let connect conn = { FS. conn }
787
798
788
- let disconnect t = P9p. disconnect t.FS. conn > |= fun () -> Ok ()
799
+ let disconnect t =
800
+ P9p. disconnect t.FS. conn > |= fun () ->
801
+ Ok ()
789
802
790
803
type t = FS .t
791
804
end
0 commit comments