git_workflow/pool/
lock.rs1use std::fs::{self, File};
4use std::path::{Path, PathBuf};
5
6use fs2::FileExt;
7
8use crate::error::{GwError, Result};
9
10pub struct PoolLock {
12 _file: File,
13 _path: PathBuf,
14}
15
16impl PoolLock {
17 pub fn acquire(pool_dir: &Path) -> Result<Self> {
20 fs::create_dir_all(pool_dir)?;
21 let lock_path = pool_dir.join("pool.lock");
22 let file = File::create(&lock_path)?;
23 file.try_lock_exclusive()
24 .map_err(|_| GwError::PoolLockTimeout)?;
25 Ok(Self {
26 _file: file,
27 _path: lock_path,
28 })
29 }
30}
31
32