@@ -70,32 +70,35 @@ open Eio.Std
70
70
71
71
type partial = (string * compiled ) list * Packages .modulety Util.StringMap .t
72
72
73
- let unmarshal filename =
73
+ let unmarshal filename : partial =
74
74
let ic = open_in_bin (Fpath. to_string filename) in
75
- let (v : partial ) = Marshal. from_channel ic in
76
- close_in ic;
77
- v
75
+ Fun. protect
76
+ ~finally: ( fun () -> close_in ic)
77
+ ( fun () -> Marshal. from_channel ic)
78
78
79
79
let marshal (v : partial ) filename =
80
80
let p = Fpath. parent filename in
81
81
Util. mkdir_p p;
82
82
let oc = open_out_bin (Fpath. to_string filename) in
83
- Marshal. to_channel oc v [] ;
84
- close_out oc
83
+ Fun. protect
84
+ ~finally: (fun () -> close_out oc)
85
+ (fun () -> Marshal. to_channel oc v [] )
85
86
86
87
let find_partials odoc_dir =
87
88
let tbl = Hashtbl. create 1000 in
88
89
let hashes_result =
89
- Bos.OS.Dir. fold_contents ~dotfiles: false
90
+ Bos.OS.Dir. fold_contents ~dotfiles: false ~elements: `Dirs
90
91
(fun p hashes ->
91
- if Fpath. filename p = " index.m" then (
92
- let tbl', hashes' = unmarshal p in
93
- List. iter
94
- (fun (k , v ) ->
95
- Hashtbl. replace tbl k (Promise. create_resolved (Ok v)))
96
- tbl';
97
- Util.StringMap. union (fun _x o1 _o2 -> Some o1) hashes hashes')
98
- else hashes)
92
+ let index_m = Fpath. ( / ) p " index.m" in
93
+ match Bos.OS.File. exists index_m with
94
+ | Ok true ->
95
+ let tbl', hashes' = unmarshal index_m in
96
+ List. iter
97
+ (fun (k , v ) ->
98
+ Hashtbl. replace tbl k (Promise. create_resolved (Ok v)))
99
+ tbl';
100
+ Util.StringMap. union (fun _x o1 _o2 -> Some o1) hashes hashes'
101
+ | _ -> hashes)
99
102
Util.StringMap. empty odoc_dir
100
103
in
101
104
match hashes_result with
0 commit comments