If my understanding is correct, the following code should produce an executable file. However it doesn't; it gets created, but the permissions specified aren't applied. What am I doing wrong?
use std::fs;
use std::os::unix::PermissionsExt;
fn main() {
fs::File::create("somefile").unwrap()
.metadata().unwrap()
.permissions()
.set_mode(0o770);
}
Use OpenOptions
:
use std::fs;
use std::os::unix::OpenOptionsExt;
fn main() {
fs::OpenOptions::new()
.create(true)
.write(true)
.mode(0o770)
.open("somefile")
.unwrap();
}
You can also use set_permissions for existing path
use std::fs;
use std::os::unix::fs::PermissionsExt;
fn main(){
fs::set_permissions("/path", fs::Permissions::from_mode(0o655)).unwrap();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With