Add file-system file locking functionality in the store
This commit is contained in:
parent
e88c5011ab
commit
a70d7d347a
2 changed files with 26 additions and 1 deletions
|
@ -66,3 +66,8 @@ verify = []
|
||||||
#
|
#
|
||||||
early-panic=[]
|
early-panic=[]
|
||||||
|
|
||||||
|
# File system locking
|
||||||
|
#
|
||||||
|
# Enable this feature to enable file-system locking in the store.
|
||||||
|
fs-locking = []
|
||||||
|
|
||||||
|
|
|
@ -130,11 +130,18 @@ impl Iterator for Walk {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl StoreEntry {
|
impl StoreEntry {
|
||||||
|
|
||||||
fn new(id: StoreId) -> Result<StoreEntry> {
|
fn new(id: StoreId) -> Result<StoreEntry> {
|
||||||
let pb = try!(id.clone().into_pathbuf());
|
let pb = try!(id.clone().into_pathbuf());
|
||||||
|
|
||||||
|
#[cfg(feature = "fs-lock")]
|
||||||
|
{
|
||||||
|
try!(open_file(pb.clone())
|
||||||
|
.and_then(|f| f.lock_exclusive().map_err_into(SEK::FileError))
|
||||||
|
.map_err_into(SEK::IoError));
|
||||||
|
}
|
||||||
|
|
||||||
Ok(StoreEntry {
|
Ok(StoreEntry {
|
||||||
id: id,
|
id: id,
|
||||||
file: FileAbstraction::Absent(pb),
|
file: FileAbstraction::Absent(pb),
|
||||||
|
@ -176,6 +183,19 @@ impl StoreEntry {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "fs-lock")]
|
||||||
|
impl Drop for StoreEntry {
|
||||||
|
|
||||||
|
fn drop(self) {
|
||||||
|
self.get_entry()
|
||||||
|
.and_then(|entry| open_file(entry.get_location().clone()).map_err_into(SEK::IoError))
|
||||||
|
.and_then(|f| f.unlock().map_err_into(SEK::FileError))
|
||||||
|
.map_err_into(SEK::IoError)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// The Store itself, through this object one can interact with IMAG's entries
|
/// The Store itself, through this object one can interact with IMAG's entries
|
||||||
pub struct Store {
|
pub struct Store {
|
||||||
location: PathBuf,
|
location: PathBuf,
|
||||||
|
|
Loading…
Reference in a new issue