Is there a way to change file metadata (e.g. owner) on Unix platforms with Rust? Is there a way to change file metadata (e.g. owner) on Unix platforms with Rust? unix unix

Is there a way to change file metadata (e.g. owner) on Unix platforms with Rust?


Some OS specific funtionality can be found in the std::os module: for example std::os::unix::fs::MetadataExt allows to read uid/ guid or std::os::unix::fs::PermissionsExt handles file modes. However AFAIK there is no std support for changing owner / group.

As PeterHall commented, there is a chmod (and chown) function in the libc crate.

For further examples and inspiration, I suggest you to have a look to the coreutils project that implements many common GNU CLI utils, among which you can find the metadata manipulation ones.