Skip to content

Support chown in eio_posix and eio_linux#781

Open
patricoferris wants to merge 1 commit into
ocaml-multicore:mainfrom
patricoferris:fchownat
Open

Support chown in eio_posix and eio_linux#781
patricoferris wants to merge 1 commit into
ocaml-multicore:mainfrom
patricoferris:fchownat

Conversation

@patricoferris

Copy link
Copy Markdown
Collaborator

This PR adds support to Eio for changing the ownership of a path using fchownat.

@talex5 talex5 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Rebasing on main should fix the OpenBSD CI error.

Comment thread lib_eio/path.ml Outdated
Comment thread lib_eio/unix/eio_unix.mli
Comment thread lib_eio/unix/stubs.c Outdated
Comment thread lib_eio_linux/low_level.ml Outdated
let chown ?dirfd ~follow:_ ~uid ~gid path =
in_worker_thread @@ fun () ->
match dirfd with
| None -> failwith "Chown is unsupported on Windows"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could just use Unix.chown here.

@patricoferris patricoferris Nov 22, 2024

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I'm wondering whether chown should be in the cross-platform API at all.

Unix.chown isn't implemented on Windows:
https://github.com/ocaml/ocaml/blob/c484c6932fa2eae03ba0f5a7dbdb26e3eee65eb0/otherlibs/unix/unix_win32.ml#L450 -- it's not implemented in python's os.chown either?

Do we have a rule for what makes it into the cross-platform API and what doesn't ? I mean we already have File.Unix_perm.t.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's OK to keep it. We might want a proper operation-not-supported error at some point.

@talex5

talex5 commented Nov 22, 2024

Copy link
Copy Markdown
Collaborator

BTW, I was planning to make a new Eio release tomorrow. Do you want me to delay that to get this in, or should I go ahead and merge this later?

@patricoferris

Copy link
Copy Markdown
Collaborator Author

Oops sorry -- cut the release, no rush on this :))

@talex5 talex5 mentioned this pull request Nov 23, 2024
14 tasks

@talex5 talex5 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I squashed and rebased this. Just wondering if the uid and gid should be optional.

Comment thread lib_eio/path.mli
Comment on lines +224 to +225
val chown : follow:bool -> uid:int64 -> gid:int64 -> _ t -> unit
(** [chown ~follow ~uid ~gid t] changes the ownership of [t] to be [uid, gid]. *)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to document follow. Also, fchown says "If the owner or group is specified as -1, then that ID is not changed". So maybe:

Suggested change
val chown : follow:bool -> uid:int64 -> gid:int64 -> _ t -> unit
(** [chown ~follow ~uid ~gid t] changes the ownership of [t] to be [uid, gid]. *)
val chown : follow:bool -> ?uid:int64 -> ?gid:int64 -> _ t -> unit
(** [chown ~follow ~uid ~gid t] changes the ownership of [t] to be [uid, gid].
[uid] or [gid] can be [None] to leave the current value unchanged.
@param follow If [t] is a symbolic link, change the permission of its target. *)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having a means to update only one of them seems sensible to me, thanks for taking a look!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants