use crate::cache_paths;
use crate::config::CargoPortConfig;
pub(crate) fn record_paused(config: &CargoPortConfig) {
let marker = cache_paths::lint_pause_marker_for(config);
if let Some(parent) = marker.as_path().parent() {
let _ = std::fs::create_dir_all(parent);
}
let _ = std::fs::write(marker.as_path(), []);
}
pub(crate) fn record_resumed(config: &CargoPortConfig) {
let _ = std::fs::remove_file(cache_paths::lint_pause_marker_for(config).as_path());
}
pub(crate) fn is_set(config: &CargoPortConfig) -> bool {
cache_paths::lint_pause_marker_for(config)
.as_path()
.is_file()
}
#[cfg(test)]
#[allow(
clippy::expect_used,
reason = "tests should panic on unexpected values"
)]
mod tests {
use std::path::Path;
use super::*;
fn config_with_cache_root(root: &Path) -> CargoPortConfig {
let mut config = CargoPortConfig::default();
config.cache.root = root.to_string_lossy().to_string();
config
}
#[test]
fn marker_round_trips_through_record_and_clear() {
let cache_dir = tempfile::tempdir().expect("tempdir");
let config = config_with_cache_root(cache_dir.path());
assert!(!is_set(&config), "no marker before recording pause");
record_paused(&config);
assert!(is_set(&config), "marker present after recording pause");
record_resumed(&config);
assert!(!is_set(&config), "marker gone after recording resume");
}
#[test]
fn record_resumed_is_a_noop_when_marker_absent() {
let cache_dir = tempfile::tempdir().expect("tempdir");
let config = config_with_cache_root(cache_dir.path());
record_resumed(&config);
assert!(!is_set(&config));
}
}