Skip to content

Commit d25bfbf

Browse files
Fix fchmodat on linux and add tests
Co-Authored-By: Daniel Ntege <[email protected]>
1 parent 359e465 commit d25bfbf

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

lib_eio_linux/dune

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@
1313
(names eio_stubs))
1414
(libraries eio eio.utils eio.unix uring fmt))
1515

16+
(rule
17+
(targets config.ml)
18+
(enabled_if ; See https://github.com/ocaml/dune/issues/4895
19+
(or (= %{system} "linux") ; Historically, just Linux-x86
20+
(= %{system} "linux_eabihf") ; Historically, Linux-arm32
21+
(= %{system} "linux_elf") ; Historically, Linux-x86_32
22+
(= %{system} "elf"))) ; Historically, Linux-ppc64
23+
(action (run ./include/discover.exe)))
24+
1625
(rule
1726
(enabled_if
1827
(and

lib_eio_linux/low_level.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ let read_link fd path =
526526

527527
let chmod ~follow ~mode dir path =
528528
let module X = Uring.Statx in
529-
let flags = if follow then X.Flags.empty_path else X.Flags.(empty_path + symlink_nofollow) in
529+
let flags = if follow then 0 else Config.at_symlink_nofollow in
530530
let flags = (flags :> int) in
531531
try
532532
with_parent_dir_fd dir path @@ fun parent leaf ->

tests/fs.md

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,11 @@ let chdir path =
7777
traceln "chdir %S" path;
7878
Unix.chdir path
7979
80-
let try_stat path =
80+
let try_stat ?(info_type=`Kind) path =
8181
let stat ~follow =
82-
match Eio.Path.stat ~follow path with
83-
| info -> Fmt.str "@[<h>%a@]" Eio.File.Stat.pp_kind info.kind
82+
match Eio.Path.stat ~follow path, info_type with
83+
| info, `Perm -> Fmt.str "@[<h>%o@]" info.perm
84+
| info, `Kind -> Fmt.str "@[<h>%a@]" Eio.File.Stat.pp_kind info.kind
8485
| exception Eio.Io (e, _) -> Fmt.str "@[<h>%a@]" Eio.Exn.pp_err e
8586
in
8687
let a = stat ~follow:false in
@@ -94,6 +95,11 @@ let try_symlink ~link_to path =
9495
match Path.symlink ~link_to path with
9596
| s -> traceln "symlink %a -> %S" Path.pp path link_to
9697
| exception ex -> traceln "@[<h>%a@]" Eio.Exn.pp ex
98+
99+
let try_chmod path ~follow ~perm =
100+
match Eio.Path.chmod ~follow path ~perm with
101+
| () -> traceln "chmod %a to %o -> ok" Path.pp path perm
102+
| exception ex -> traceln "@[<h>%a@]" Eio.Exn.pp ex
97103
```
98104

99105
# Basic test cases
@@ -865,6 +871,27 @@ Unconfined:
865871
- : unit = ()
866872
```
867873

874+
# chmod
875+
876+
Chmod works.
877+
878+
```ocaml
879+
# run ~clear:["test-file"] @@ fun env ->
880+
let cwd = Eio.Stdenv.cwd env in
881+
let file_path = cwd / "test-file" in
882+
Path.save ~create:(`Exclusive 0o644) file_path "test data";
883+
try_chmod ~follow:false ~perm:0o400 file_path;
884+
try_stat ~info_type:`Perm file_path;
885+
try_chmod ~follow:false ~perm:0o600 file_path;
886+
try_stat ~info_type:`Perm file_path
887+
+chmod <cwd:test-file> to 400 -> ok
888+
+<cwd:test-file> -> 400
889+
+chmod <cwd:test-file> to 600 -> ok
890+
+<cwd:test-file> -> 600
891+
- : unit = ()
892+
```
893+
894+
868895
# pread/pwrite
869896

870897
Check reading and writing vectors at arbitrary offsets:

0 commit comments

Comments
 (0)