mirror of
https://github.com/samvallad33/vestige.git
synced 2026-06-08 20:25:16 +02:00
Fix data-dir permission preservation
This commit is contained in:
parent
14b061f124
commit
3df930ca7e
1 changed files with 20 additions and 2 deletions
|
|
@ -256,12 +256,13 @@ fn prepare_storage_path(data_dir: Option<PathBuf>) -> io::Result<Option<PathBuf>
|
|||
}
|
||||
|
||||
// Only create if it doesn't exist (avoids "File exists" error on existing directories)
|
||||
if !data_dir.exists() {
|
||||
let created = !data_dir.exists();
|
||||
if created {
|
||||
fs::create_dir_all(&data_dir)?;
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
{
|
||||
if created {
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
let _ = fs::set_permissions(&data_dir, fs::Permissions::from_mode(0o700));
|
||||
}
|
||||
|
|
@ -594,6 +595,23 @@ mod tests {
|
|||
assert_eq!(db_path, Some(data_dir.join(DATABASE_FILE)));
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn prepare_storage_path_preserves_existing_data_dir_permissions() {
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
|
||||
let temp = tempfile::tempdir().unwrap();
|
||||
let data_dir = temp.path().join("shared");
|
||||
fs::create_dir_all(&data_dir).unwrap();
|
||||
fs::set_permissions(&data_dir, fs::Permissions::from_mode(0o755)).unwrap();
|
||||
|
||||
let db_path = prepare_storage_path(Some(data_dir.clone())).unwrap();
|
||||
let mode = fs::metadata(&data_dir).unwrap().permissions().mode() & 0o777;
|
||||
|
||||
assert_eq!(db_path, Some(data_dir.join(DATABASE_FILE)));
|
||||
assert_eq!(mode, 0o755);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn expand_tilde_expands_current_users_home_only() {
|
||||
let home = BaseDirs::new().unwrap().home_dir().to_path_buf();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue