use std::io;
pub enum LockScope {
Shared,
Local,
}
#[derive(serde::Serialize, utoipa::ToSchema)]
pub struct LockStatus {
pub shared: bool,
pub local: bool,
pub locked: bool,
}
pub fn is_globally_locked() -> bool {
crate::paths::global_lock_path().exists() || crate::paths::global_local_lock_path().exists()
}
pub fn lock_status() -> LockStatus {
let shared = crate::paths::global_lock_path().exists();
let local = crate::paths::global_local_lock_path().exists();
LockStatus {
shared,
local,
locked: shared || local,
}
}
pub fn set_lock(scope: LockScope, locked: bool) -> io::Result<()> {
let path = match scope {
LockScope::Shared => crate::paths::global_lock_path(),
LockScope::Local => crate::paths::global_local_lock_path(),
};
if locked {
std::fs::create_dir_all(crate::paths::config_dir())?;
std::fs::write(&path, b"")?;
} else if path.exists() {
std::fs::remove_file(&path)?;
}
Ok(())
}
#[cfg(test)]
#[path = "global_lock_tests.rs"]
mod tests;