Skip to content

Commit 1fdd2a4

Browse files
committed
Factor out path_is_an_empty_dir
1 parent 5f51bcc commit 1fdd2a4

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/sys/stm_tests.ml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ struct
190190
| Some File -> false
191191
| Some (Directory _) -> true
192192

193+
let path_is_an_empty_dir fs path =
194+
Model.readdir fs path = Some []
195+
193196
let path_is_a_file fs path =
194197
match Model.find_opt fs path with
195198
| None
@@ -227,11 +230,11 @@ struct
227230
| Some File ->
228231
if (not (Model.mem fs new_path) || path_is_a_file fs new_path) then Model.rename fs old_path new_path else fs
229232
| Some (Directory _) ->
230-
if (not (Model.mem fs new_path) || Model.readdir fs new_path = Some []) then Model.rename fs old_path new_path else fs)
233+
if (not (Model.mem fs new_path) || path_is_an_empty_dir fs new_path) then Model.rename fs old_path new_path else fs)
231234
| Is_directory _path -> fs
232235
| Rmdir (path,delete_dir_name) ->
233236
let complete_path = path @ [delete_dir_name] in
234-
if Model.mem fs complete_path && Model.readdir fs complete_path = Some []
237+
if Model.mem fs complete_path && path_is_an_empty_dir fs complete_path
235238
then Model.remove fs path delete_dir_name
236239
else fs
237240
| Readdir _path -> fs
@@ -313,7 +316,7 @@ struct
313316
path_is_a_dir fs old_path && Model.mem fs new_path && not (path_is_a_dir fs new_path)) ||
314317
(s = "Is a directory" && path_is_a_dir fs new_path) ||
315318
(s = "Directory not empty" &&
316-
is_true_prefix new_path old_path || (path_is_a_dir fs new_path && not (Model.readdir fs new_path = Some [])))
319+
is_true_prefix new_path old_path || (path_is_a_dir fs new_path && not (path_is_an_empty_dir fs new_path)))
317320
| Error _ -> false)
318321
| Mkdir (path, new_dir_name), Res ((Result (Unit,Exn),_), res) ->
319322
let complete_path = (path @ [new_dir_name]) in
@@ -337,14 +340,14 @@ struct
337340
(match err with
338341
| Sys_error s ->
339342
(s = (p complete_path) ^ ": Permission denied") ||
340-
(s = (p complete_path) ^ ": Directory not empty" && not (Model.readdir fs complete_path = Some [])) ||
343+
(s = (p complete_path) ^ ": Directory not empty" && not (path_is_an_empty_dir fs complete_path)) ||
341344
(s = (p complete_path) ^ ": No such file or directory" && not (Model.mem fs complete_path)) ||
342345
if Sys.win32 && not (path_is_a_dir fs complete_path) (* if not a directory *)
343346
then s = (p complete_path) ^ ": Invalid argument"
344347
else s = (p complete_path) ^ ": Not a directory"
345348
| _ -> false)
346349
| Ok () ->
347-
Model.mem fs complete_path && path_is_a_dir fs complete_path && Model.readdir fs complete_path = Some [])
350+
Model.mem fs complete_path && path_is_a_dir fs complete_path && path_is_an_empty_dir fs complete_path)
348351
| Readdir path, Res ((Result (Array String,Exn),_), res) ->
349352
(match res with
350353
| Error err ->

0 commit comments

Comments
 (0)