dirmgr: Add a helper to create LockFile errors.
This commit is contained in:
parent
c983987782
commit
3c424c82d7
|
@ -180,6 +180,12 @@ impl Error {
|
|||
Error::NetDocError { source, cause }
|
||||
}
|
||||
|
||||
/// Construct a new `Error` from `std::io::Error` for an error that occurred
|
||||
/// while locking a file.
|
||||
pub(crate) fn from_lockfile(err: std::io::Error) -> Error {
|
||||
Error::LockFile(Arc::new(err))
|
||||
}
|
||||
|
||||
/// Return true if this error is serious enough that we should mark this
|
||||
/// cache as having failed.
|
||||
pub(crate) fn indicates_cache_failure(&self) -> bool {
|
||||
|
|
|
@ -93,13 +93,8 @@ impl SqliteStore {
|
|||
}
|
||||
}
|
||||
|
||||
let mut lockfile =
|
||||
fslock::LockFile::open(&lockpath).map_err(|e| Error::LockFile(Arc::new(e)))?;
|
||||
if !readonly
|
||||
&& !lockfile
|
||||
.try_lock()
|
||||
.map_err(|e| Error::LockFile(Arc::new(e)))?
|
||||
{
|
||||
let mut lockfile = fslock::LockFile::open(&lockpath).map_err(Error::from_lockfile)?;
|
||||
if !readonly && !lockfile.try_lock().map_err(Error::from_lockfile)? {
|
||||
readonly = true; // we couldn't get the lock!
|
||||
};
|
||||
let flags = if readonly {
|
||||
|
@ -276,7 +271,7 @@ impl Store for SqliteStore {
|
|||
.lockfile
|
||||
.as_mut()
|
||||
.expect("No lockfile open; cannot upgrade to read-write storage");
|
||||
if !lf.try_lock().map_err(|e| Error::LockFile(Arc::new(e)))? {
|
||||
if !lf.try_lock().map_err(Error::from_lockfile)? {
|
||||
// Somebody else has the lock.
|
||||
return Ok(false);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue