mirror of
https://gitlab.com/gabmus/envision.git
synced 2025-04-20 11:35:48 +00:00
feat: function to set file readonly
This commit is contained in:
parent
ab1f4c1093
commit
9229d082ee
1 changed files with 14 additions and 1 deletions
|
@ -1,6 +1,6 @@
|
|||
use std::{
|
||||
env,
|
||||
fs::{create_dir_all, OpenOptions},
|
||||
fs::{self, create_dir_all, OpenOptions},
|
||||
io::BufWriter,
|
||||
path::Path,
|
||||
};
|
||||
|
@ -53,3 +53,16 @@ pub fn get_data_dir() -> String {
|
|||
),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_file_radonly(path_s: &String, readonly: bool) {
|
||||
let path = Path::new(&path_s);
|
||||
if !path.is_file() {
|
||||
println!("WARN: trying to set readonly on a file that does not exist");
|
||||
return;
|
||||
}
|
||||
let mut perms = fs::metadata(path)
|
||||
.expect_dialog("Could not get metadata for file")
|
||||
.permissions();
|
||||
perms.set_readonly(readonly);
|
||||
fs::set_permissions(path, perms).expect_dialog("Could not set permissions for file")
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue