@@ -23,6 +23,11 @@ let try_mkdir path =
2323 | () -> traceln " mkdir %a -> ok" Path. pp path
2424 | exception ex -> raise ex
2525
26+ let try_mkdirs ?exists_ok path =
27+ match Path. mkdirs ?exists_ok path ~perm: 0o700 with
28+ | () -> traceln " mkdirs %a -> ok" Path. pp path
29+ | exception ex -> traceln " @[<h>%a@]" Eio.Exn. pp ex
30+
2631let try_rename p1 p2 =
2732 match Path. rename p1 p2 with
2833 | () -> traceln " rename %a to %a -> ok" Path. pp p1 Path. pp p2
@@ -75,7 +80,7 @@ let test_exclusive env () =
7580 Eio. traceln " fiest" ;
7681 Path. save ~create: (`Exclusive 0o666 ) path " first-write" ;
7782 Eio. traceln " next" ;
78- try
83+ try
7984 Path. save ~create: (`Exclusive 0o666 ) path " first-write" ;
8085 Eio. traceln " nope" ;
8186 failwith " Should have failed"
@@ -84,15 +89,15 @@ let test_exclusive env () =
8489let test_if_missing env () =
8590 let cwd = Eio.Stdenv. cwd env in
8691 let test_file = (cwd / " test-file" ) in
87- with_temp_file test_file @@ fun test_file ->
92+ with_temp_file test_file @@ fun test_file ->
8893 Path. save ~create: (`If_missing 0o666 ) test_file " 1st-write-original" ;
8994 Path. save ~create: (`If_missing 0o666 ) test_file " 2nd-write" ;
9095 Alcotest. (check string ) " same contents" " 2nd-write-original" (Path. load test_file)
9196
9297let test_trunc env () =
9398 let cwd = Eio.Stdenv. cwd env in
9499 let test_file = (cwd / " test-file" ) in
95- with_temp_file test_file @@ fun test_file ->
100+ with_temp_file test_file @@ fun test_file ->
96101 Path. save ~create: (`Or_truncate 0o666 ) test_file " 1st-write-original" ;
97102 Path. save ~create: (`Or_truncate 0o666 ) test_file " 2nd-write" ;
98103 Alcotest. (check string ) " same contents" " 2nd-write" (Path. load test_file)
@@ -125,20 +130,33 @@ let test_mkdir env () =
125130 Unix. rmdir " subdir\\ nested" ;
126131 Unix. rmdir " subdir"
127132
133+ let test_mkdirs env () =
134+ let cwd = Eio.Stdenv. cwd env in
135+ let nested = cwd / " subdir1" / " subdir2" / " subdir3" in
136+ try_mkdirs nested;
137+ let one_more = Path. (nested / " subdir4" ) in
138+ (try
139+ try_mkdirs one_more
140+ with Eio. Io (Eio.Fs. E (Already_exists _ ), _ ) -> () );
141+ try_mkdirs ~exists_ok: true one_more;
142+ try
143+ try_mkdirs (cwd / " .." / " outside" )
144+ with Eio. Io (Eio.Fs. E (Permission_denied _ ), _ ) -> ()
145+
128146let test_symlink env () =
129- (*
147+ (*
130148 Important note: assuming that neither "another" nor
131149 "to-subdir" exist, the following program will behave
132150 differently if you don't have the ~to_dir flag.
133151
134152 With [to_dir] set to [true] we get the desired UNIX behaviour,
135153 without it [Unix.realpath] will actually show the parent directory
136154 of "another". Presumably this is because Windows distinguishes
137- between file symlinks and directory symlinks. Fun.
155+ between file symlinks and directory symlinks. Fun.
138156
139157 {[ Unix.symlink ~to_dir:true "another" "to-subdir";
140158 Unix.mkdir "another" 0o700;
141- print_endline @@ Unix.realpath "to-subdir" |}
159+ print_endline @@ Unix.realpath "to-subdir" |}
142160 *)
143161 let cwd = Eio.Stdenv. cwd env in
144162 try_mkdir (cwd / " sandbox" );
@@ -186,13 +204,13 @@ let test_unlink env () =
186204 try_unlink (cwd / " file" );
187205 try_unlink (cwd / " subdir\\ file2" );
188206 let () =
189- try
207+ try
190208 try_read_file (cwd / " file" );
191209 failwith " file should not exist"
192210 with Eio. Io (Eio.Fs. E (Not_found _ ), _ ) -> ()
193211 in
194212 let () =
195- try
213+ try
196214 try_read_file (cwd / " subdir\\ file2" );
197215 failwith " file should not exist"
198216 with Eio. Io (Eio.Fs. E (Not_found _ ), _ ) -> ()
@@ -201,7 +219,7 @@ let test_unlink env () =
201219 (* Supposed to use symlinks here. *)
202220 try_unlink (cwd / " subdir\\ file2" );
203221 let () =
204- try
222+ try
205223 try_read_file (cwd / " subdir\\ file2" );
206224 failwith " file should not exist"
207225 with Eio. Io (Eio.Fs. E (Not_found _ ), _ ) -> ()
@@ -211,13 +229,13 @@ let test_unlink env () =
211229let try_failing_unlink env () =
212230 let cwd = Eio.Stdenv. cwd env in
213231 let () =
214- try
232+ try
215233 try_unlink (cwd / " missing" );
216234 failwith " Expected not found!"
217235 with Eio. Io (Eio.Fs. E (Not_found _ ), _ ) -> ()
218236 in
219237 let () =
220- try
238+ try
221239 try_unlink (cwd / " ..\\ foo" );
222240 failwith " Expected permission denied!"
223241 with Eio. Io (Eio.Fs. E (Permission_denied _ ), _ ) -> ()
@@ -233,13 +251,13 @@ let test_remove_dir env () =
233251 try_rmdir (cwd / " d1" );
234252 try_rmdir (cwd / " subdir\\ d2" );
235253 let () =
236- try
254+ try
237255 try_read_dir (cwd / " d1" );
238256 failwith " Expected not found"
239257 with Eio. Io (Eio.Fs. E (Not_found _ ), _ ) -> ()
240- in
258+ in
241259 let () =
242- try
260+ try
243261 try_read_dir (cwd / " subdir\\ d2" );
244262 failwith " Expected not found"
245263 with Eio. Io (Eio.Fs. E (Not_found _ ), _ ) -> ()
0 commit comments