Skip to content

Commit

Permalink
Stub chmod on windows
Browse files Browse the repository at this point in the history
Co-Authored-By: Daniel Ntege <[email protected]>
  • Loading branch information
patricoferris and webbunivAdmin committed Nov 29, 2024
1 parent f004a5e commit 9873fb6
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
4 changes: 4 additions & 0 deletions lib_eio/unix/stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ CAMLprim value eio_unix_readlinkat(value v_fd, value v_path, value v_cs) {
}

CAMLprim value eio_unix_fchmodat(value v_fd, value v_path, value v_mode, value v_flags) {
#ifdef _WIN32
caml_unix_error(EOPNOTSUPP, "fchmodat not supported on Windows", v_path);
#else
CAMLparam1(v_path);
char *path;
int ret;
Expand All @@ -66,4 +69,5 @@ CAMLprim value eio_unix_fchmodat(value v_fd, value v_path, value v_mode, value v
caml_stat_free_preserving_errno(path);
if (ret == -1) uerror("fchmodat", v_path);
CAMLreturn(Val_unit);
#endif
}
4 changes: 4 additions & 0 deletions lib_eio_windows/fs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ end = struct
Switch.on_release sw (fun () -> close d);
Eio.Resource.T (d, Handler.v)

let chmod t ~follow:_ ~perm path =
with_parent_dir t path @@ fun dirfd path ->
Low_level.chmod ~mode:perm dirfd path

let pp f t = Fmt.string f (String.escaped t.label)

let native _t _path =
Expand Down
16 changes: 12 additions & 4 deletions lib_eio_windows/low_level.ml
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ external eio_openat : Unix.file_descr option -> bool -> string -> Flags.Open.t -
let openat ?dirfd ?(nofollow=false) ~sw path flags dis create =
with_dirfd "openat" dirfd @@ fun dirfd ->
Switch.check sw;
in_worker_thread (fun () -> eio_openat dirfd nofollow path Flags.Open.(flags + cloexec (* + nonblock *)) dis create)
in_worker_thread ~label:"openat" (fun () -> eio_openat dirfd nofollow path Flags.Open.(flags + cloexec (* + nonblock *)) dis create)
|> Fd.of_unix ~sw ~blocking:false ~close_unix:true

let mkdir ?dirfd ?(nofollow=false) ~mode:_ path =
Expand All @@ -223,25 +223,33 @@ external eio_unlinkat : Unix.file_descr option -> string -> bool -> unit = "caml

let unlink ?dirfd ~dir path =
with_dirfd "unlink" dirfd @@ fun dirfd ->
in_worker_thread @@ fun () ->
in_worker_thread ~label:"unlink" @@ fun () ->
eio_unlinkat dirfd path dir

external eio_renameat : Unix.file_descr option -> string -> Unix.file_descr option -> string -> unit = "caml_eio_windows_renameat"

let rename ?old_dir old_path ?new_dir new_path =
with_dirfd "rename-old" old_dir @@ fun old_dir ->
with_dirfd "rename-new" new_dir @@ fun new_dir ->
in_worker_thread @@ fun () ->
in_worker_thread ~label:"rename" @@ fun () ->
eio_renameat old_dir old_path new_dir new_path


external eio_symlinkat : string -> Unix.file_descr option -> string -> unit = "caml_eio_windows_symlinkat"

let symlink ~link_to new_dir new_path =
with_dirfd "symlink-new" new_dir @@ fun new_dir ->
in_worker_thread @@ fun () ->
in_worker_thread ~label:"symlink" @@ fun () ->
eio_symlinkat link_to new_dir new_path

let chmod ~mode new_dir new_path =
with_dirfd "chmod" new_dir @@ fun new_dir ->
match new_dir with
| Some _ -> failwith "chmod not supported on Windows"
| None ->
in_worker_thread ~label:"chmod" @@ fun () ->
Unix.chmod new_path mode

let lseek fd off cmd =
Fd.use_exn "lseek" fd @@ fun fd ->
let cmd =
Expand Down
4 changes: 4 additions & 0 deletions lib_eio_windows/low_level.mli
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ val symlink : link_to:string -> fd option -> string -> unit
(** [symlink ~link_to dir path] will create a new symlink at [dir / path]
linking to [link_to]. *)

val chmod : mode:int -> fd option -> string -> unit
(** [chmod ~mode path] is just a non-blocking call to {! Unix.chmod} when
[fd = None], otherwise it is unsupported. *)

val readdir : string -> string array

val readv : fd -> Cstruct.t array -> int
Expand Down

0 comments on commit 9873fb6

Please sign in to comment.