Mercurial > lbo > hg > leveldb-rs
changeset 303:26f7cbdfe6c6
db_impl: Refactor acquire_lock() method.
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Wed, 27 Sep 2017 05:51:33 +0000 |
parents | a82f7228192c |
children | d903e81666e7 |
files | src/db_impl.rs |
diffstat | 1 files changed, 11 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/src/db_impl.rs Wed Sep 27 05:51:10 2017 +0000 +++ b/src/db_impl.rs Wed Sep 27 05:51:33 2017 +0000 @@ -117,17 +117,17 @@ /// acquire_lock acquires the lock file. fn acquire_lock(&mut self) -> Result<()> { let lock_r = self.opt.env.lock(Path::new(&lock_file_name(&self.name))); - if let Ok(lockfile) = lock_r { - self.lock = Some(lockfile); - return Ok(()); + match lock_r { + Ok(lockfile) => { + self.lock = Some(lockfile); + Ok(()) + } + Err(ref e) if e.code == StatusCode::LockError => { + err(StatusCode::LockError, + "database lock is held by another instance") + } + Err(e) => Err(e), } - - let e = lock_r.unwrap_err(); - if e.code == StatusCode::LockError { - return err(StatusCode::LockError, - "database lock is held by another instance"); - } - e } /// release_lock releases the lock file, if it's currently held. @@ -690,7 +690,7 @@ impl Drop for DB { fn drop(&mut self) { - self.release_lock(); + self.release_lock().is_ok(); } }