use std::sync::Mutex;
static CWD_LOCK: Mutex<()> = Mutex::new(());
pub(crate) fn cwd_lock() -> std::sync::MutexGuard<'static, ()> {
CWD_LOCK.lock().unwrap_or_else(|e| e.into_inner())
}
static NON_INTERACTIVE_LOCK: Mutex<()> = Mutex::new(());
pub(crate) struct NonInteractiveGuard {
_lock: std::sync::MutexGuard<'static, ()>,
prev: bool,
}
impl NonInteractiveGuard {
pub(crate) fn new(set_to: bool) -> Self {
let lock = NON_INTERACTIVE_LOCK
.lock()
.unwrap_or_else(|e| e.into_inner());
let prev = crate::utils::is_non_interactive();
crate::utils::set_non_interactive(set_to);
Self { _lock: lock, prev }
}
}
impl Drop for NonInteractiveGuard {
fn drop(&mut self) {
crate::utils::set_non_interactive(self.prev);
}
}