Skip to content

Commit 9873fb6

Browse files
Stub chmod on windows
Co-Authored-By: Daniel Ntege <[email protected]>
1 parent f004a5e commit 9873fb6

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

lib_eio/unix/stubs.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ CAMLprim value eio_unix_readlinkat(value v_fd, value v_path, value v_cs) {
5555
}
5656

5757
CAMLprim value eio_unix_fchmodat(value v_fd, value v_path, value v_mode, value v_flags) {
58+
#ifdef _WIN32
59+
caml_unix_error(EOPNOTSUPP, "fchmodat not supported on Windows", v_path);
60+
#else
5861
CAMLparam1(v_path);
5962
char *path;
6063
int ret;
@@ -66,4 +69,5 @@ CAMLprim value eio_unix_fchmodat(value v_fd, value v_path, value v_mode, value v
6669
caml_stat_free_preserving_errno(path);
6770
if (ret == -1) uerror("fchmodat", v_path);
6871
CAMLreturn(Val_unit);
72+
#endif
6973
}

lib_eio_windows/fs.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ end = struct
185185
Switch.on_release sw (fun () -> close d);
186186
Eio.Resource.T (d, Handler.v)
187187

188+
let chmod t ~follow:_ ~perm path =
189+
with_parent_dir t path @@ fun dirfd path ->
190+
Low_level.chmod ~mode:perm dirfd path
191+
188192
let pp f t = Fmt.string f (String.escaped t.label)
189193

190194
let native _t _path =

lib_eio_windows/low_level.ml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ external eio_openat : Unix.file_descr option -> bool -> string -> Flags.Open.t -
211211
let openat ?dirfd ?(nofollow=false) ~sw path flags dis create =
212212
with_dirfd "openat" dirfd @@ fun dirfd ->
213213
Switch.check sw;
214-
in_worker_thread (fun () -> eio_openat dirfd nofollow path Flags.Open.(flags + cloexec (* + nonblock *)) dis create)
214+
in_worker_thread ~label:"openat" (fun () -> eio_openat dirfd nofollow path Flags.Open.(flags + cloexec (* + nonblock *)) dis create)
215215
|> Fd.of_unix ~sw ~blocking:false ~close_unix:true
216216

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

224224
let unlink ?dirfd ~dir path =
225225
with_dirfd "unlink" dirfd @@ fun dirfd ->
226-
in_worker_thread @@ fun () ->
226+
in_worker_thread ~label:"unlink" @@ fun () ->
227227
eio_unlinkat dirfd path dir
228228

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

231231
let rename ?old_dir old_path ?new_dir new_path =
232232
with_dirfd "rename-old" old_dir @@ fun old_dir ->
233233
with_dirfd "rename-new" new_dir @@ fun new_dir ->
234-
in_worker_thread @@ fun () ->
234+
in_worker_thread ~label:"rename" @@ fun () ->
235235
eio_renameat old_dir old_path new_dir new_path
236236

237237

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

240240
let symlink ~link_to new_dir new_path =
241241
with_dirfd "symlink-new" new_dir @@ fun new_dir ->
242-
in_worker_thread @@ fun () ->
242+
in_worker_thread ~label:"symlink" @@ fun () ->
243243
eio_symlinkat link_to new_dir new_path
244244

245+
let chmod ~mode new_dir new_path =
246+
with_dirfd "chmod" new_dir @@ fun new_dir ->
247+
match new_dir with
248+
| Some _ -> failwith "chmod not supported on Windows"
249+
| None ->
250+
in_worker_thread ~label:"chmod" @@ fun () ->
251+
Unix.chmod new_path mode
252+
245253
let lseek fd off cmd =
246254
Fd.use_exn "lseek" fd @@ fun fd ->
247255
let cmd =

lib_eio_windows/low_level.mli

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ val symlink : link_to:string -> fd option -> string -> unit
5252
(** [symlink ~link_to dir path] will create a new symlink at [dir / path]
5353
linking to [link_to]. *)
5454

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

5761
val readv : fd -> Cstruct.t array -> int

0 commit comments

Comments
 (0)