use crate::fs_kind::{FilesystemKind, filesystem_kind};
use crate::test_support::fixture;
use std::path::PathBuf;
pub(crate) const ABSENT_ACKNOWLEDGED_VARIABLE: &str = "CLI_GIT_BTRFS_ABSENT_ACKNOWLEDGED";
pub(crate) fn btrfs_fixture(name: &str) -> Option<PathBuf> {
let root: PathBuf = fixture(name);
let kind: Result<FilesystemKind, _> = filesystem_kind(root.as_path());
if kind == Ok(FilesystemKind::Btrfs) {
return Some(root);
}
let acknowledged: bool = std::env::var_os(ABSENT_ACKNOWLEDGED_VARIABLE).is_some_and(|value| { return !value.is_empty(); });
assert!(
acknowledged,
"the control {name} needs a btrfs fixture root, but {} is on {kind:?}; set CLI_GIT_TEST_ROOT to a directory on \
btrfs, or set {ABSENT_ACKNOWLEDGED_VARIABLE}=1 to state that this run has none",
root.display()
);
eprintln!("BTRFS CONTROL NOT RUN: {name} (fixture root {} is on {kind:?}; the host task native:test:host covers it)", root.display());
return None;
}
pub(crate) fn removal_allowed(root: &std::path::Path) -> bool {
return crate::fs_mount_options::read_mount_facts(root)
.ok()
.flatten()
.is_some_and(|facts| { return facts.has_option("user_subvol_rm_allowed"); });
}