Skip to content

Commit f004a5e

Browse files
committed
Use Eio_unix.Private.chmod in eio_linux
1 parent f7b0f73 commit f004a5e

File tree

2 files changed

+9
-25
lines changed

2 files changed

+9
-25
lines changed

lib_eio_linux/eio_stubs.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -115,20 +115,6 @@ CAMLprim value caml_eio_symlinkat(value v_old_path, value v_new_fd, value v_new_
115115
CAMLreturn(Val_unit);
116116
}
117117

118-
CAMLprim value caml_eio_fchmodat(value v_fd, value v_path, value v_mode, value v_flags) {
119-
CAMLparam1(v_path);
120-
char *path;
121-
int ret;
122-
caml_unix_check_path(v_path, "fchmodat");
123-
path = caml_stat_strdup(String_val(v_path));
124-
caml_enter_blocking_section();
125-
ret = fchmodat(Int_val(v_fd), path, Int_val(v_mode), Int_val(v_flags));
126-
caml_leave_blocking_section();
127-
caml_stat_free(path);
128-
if (ret == -1) uerror("fchmodat", v_path);
129-
CAMLreturn(Val_unit);
130-
}
131-
132118
CAMLprim value caml_eio_getrandom(value v_ba, value v_off, value v_len) {
133119
CAMLparam1(v_ba);
134120
ssize_t ret;

lib_eio_linux/low_level.ml

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,6 @@ external eio_renameat : Unix.file_descr -> string -> Unix.file_descr -> string -
360360

361361
external eio_symlinkat : string -> Unix.file_descr -> string -> unit = "caml_eio_symlinkat"
362362

363-
external eio_fchmodat : Unix.file_descr -> string -> int -> int -> unit = "caml_eio_fchmodat"
364-
365363
external eio_getrandom : Cstruct.buffer -> int -> int -> int = "caml_eio_getrandom"
366364

367365
external eio_getdents : Unix.file_descr -> string list = "caml_eio_getdents"
@@ -488,15 +486,6 @@ let symlink ~link_to dir path =
488486
eio_symlinkat link_to parent leaf
489487
with Unix.Unix_error (code, name, arg) -> raise @@ Err.wrap_fs code name arg
490488

491-
492-
let chmod ~follow ~mode dir path =
493-
let module X = Uring.Statx in
494-
with_parent_dir "chmodat" dir path @@ fun parent leaf ->
495-
let flags = if follow then 0 else (* at_symlink_nofollow *) 0x100 in
496-
try
497-
eio_fchmodat parent leaf mode flags
498-
with Unix.Unix_error (code, name, arg) -> raise @@ Err.wrap_fs code name arg
499-
500489
let shutdown socket command =
501490
try
502491
Fd.use_exn "shutdown" socket @@ fun fd ->
@@ -535,6 +524,15 @@ let read_link fd path =
535524
Eio_unix.run_in_systhread ~label:"read_link" (fun () -> Eio_unix.Private.read_link (Some parent) leaf)
536525
with Unix.Unix_error (code, name, arg) -> raise @@ Err.wrap_fs code name arg
537526

527+
let chmod ~follow ~mode dir path =
528+
let module X = Uring.Statx in
529+
let flags = if follow then X.Flags.empty_path else X.Flags.(empty_path + symlink_nofollow) in
530+
let flags = (flags :> int) in
531+
try
532+
with_parent_dir_fd dir path @@ fun parent leaf ->
533+
Eio_unix.run_in_systhread ~label:"chmod" (fun () -> Eio_unix.Private.chmod parent leaf ~mode ~flags)
534+
with Unix.Unix_error (code, name, arg) -> raise @@ Err.wrap_fs code name arg
535+
538536
(* https://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml *)
539537
let getaddrinfo ~service node =
540538
let to_eio_sockaddr_t {Unix.ai_family; ai_addr; ai_socktype; ai_protocol; _ } =

0 commit comments

Comments
 (0)