feat: bootstrap awg2 harness rust workspace and docs
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
use std::{fs, path::Path};
|
||||
|
||||
pub struct FileLock {
|
||||
path: String,
|
||||
}
|
||||
|
||||
impl FileLock {
|
||||
pub fn acquire(path: &str) -> anyhow::Result<Self> {
|
||||
let p = Path::new(path);
|
||||
if let Some(parent) = p.parent() {
|
||||
fs::create_dir_all(parent)?;
|
||||
}
|
||||
if p.exists() {
|
||||
anyhow::bail!("lock already exists: {path}");
|
||||
}
|
||||
fs::write(p, std::process::id().to_string())?;
|
||||
Ok(Self {
|
||||
path: path.to_string(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for FileLock {
|
||||
fn drop(&mut self) {
|
||||
let _ = fs::remove_file(&self.path);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user