pub(crate) const SKULD_DB_DIR_ENV: &str = "SKULD_DB_DIR";
pub(crate) struct FixtureDirs {
_exe_copy: Option<tempfile::TempDir>,
_db_dir: tempfile::TempDir,
}
impl FixtureDirs {
pub(super) fn new(exe_copy: Option<tempfile::TempDir>, db_dir: tempfile::TempDir) -> Self {
Self {
_exe_copy: exe_copy,
_db_dir: db_dir,
}
}
}
pub(super) fn fixture_db_dir() -> tempfile::TempDir {
let dir = tmp_dir();
#[cfg(not(target_os = "linux"))]
if unsafe { libc::geteuid() } == 0 {
let uid = crate::test_privilege::UNPRIVILEGED;
std::os::unix::fs::chown(dir.path(), Some(uid), Some(uid))
.expect("chown the fixture's skuld DB directory to its post-drop identity");
}
dir
}
#[cfg(target_os = "linux")]
pub(super) fn fixture_db_dir_searchable() -> tempfile::TempDir {
use std::os::unix::fs::PermissionsExt;
let dir = tmp_dir();
std::fs::set_permissions(dir.path(), std::fs::Permissions::from_mode(0o755))
.expect("make the fixture's skuld DB directory searchable");
dir
}
fn tmp_dir() -> tempfile::TempDir {
tempfile::Builder::new()
.prefix("cosca-skuld-db-")
.tempdir_in("/tmp")
.expect("tempdir directly under /tmp for the fixture's skuld DB")
}
#[cfg(test)]
#[path = "db_dir_tests.rs"]
mod db_dir_tests;