Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

unix

rust

The standard library provides a way to change file permissions, so I'm wondering if I'm missing something.

like image 703
tshepang Avatar asked Feb 21 '17 23:02

tshepang


1 Answers

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.

like image 76
dippi Avatar answered Sep 22 '22 13:09

dippi