@@ -280,6 +280,8 @@ struct
280280 | Mkfile (path , new_file_name ) ->
281281 Res (result unit exn , protect mkfile (p path / new_file_name))
282282
283+ let match_err err path msg = err = (p path) ^ " : " ^ msg
284+
283285 let postcond c (fs : filesys ) res =
284286 match c, res with
285287 | File_exists path , Res ((Bool,_ ),b ) -> b = Model. mem fs path
@@ -291,19 +293,19 @@ struct
291293 | Some File -> b = false
292294 | None -> false )
293295 | Error (Sys_error s ) ->
294- (s = (p path) ^ " : No such file or directory" && not (Model. mem fs path)) ||
295- (s = p path ^ " : Not a directory" && List. exists (fun pref -> not (path_is_a_dir fs pref)) (path_prefixes path))
296+ (match_err s path " No such file or directory" && not (Model. mem fs path)) ||
297+ (match_err s path " Not a directory" && List. exists (fun pref -> not (path_is_a_dir fs pref)) (path_prefixes path))
296298 | _ -> false )
297299 | Remove (path , file_name ), Res ((Result (Unit,Exn),_ ), res ) ->
298300 let complete_path = (path @ [file_name]) in
299301 (match res with
300302 | Ok () -> Model. mem fs complete_path && path_is_a_dir fs path && not (path_is_a_dir fs complete_path)
301303 | Error (Sys_error s ) ->
302- (s = (p complete_path) ^ " : No such file or directory" && not (Model. mem fs complete_path)) ||
303- (s = (p complete_path) ^ " : Is a directory" && path_is_a_dir fs complete_path) || (* Linux*)
304- (s = (p complete_path) ^ " : Operation not permitted" && path_is_a_dir fs complete_path) || (* macOS*)
305- (s = (p complete_path) ^ " : Permission denied" && path_is_a_dir fs complete_path) || (* Win*)
306- (s = (p complete_path) ^ " : Not a directory" && not (path_is_a_dir fs path))
304+ (match_err s complete_path " No such file or directory" && not (Model. mem fs complete_path)) ||
305+ (match_err s complete_path " Is a directory" && path_is_a_dir fs complete_path) || (* Linux*)
306+ (match_err s complete_path " Operation not permitted" && path_is_a_dir fs complete_path) || (* macOS*)
307+ (match_err s complete_path " Permission denied" && path_is_a_dir fs complete_path) || (* Win*)
308+ (match_err s complete_path " Not a directory" && not (path_is_a_dir fs path))
307309 | Error _ -> false
308310 )
309311 | Rename (old_path , new_path ), Res ((Result (Unit,Exn),_ ), res ) ->
@@ -327,13 +329,13 @@ struct
327329 | Error err ->
328330 (match err with
329331 | Sys_error s ->
330- (s = (p complete_path) ^ " : Permission denied" ) ||
331- (s = (p complete_path) ^ " : File exists" && Model. mem fs complete_path) ||
332- ((s = (p complete_path) ^ " : No such file or directory"
333- || s = (p complete_path) ^ " : Invalid argument" ) && not (Model. mem fs path)) ||
332+ (match_err s complete_path " Permission denied" ) ||
333+ (match_err s complete_path " File exists" && Model. mem fs complete_path) ||
334+ ((match_err s complete_path " No such file or directory"
335+ || match_err s complete_path " Invalid argument" ) && not (Model. mem fs path)) ||
334336 if Sys. win32 && not (path_is_a_dir fs complete_path)
335- then s = (p complete_path) ^ " : No such file or directory"
336- else s = (p complete_path) ^ " : Not a directory"
337+ then match_err s complete_path " No such file or directory"
338+ else match_err s complete_path " Not a directory"
337339 | _ -> false )
338340 | Ok () -> Model. mem fs path && path_is_a_dir fs path && not (Model. mem fs complete_path))
339341 | Rmdir (path , delete_dir_name ), Res ((Result (Unit,Exn),_ ), res ) ->
@@ -342,12 +344,12 @@ struct
342344 | Error err ->
343345 (match err with
344346 | Sys_error s ->
345- (s = (p complete_path) ^ " : Permission denied" ) ||
346- (s = (p complete_path) ^ " : Directory not empty" && not (path_is_an_empty_dir fs complete_path)) ||
347- (s = (p complete_path) ^ " : No such file or directory" && not (Model. mem fs complete_path)) ||
347+ (match_err s complete_path " Permission denied" ) ||
348+ (match_err s complete_path " Directory not empty" && not (path_is_an_empty_dir fs complete_path)) ||
349+ (match_err s complete_path " No such file or directory" && not (Model. mem fs complete_path)) ||
348350 if Sys. win32 && not (path_is_a_dir fs complete_path) (* if not a directory *)
349- then s = (p complete_path) ^ " : Invalid argument"
350- else s = (p complete_path) ^ " : Not a directory"
351+ then match_err s complete_path " Invalid argument"
352+ else match_err s complete_path " Not a directory"
351353 | _ -> false )
352354 | Ok () ->
353355 Model. mem fs complete_path && path_is_a_dir fs complete_path && path_is_an_empty_dir fs complete_path)
@@ -356,11 +358,11 @@ struct
356358 | Error err ->
357359 (match err with
358360 | Sys_error s ->
359- (s = (p path) ^ " : Permission denied" ) ||
360- (s = (p path) ^ " : No such file or directory" && not (Model. mem fs path)) ||
361+ (match_err s path " Permission denied" ) ||
362+ (match_err s path " No such file or directory" && not (Model. mem fs path)) ||
361363 if Sys. win32 && not (path_is_a_dir fs path) (* if not a directory *)
362- then s = (p path) ^ " : Invalid argument"
363- else s = (p path) ^ " : Not a directory"
364+ then match_err s path " Invalid argument"
365+ else match_err s path " Not a directory"
364366 | _ -> false )
365367 | Ok array_of_subdir ->
366368 (* Temporary work around for mingW, see https://github.com/ocaml/ocaml/issues/11829 *)
@@ -375,8 +377,7 @@ struct
375377 = List. sort String. compare (Array. to_list array_of_subdir))))
376378 | Mkfile (path , new_file_name ), Res ((Result (Unit,Exn),_ ),res ) -> (
377379 let complete_path = path @ [ new_file_name ] in
378- let concatenated_path = p complete_path in
379- let match_msg err msg = err = concatenated_path ^ " : " ^ msg in
380+ let match_msg err msg = match_err err complete_path msg in
380381 let match_msgs err = List. exists (match_msg err) in
381382 let msgs_already_exists = [" File exists" ; " Permission denied" ]
382383 (* Permission denied: seen (sometimes?) on Windows *)
0 commit comments