Commit
Author: Kevin Schoon [me@kevinschoon.com]
Hash: 5aea04c01bad401cf3be855b7c47c0ae7a0c1e52
Timestamp: Mon, 23 May 2022 03:19:19 +0000 (2 years ago)

+33 -35 +/-13 browse
migrate to core_unix for due to upstream changes
migrate to core_unix for due to upstream changes

Janestreet migrated pretty much all useful Unix OS level stuff into a new
module called core_unix.

https://blog.janestreet.com/goodbye-Core_kernel/
1diff --git a/bin/dune b/bin/dune
2index 43a0b41..d3bc829 100644
3--- a/bin/dune
4+++ b/bin/dune
5 @@ -3,6 +3,6 @@
6 (name note)
7 (preprocess
8 (pps ppx_jane))
9- (libraries note_lib base core dune-build-info)
10+ (libraries note_lib base core core_unix.command_unix dune-build-info)
11 (modes exe)
12 (ocamlopt_flags))
13 diff --git a/bin/note.ml b/bin/note.ml
14index 7866844..6ecd58e 100644
15--- a/bin/note.ml
16+++ b/bin/note.ml
17 @@ -268,7 +268,7 @@ let version =
18 | Some v -> Build_info.V1.Version.to_string v
19
20 let run =
21- Command.run ~version ~build_info:""
22+ Command_unix.run ~version ~build_info:""
23 (Command.group ~summary:"Note is a simple CLI based note taking application"
24 [
25 ("cat", cat_notes);
26 diff --git a/lib/config.ml b/lib/config.ml
27index 8bf09ee..abc4940 100644
28--- a/lib/config.ml
29+++ b/lib/config.ml
30 @@ -2,7 +2,7 @@ open Core
31
32 let noop a = a
33
34- let home = Sys.home_directory ()
35+ let home = Sys_unix.home_directory ()
36
37 let base_xdg_config_path = Filename.concat home ".config"
38
39 @@ -347,19 +347,19 @@ let set t key value =
40
41 let load path =
42 let cfg =
43- match Sys.file_exists path with
44+ match Sys_unix.file_exists path with
45 | `Yes -> of_string (In_channel.read_all path)
46 | `No | `Unknown ->
47- Unix.mkdir_p (Filename.dirname path);
48+ Core_unix.mkdir_p (Filename.dirname path);
49 Out_channel.write_all path ~data:(Ezjsonm.to_string (Ezjsonm.dict []));
50 of_string (In_channel.read_all path)
51 in
52
53 (* intiailize the state directory if it is missing *)
54- match Sys.file_exists cfg.state_dir with
55+ match Sys_unix.file_exists cfg.state_dir with
56 | `Yes -> cfg
57 | `No | `Unknown ->
58- Unix.mkdir_p cfg.state_dir;
59+ Core_unix.mkdir_p cfg.state_dir;
60 cfg
61
62 let save t = Out_channel.write_all ~data:(to_string t) config_path
63 diff --git a/lib/dune b/lib/dune
64index 6bd0172..78454e8 100644
65--- a/lib/dune
66+++ b/lib/dune
67 @@ -2,4 +2,4 @@
68 (name note_lib)
69 (preprocess
70 (pps ppx_jane))
71- (libraries ANSITerminal base core dune-build-info ezjsonm lambdasoup omd stdio re yaml))
72+ (libraries ANSITerminal base core core_unix core_unix.sys_unix core_unix.date_unix dune-build-info ezjsonm lambdasoup omd stdio re yaml))
73 diff --git a/lib/manifest.ml b/lib/manifest.ml
74index f2a0fcc..b843cdb 100644
75--- a/lib/manifest.ml
76+++ b/lib/manifest.ml
77 @@ -79,19 +79,19 @@ let mpath manifest = Filename.concat manifest.state_dir "manifest.json"
78
79 let lock manifest =
80 let lockfile = manifest |> lockfile in
81- match lockfile |> Sys.file_exists with
82+ match lockfile |> Sys_unix.file_exists with
83 | `Yes -> failwith "unable to aquire lock"
84 | `No | `Unknown -> Out_channel.write_all ~data:"<locked>" lockfile
85
86 let unlock manifest =
87 let lockfile = manifest |> lockfile in
88- match lockfile |> Sys.file_exists with
89- | `Yes -> Sys.remove lockfile
90+ match lockfile |> Sys_unix.file_exists with
91+ | `Yes -> Sys_unix.remove lockfile
92 | `No | `Unknown -> ()
93
94 let load_or_init state_dir =
95 let mpath = Filename.concat state_dir "manifest.json" in
96- match Sys.file_exists mpath with
97+ match Sys_unix.file_exists mpath with
98 | `Yes ->
99 mpath |> In_channel.read_all |> of_string ~state_dir:(Some state_dir)
100 | `No | `Unknown ->
101 diff --git a/lib/note.ml b/lib/note.ml
102index b72c8a0..c269e96 100644
103--- a/lib/note.ml
104+++ b/lib/note.ml
105 @@ -67,7 +67,7 @@ let extract_structured_data content =
106 in
107 let get_data ~values doc =
108 match doc with
109- | Omd.Code_block (_, kind, content) -> of_codeblock kind content @ values
110+ | Omd.Code_block (kind, content) -> of_codeblock kind content @ values
111 | _ -> values
112 in
113 let doc = content |> Omd.of_string in
114 @@ -184,7 +184,7 @@ module Adapter = struct
115 let editor_command ~editor path = Format.sprintf "%s %s" editor path
116
117 let run_or_noop command =
118- match command with Some command -> command |> Sys.command_exn | None -> ()
119+ match command with Some command -> command |> Sys_unix.command_exn | None -> ()
120
121 let load ~path options =
122 let manifest = options.state_dir |> Manifest.load_or_init in
123 @@ -235,7 +235,7 @@ module Adapter = struct
124 slug |> Slug.to_string |> Out_channel.write_all ~data:(note |> to_string);
125 slug |> Slug.to_string
126 |> editor_command ~editor:options.editor
127- |> Sys.command_exn);
128+ |> Sys_unix.command_exn);
129 options.on_modification |> run_or_noop;
130 manifest |> Manifest.save
131
132 @@ -246,7 +246,7 @@ module Adapter = struct
133 | Some item ->
134 let slug = item.slug in
135 let manifest = manifest |> Manifest.remove ~path in
136- slug |> Slug.to_string |> Unix.remove;
137+ slug |> Slug.to_string |> Sys_unix.remove;
138 options.on_modification |> run_or_noop;
139 manifest |> Manifest.save
140 | None -> failwith "not found"
141 @@ -259,7 +259,7 @@ module Adapter = struct
142 let slug = item.slug in
143 slug |> Slug.to_string
144 |> editor_command ~editor:options.editor
145- |> Sys.command_exn;
146+ |> Sys_unix.command_exn;
147 let note = slug |> Slug.to_string |> In_channel.read_all |> of_string in
148 let adjusted_path = note.frontmatter.path in
149 (if not (Filename.equal adjusted_path item.path) then
150 diff --git a/lib/slug.ml b/lib/slug.ml
151index 200ef29..a05ab1a 100644
152--- a/lib/slug.ml
153+++ b/lib/slug.ml
154 @@ -9,7 +9,7 @@ let to_string slug = slug.path
155 let of_string ?(basepath = None) path =
156 let result = Re.all pattern path |> List.hd_exn in
157 let items = Re.Group.all result |> Array.to_list in
158- let date = Date.parse ~fmt:"%Y%m%d" (List.nth_exn items 2) in
159+ let date = Date_unix.parse ~fmt:"%Y%m%d" (List.nth_exn items 2) in
160 let index = int_of_string (List.nth_exn items 3) in
161 let path =
162 match basepath with
163 @@ -24,7 +24,7 @@ let of_string ?(basepath = None) path =
164 { path; date; index }
165
166 let shortname t =
167- let date_str = Date.format t.date "%Y%m%d" in
168+ let date_str = Date_unix.format t.date "%Y%m%d" in
169 sprintf "note-%s-%d" date_str t.index
170
171 let append ~path t =
172 @@ -37,13 +37,13 @@ let is_note path =
173 Filename.basename path |> String.is_substring ~substring:"note-"
174
175 let load state_dir =
176- state_dir |> Sys.ls_dir |> List.filter ~f:is_note
177+ state_dir |> Sys_unix.ls_dir |> List.filter ~f:is_note
178 |> List.map ~f:(Filename.concat state_dir)
179 |> List.map ~f:of_string
180
181 let next ?(last = None) state_dir =
182 let today = Time.now () |> Time.to_date ~zone:Time.Zone.utc in
183- let today_str = Date.format today "%Y%m%d" in
184+ let today_str = Date_unix.format today "%Y%m%d" in
185 match last with
186 | Some last ->
187 let tomorrow = Date.add_days today 1 in
188 diff --git a/lib/sync.ml b/lib/sync.ml
189index 70f6507..83a97e9 100644
190--- a/lib/sync.ml
191+++ b/lib/sync.ml
192 @@ -1,6 +1,4 @@
193- open Core
194-
195 let sync on_sync =
196 match on_sync with
197- | Some cmd -> Sys.command_exn cmd
198+ | Some cmd -> Sys_unix.command_exn cmd
199 | None -> ()
200 diff --git a/test/config_test.ml b/test/config_test.ml
201index 0aef5c2..c5770ee 100644
202--- a/test/config_test.ml
203+++ b/test/config_test.ml
204 @@ -2,7 +2,7 @@ open Core
205 open Note_lib
206
207 let test_configuration () =
208- let config_path = Filename.temp_file "note-test" "" in
209+ let config_path = Filename_unix.temp_file "note-test" "" in
210 let _ = config_path |> Config.load in
211 Alcotest.(check bool) "config loaded" true true
212
213 diff --git a/test/dune b/test/dune
214index eaab266..1f0b726 100644
215--- a/test/dune
216+++ b/test/dune
217 @@ -1,4 +1,4 @@
218 (tests
219 (names config_test display_test manifest_test note_test slug_test)
220- (libraries note_lib alcotest)
221+ (libraries note_lib alcotest core_unix.filename_unix core_unix.time_unix)
222 )
223 diff --git a/test/manifest_test.ml b/test/manifest_test.ml
224index 5e9b421..94ed81d 100644
225--- a/test/manifest_test.ml
226+++ b/test/manifest_test.ml
227 @@ -3,7 +3,7 @@ open Note_lib
228
229 let test_recurse () =
230 let manifest =
231- Manifest.make (Filename.temp_dir "note-test" "")
232+ Manifest.make (Filename_unix.temp_dir "note-test" "")
233 |> Manifest.create ~path:"/"
234 |> Manifest.create ~path:"/a"
235 |> Manifest.create ~path:"/a/b"
236 @@ -18,7 +18,7 @@ let test_recurse () =
237 Alcotest.(check int) "n_results" 0 (List.length (manifest |> Manifest.list ~path:"/a/b/c/d"))
238
239 let test_manifest () =
240- let manifest = Manifest.make (Filename.temp_dir "note-test" "") in
241+ let manifest = Manifest.make (Filename_unix.temp_dir "note-test" "") in
242 manifest |> Manifest.save;
243 let manifest =
244 Manifest.load_or_init manifest.state_dir |> Manifest.create ~path:"/fuu"
245 @@ -45,7 +45,7 @@ let test_manifest () =
246
247 let test_move () =
248 let manifest =
249- Manifest.make (Filename.temp_dir "note-test" "")
250+ Manifest.make (Filename_unix.temp_dir "note-test" "")
251 |> Manifest.create ~path:"/a"
252 |> Manifest.create ~path:"/a/b"
253 in
254 diff --git a/test/note_test.ml b/test/note_test.ml
255index 3a9c76a..946899a 100644
256--- a/test/note_test.ml
257+++ b/test/note_test.ml
258 @@ -23,7 +23,7 @@ description: "baz"
259 let adapter () =
260 let options : Note.options =
261 {
262- state_dir = Filename.temp_dir "note-test" "";
263+ state_dir = Filename_unix.temp_dir "note-test" "";
264 editor = "true";
265 on_modification = None;
266 }
267 @@ -42,7 +42,7 @@ let adapter () =
268 let suggest_path () =
269 let options : Note.options =
270 {
271- state_dir = Filename.temp_dir "note-test" "";
272+ state_dir = Filename_unix.temp_dir "note-test" "";
273 editor = "true";
274 on_modification = None;
275 }
276 @@ -62,7 +62,7 @@ let suggest_path () =
277 let suggest_tags () =
278 let options : Note.options =
279 {
280- state_dir = Filename.temp_dir "note-test" "";
281+ state_dir = Filename_unix.temp_dir "note-test" "";
282 editor = "true";
283 on_modification = None;
284 }
285 diff --git a/test/slug_test.ml b/test/slug_test.ml
286index 0c34fc7..78a71ff 100644
287--- a/test/slug_test.ml
288+++ b/test/slug_test.ml
289 @@ -21,8 +21,8 @@ let test_slug_comparable () =
290 Alcotest.(check bool) "identical paths" true (Slug.compare s1 s2 = 0)
291
292 let test_slug_path () =
293- let date_string = Time.format (Time.now ()) "%Y%m%d" ~zone:Time.Zone.utc in
294- let state_dir = Filename.temp_dir "note-test" "" in
295+ let date_string = Time_unix.format (Time.now ()) "%Y%m%d" ~zone:Time.Zone.utc in
296+ let state_dir = Filename_unix.temp_dir "note-test" "" in
297 let slug = Slug.next state_dir in
298 let expected =
299 Filename.concat state_dir (sprintf "note-%s-0.md" date_string)
300 @@ -30,7 +30,7 @@ let test_slug_path () =
301 Alcotest.(check string) "path" expected slug.path
302
303 let test_slug_increment () =
304- let date_string = Time.format (Time.now ()) "%Y%m%d" ~zone:Time.Zone.utc in
305+ let date_string = Time_unix.format (Time.now ()) "%Y%m%d" ~zone:Time.Zone.utc in
306 let slug = Slug.next "/fuu/bar" in
307 let expected = sprintf "/fuu/bar/note-%s-%d.md" date_string 0 in
308 Alcotest.(check string) "check path" expected (slug |> Slug.to_string);