use std::path::Path;
pub use crate::file_lock::FileLock as ConfigLock;
pub fn create_config_file(parent: &Path) -> std::io::Result<tempfile::NamedTempFile> {
crate::atomic_file::create_staging_file(parent, "shep", ".toml.tmp")
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn a_staged_config_file_is_owner_only_named_for_the_pair_and_lands_where_asked() {
let dir = tempfile::tempdir().unwrap();
let tmp = create_config_file(dir.path()).unwrap();
assert_eq!(tmp.path().parent(), Some(dir.path()));
let name = tmp.path().file_name().unwrap().to_str().unwrap();
assert!(name.starts_with("shep"), "{name}");
assert!(name.ends_with(".toml.tmp"), "{name}");
#[cfg(unix)]
{
use std::os::unix::fs::PermissionsExt;
let mode = tmp.as_file().metadata().unwrap().permissions().mode() & 0o777;
assert_eq!(mode, 0o600);
}
}
}