Closed
Description
Location
std::fs::symlink_metadata
or std::fs::set_permissions
Summary
fn main() -> std::io::Result<()> {
use std::os::unix::fs::PermissionsExt;
let path = std::path::PathBuf::from("bar"); // `bar` is a symlink
let meta = std::fs::symlink_metadata(&path)?;
let mut permissions = meta.permissions();
println!("current mode: {:o}", permissions.mode());
permissions.set_mode(0o707);
println!("new mode: {:o}", permissions.mode());
std::fs::set_permissions(&path, permissions)?; // applied permission to original file
let meta = std::fs::symlink_metadata(&path)?;
let mut permissions = meta.permissions();
println!("reloaded mode: {:o}", permissions.mode());
Ok(())
}
current mode: 120755
new mode: 707
reloaded mode: 120755
Since I could obtain metadata for either original file or symlink, I expected there must be a way to apply permissions to symlink. But symlink_metadata
revealed not to have a pair of set_permissions
.
By the design if it is intended or lack of API, it could be documented somewhere like symlink_metadata
or set_permissions
.
On the other hand, metadata is obtainable from either file or symlink. Then I expected set_permission
to be placed on metadata object if metadata includes symlink information.
e.g. metadata.set_permissions(path, permissions)
Metadata
Metadata
Assignees
Labels
Area: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Lints (warnings about flaws in source code) such as unused_mut.Relevant to the compiler team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.