From 58458b640623d782ce881848d8baafa18f028033 Mon Sep 17 00:00:00 2001 From: Leandro Ostera Date: Wed, 23 Oct 2024 00:56:31 +0200 Subject: [PATCH] feat: add permissions to file open calls --- packages/riot-stdlib/file.ml | 11 +++++++---- packages/riot-stdlib/process.ml | 1 - packages/riot/riot.mli | 4 ++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/riot-stdlib/file.ml b/packages/riot-stdlib/file.ml index 3177d13a..7ff15fb4 100644 --- a/packages/riot-stdlib/file.ml +++ b/packages/riot-stdlib/file.ml @@ -9,12 +9,15 @@ type rw_file = [ `w | `r ] file let fd t = t.fd let base_permissions = 0o640 -let do_open path flags = - let raw_fd = Unix.openfile path flags base_permissions in +let do_open ?(permissions = base_permissions) path flags = + let raw_fd = Unix.openfile path flags permissions in { fd = Fd.make raw_fd; path } -let open_read path = do_open path Unix.[ O_RDONLY ] -let open_write path = do_open path Unix.[ O_WRONLY; O_CREAT ] +let open_read ?permissions path = do_open ?permissions path Unix.[ O_RDONLY ] + +let open_write ?permissions path = + do_open ?permissions path Unix.[ O_WRONLY; O_CREAT ] + let close t = Fd.close t.fd let remove path = Unix.unlink path let seek t ~off = Fd.seek t.fd off Unix.SEEK_SET diff --git a/packages/riot-stdlib/process.ml b/packages/riot-stdlib/process.ml index f8d912d6..5c46e60e 100644 --- a/packages/riot-stdlib/process.ml +++ b/packages/riot-stdlib/process.ml @@ -49,5 +49,4 @@ let demonitor pid = demonitor pid let is_alive pid = is_process_alive pid - let register ~name pid = register name pid diff --git a/packages/riot/riot.mli b/packages/riot/riot.mli index a0d2fb3c..82b4ff53 100644 --- a/packages/riot/riot.mli +++ b/packages/riot/riot.mli @@ -645,8 +645,8 @@ module File : sig type rw_file = [ `r | `w ] file val fd : _ file -> Unix.file_descr - val open_read : string -> read_file - val open_write : string -> write_file + val open_read : ?permissions:int -> string -> read_file + val open_write : ?permissions:int -> string -> write_file val close : _ file -> unit val remove : string -> unit val seek : _ file -> off:int -> int