Skip to content

Commit

Permalink
feat: add permissions to file open calls
Browse files Browse the repository at this point in the history
  • Loading branch information
leostera committed Oct 22, 2024
1 parent a3aaa78 commit 58458b6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
11 changes: 7 additions & 4 deletions packages/riot-stdlib/file.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion packages/riot-stdlib/process.ml
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,4 @@ let demonitor pid =
demonitor pid

let is_alive pid = is_process_alive pid

let register ~name pid = register name pid
4 changes: 2 additions & 2 deletions packages/riot/riot.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 58458b6

Please sign in to comment.