Skip to content
This repository has been archived by the owner on Jan 31, 2024. It is now read-only.

Commit

Permalink
config permissions finalize
Browse files Browse the repository at this point in the history
  • Loading branch information
ozgunozerk committed Oct 3, 2022
1 parent fe8849b commit 98125af
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src-tauri/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,22 @@ pub(crate) fn custom_log_dir(id: &str) -> PathBuf {
path.expect("log path generation should succeed")
}

// TODO: current implementation works only on unix like systems
#[tauri::command]
pub(crate) fn create_file(path: &str, content: String) {
let mut file = File::create(path).expect("can't create file");
file.write_all(content.as_bytes())
.expect("couldn't write file");
let metadata = file.metadata().expect("can't get metadata");
let mut permissions = metadata.permissions();

permissions.set_mode(0o644); // Read/write for owner and read for others.
assert_eq!(permissions.mode(), 0o644);
// config file is created under the current user's folder, in Windows, other users do not have read/write access to these
#[cfg(not(target_os = "windows"))]
{
let mut perms = file
.metadata()
.expect("could not get metadata")
.permissions();
perms.set_mode(0o600);

file.set_permissions(perms)
.expect("failed to set permissions for the config");
}
}

0 comments on commit 98125af

Please sign in to comment.