mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2025-01-02 14:31:50 +03:00
Merge pull request #1285 from gitbutlerapp/Set-user-only-permissions
Set files in data dir to user only (0o600)
This commit is contained in:
commit
002a52af57
@ -71,14 +71,24 @@ impl Storage {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::{fs, os::unix::prelude::PermissionsExt};
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_get_or_create() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let controller = Storage::from(&dir.path().to_path_buf());
|
||||
|
||||
let once = controller.get_or_create().unwrap();
|
||||
let twice = controller.get_or_create().unwrap();
|
||||
assert_eq!(once, twice);
|
||||
|
||||
// check permissions of the private key
|
||||
let permissions = fs::metadata(dir.path().join("keys/ed25519"))
|
||||
.unwrap()
|
||||
.permissions();
|
||||
let perms = format!("{:o}", permissions.mode());
|
||||
assert_eq!(perms, "100600");
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
use std::{
|
||||
fs,
|
||||
os::unix::prelude::PermissionsExt,
|
||||
path::{self, Path, PathBuf},
|
||||
sync::{Arc, RwLock},
|
||||
};
|
||||
@ -65,6 +66,13 @@ impl Storage {
|
||||
fs::create_dir_all(dir).map_err(Error::IO)?;
|
||||
}
|
||||
fs::write(file_path.clone(), content).map_err(Error::IO)?;
|
||||
|
||||
// Set the permissions to be user-only.
|
||||
let metadata = fs::metadata(file_path.clone())?;
|
||||
let mut permissions = metadata.permissions();
|
||||
permissions.set_mode(0o600); // User read/write
|
||||
fs::set_permissions(file_path.clone(), permissions)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user