mirror of
https://github.com/scottlamb/moonfire-nvr.git
synced 2025-01-13 07:53:22 -05:00
better error msg when db dir open fails
The previous poor error message was reported by Marlon Hendred: https://groups.google.com/g/moonfire-nvr-users/c/X9k2cOCJUDQ/m/1y1ikrWoAAAJ
This commit is contained in:
parent
cc93768a9a
commit
d83bb1bf4d
@ -53,11 +53,17 @@ enum OpenMode {
|
|||||||
/// Locks the directory without opening the database.
|
/// Locks the directory without opening the database.
|
||||||
/// The returned `dir::Fd` holds the lock and should be kept open as long as the `Connection` is.
|
/// The returned `dir::Fd` holds the lock and should be kept open as long as the `Connection` is.
|
||||||
fn open_dir(db_dir: &Path, mode: OpenMode) -> Result<dir::Fd, Error> {
|
fn open_dir(db_dir: &Path, mode: OpenMode) -> Result<dir::Fd, Error> {
|
||||||
let dir = dir::Fd::open(db_dir, mode == OpenMode::Create)?;
|
let dir = dir::Fd::open(db_dir, mode == OpenMode::Create)
|
||||||
|
.map_err(|e| e.context(if e == nix::Error::Sys(nix::errno::Errno::ENOENT) {
|
||||||
|
format!("db dir {} not found; try running moonfire-nvr init",
|
||||||
|
db_dir.display())
|
||||||
|
} else {
|
||||||
|
format!("unable to open db dir {}: {}", db_dir.display(), &e)
|
||||||
|
}))?;
|
||||||
let ro = mode == OpenMode::ReadOnly;
|
let ro = mode == OpenMode::ReadOnly;
|
||||||
dir.lock(if ro { FlockArg::LockSharedNonblock } else { FlockArg::LockExclusiveNonblock })
|
dir.lock(if ro { FlockArg::LockSharedNonblock } else { FlockArg::LockExclusiveNonblock })
|
||||||
.map_err(|e| e.context(format!("db dir {:?} already in use; can't get {} lock",
|
.map_err(|e| e.context(format!("db dir {} already in use; can't get {} lock",
|
||||||
db_dir, if ro { "shared" } else { "exclusive" })))?;
|
db_dir.display(), if ro { "shared" } else { "exclusive" })))?;
|
||||||
Ok(dir)
|
Ok(dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user