@@ -14,10 +14,12 @@ module Path = Eio.Path
1414let () = Eio.Exn.Backend.show := false
1515
1616open Eio.Std
17+ open Eio.Exn
1718
1819let ( / ) = Path.( / )
1920
2021let run ?clear:(paths = []) fn =
22+ Eio_main.run @@ fun env ->
2123 let cwd = Eio.Stdenv.cwd env in
2224 List.iter (fun p -> Eio.Path.rmtree ~missing_ok:true (cwd / p)) paths;
2325 fn env
@@ -76,12 +78,13 @@ let chdir path =
7678 traceln "chdir %S" path;
7779 Unix.chdir path
7880
79- let try_stat path =
81+ let try_stat ?(info_type=`Kind) path =
8082 let stat ~follow =
81- match Eio.Path.stat ~follow path with
82- | info -> Fmt.str "@[<h>%a@]" Eio.File.Stat.pp_kind info.kind
83- | exception Eio.Io (e, _) -> Fmt.str "@[<h>%a@]" Eio.Exn.pp_err e
84- in
83+ match Eio.Path.stat ~follow path, info_type with
84+ | info, `Perm -> Fmt.str "@[<h>%o@]" info.perm
85+ | info, `Kind -> Fmt.str "@[<h>%a@]" Eio.File.Stat.pp_kind info.kind
86+ | exception Eio.Io (e, _) -> Fmt.str "@[<h>%a@]" Eio.Exn.pp_err e
87+ in
8588 let a = stat ~follow:false in
8689 let b = stat ~follow:true in
8790 if a = b then
@@ -94,10 +97,10 @@ let try_symlink ~link_to path =
9497 | s -> traceln "symlink %a -> %S" Path.pp path link_to
9598 | exception ex -> traceln "@[<h>%a@]" Eio.Exn.pp ex
9699
97- let try_chmod ~perm path =
98- match Path.chmod ~perm path with
99- | () -> Eio. traceln "chmod %o -> %a" perm Path.pp path
100- | exception ex -> Eio. traceln "@[<h>%a@]" Eio.Exn.pp ex
100+ let try_chmod path ~follow ~perm =
101+ match Eio. Path.chmod ~follow path ~perm with
102+ | () -> traceln "chmod %a to % o -> ok" Path.pp path perm
103+ | exception ex -> traceln "@[<h>%a@]" Eio.Exn.pp ex
101104
102105```
103106
@@ -834,6 +837,7 @@ Unconfined:
834837 try_stat cwd;
835838 try_stat (cwd / "..");
836839 try_stat (cwd / "stat_subdir2/..");
840+
837841 Path.symlink ~link_to:".." (cwd / "parent-symlink");
838842 try_stat (cwd / "parent-symlink");
839843 try_stat (cwd / "missing1" / "missing2");
@@ -849,7 +853,6 @@ Unconfined:
849853- : unit = ()
850854```
851855
852-
853856# read_link
854857
855858``` ocaml
@@ -1019,21 +1022,34 @@ Exception: Failure "Simulated error".
10191022```
10201023
10211024``` ocaml
1022- run ~clear:["stat_subdir2"; "symlink"; "broken-symlink"; "parent-symlink "] @@ fun env ->
1025+ # run ~clear:["test-file "] @@ fun env ->
10231026 let cwd = Eio.Stdenv.cwd env in
10241027 Switch.run @@ fun sw ->
1025- Path.mkdir (cwd / "stat_subdir2");
1026- Path.symlink ~link_to:"stat_subdir2" (cwd / "symlink");
1027- Path.symlink ~link_to:"missing" (cwd / "broken-symlink");
1028- try_stat (cwd / "stat_subdir2");
1029- try_stat (cwd / "symlink");
1030- try_stat (cwd / "broken-symlink");
1031- try_chmod ~perm:0o777 (cwd / "stat_subdir2");
1032- try_stat cwd;
1033- try_stat (cwd / "..");
1034- try_stat (cwd / "stat_subdir2/..");
1035- Path.symlink ~link_to:".." (cwd / "parent-symlink");
1036- try_stat (cwd / "parent-symlink");
1037- try_stat (cwd / "missing1" / "missing2");
1038- ();
1028+
1029+ let file_path = cwd / "test-file" in
1030+ Path.save ~create:(`Exclusive 0o644) file_path "test data";
1031+ traceln "+create <cwd:test-file> with permissions 0o644 -> ok";
1032+
1033+ let initial_perm = (Path.stat ~follow:true file_path).perm in
1034+ traceln "+<cwd:test-file> initial permissions = %o" initial_perm;
1035+ assert (initial_perm = 0o644);
1036+
1037+ try_chmod ~follow:true ~perm:0o400 file_path;
1038+
1039+ try_stat ~info_type:`Perm file_path;
1040+
1041+ try_chmod ~follow:true ~perm:0o600 file_path;
1042+ try_stat ~info_type:`Perm file_path;
1043+
1044+ Eio.Path.unlink file_path;
1045+ traceln "+unlink <cwd:test-file> -> ok";
1046+ ()
1047+ ++create <cwd:test-file> with permissions 0o644 -> ok
1048+ ++<cwd:test-file> initial permissions = 644
1049+ +chmod <cwd:test-file> to 400 -> ok
1050+ +<cwd:test-file> -> 400
1051+ +chmod <cwd:test-file> to 600 -> ok
1052+ +<cwd:test-file> -> 600
1053+ ++unlink <cwd:test-file> -> ok
1054+ - : unit = ()
10391055```
0 commit comments