Don't try to lock an already-locked lockfile.

Also, remove a dbg
This commit is contained in:
Nick Mathewson 2021-08-06 17:19:50 -04:00
parent af750e2010
commit d01d9643f0
1 changed files with 5 additions and 2 deletions

View File

@ -168,7 +168,11 @@ impl StateMgr for FsStateMgr {
}
fn try_lock(&self) -> Result<bool> {
let mut lockfile = self.inner.lockfile.lock().unwrap();
Ok(lockfile.try_lock()?)
if lockfile.owns_lock() {
Ok(true)
} else {
Ok(lockfile.try_lock()?)
}
}
fn load<D>(&self, key: &str) -> Result<Option<D>>
where
@ -204,7 +208,6 @@ impl StateMgr for FsStateMgr {
let fname_tmp = fname.with_extension("tmp");
std::fs::write(&fname_tmp, (&output).as_bytes())?;
dbg!(&fname_tmp, &fname);
std::fs::rename(fname_tmp, fname)?;
Ok(())