mirror of
https://github.com/warp-tech/warpgate.git
synced 2024-09-20 06:46:17 +08:00
fixed #966 - don't try to change config permissions unless necessary
This commit is contained in:
parent
32078670a8
commit
81cefebe96
|
@ -1,10 +1,21 @@
|
|||
use std::os::unix::prelude::PermissionsExt;
|
||||
use std::path::Path;
|
||||
|
||||
fn maybe_apply_permissions<P: AsRef<Path>>(
|
||||
path: P,
|
||||
permissions: std::fs::Permissions,
|
||||
) -> std::io::Result<()> {
|
||||
let current = std::fs::metadata(&path)?.permissions();
|
||||
if current != permissions {
|
||||
std::fs::set_permissions(path, permissions)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn secure_directory<P: AsRef<Path>>(path: P) -> std::io::Result<()> {
|
||||
std::fs::set_permissions(path.as_ref(), std::fs::Permissions::from_mode(0o700))
|
||||
maybe_apply_permissions(path.as_ref(), std::fs::Permissions::from_mode(0o700))
|
||||
}
|
||||
|
||||
pub fn secure_file<P: AsRef<Path>>(path: P) -> std::io::Result<()> {
|
||||
std::fs::set_permissions(path.as_ref(), std::fs::Permissions::from_mode(0o600))
|
||||
maybe_apply_permissions(path.as_ref(), std::fs::Permissions::from_mode(0o600))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue