Merge branch 'perm' into 'main'

set permission to 700 for directories

See merge request paris8-rust/rnote!7
This commit is contained in:
Volodymyr Patuta 2020-12-03 09:32:33 +01:00
commit fce453c53a
2 changed files with 17 additions and 4 deletions

View File

@ -5,7 +5,7 @@ A minimal note taking cli tool.
## Description
**rnote** creates `Markdown` text files (with persission set to 600) in a date-named or category-named directories with a name of a header of the note.
**rnote** creates `Markdown` text files (with permissions set to 600) in a date-named or category-named directories (with permissions set to 700) with a name of a header of the note.
Example:

View File

@ -23,12 +23,25 @@ fn get_path(category: &str) -> Result<String> {
/// Create directory for a note.
pub fn create_dir(category: &str) -> Result<()> {
let path = get_base_path()?;
let base = get_base_path()?;
let date = Utc::now().format("%Y-%m-%d");
match category.is_empty() {
true => fs::create_dir_all(format!("{}{}", path, date))?,
false => fs::create_dir_all(format!("{}{}", path, category))?,
true => {
fs::create_dir_all(format!("{}{}", base, date))?;
fs::set_permissions(
format!("{}{}", base, date),
fs::Permissions::from_mode(0o700),
)?;
}
false => {
fs::create_dir_all(format!("{}{}", base, category))?;
fs::set_permissions(
format!("{}{}", base, category),
fs::Permissions::from_mode(0o700),
)?;
}
}
fs::set_permissions(base, fs::Permissions::from_mode(0o700))?;
Ok(())
}