Merge pull request #1084 from matthiasbeyer/libimagstore/move-by-id-check-fs
libimagstore: move_by_id() should check FS
This commit is contained in:
commit
2cee0db1ec
6 changed files with 25 additions and 0 deletions
|
@ -133,6 +133,10 @@ impl FileAbstraction for FSFileAbstraction {
|
||||||
create_dir_all(path).chain_err(|| SEK::DirNotCreated)
|
create_dir_all(path).chain_err(|| SEK::DirNotCreated)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn exists(&self, path: &PathBuf) -> Result<bool, SE> {
|
||||||
|
Ok(path.exists())
|
||||||
|
}
|
||||||
|
|
||||||
fn new_instance(&self, p: PathBuf) -> Box<FileAbstractionInstance> {
|
fn new_instance(&self, p: PathBuf) -> Box<FileAbstractionInstance> {
|
||||||
Box::new(FSFileAbstractionInstance::Absent(p))
|
Box::new(FSFileAbstractionInstance::Absent(p))
|
||||||
}
|
}
|
||||||
|
|
|
@ -152,6 +152,13 @@ impl FileAbstraction for InMemoryFileAbstraction {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn exists(&self, pb: &PathBuf) -> Result<bool, SE> {
|
||||||
|
let mut mtx = self.backend().lock().expect("Locking Mutex failed");
|
||||||
|
let backend = mtx.get_mut();
|
||||||
|
|
||||||
|
Ok(backend.contains_key(pb))
|
||||||
|
}
|
||||||
|
|
||||||
fn new_instance(&self, p: PathBuf) -> Box<FileAbstractionInstance> {
|
fn new_instance(&self, p: PathBuf) -> Box<FileAbstractionInstance> {
|
||||||
Box::new(InMemoryFileAbstractionInstance::new(self.backend().clone(), p))
|
Box::new(InMemoryFileAbstractionInstance::new(self.backend().clone(), p))
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,8 @@ pub trait FileAbstraction : Debug {
|
||||||
fn rename(&self, from: &PathBuf, to: &PathBuf) -> Result<(), SE>;
|
fn rename(&self, from: &PathBuf, to: &PathBuf) -> Result<(), SE>;
|
||||||
fn create_dir_all(&self, _: &PathBuf) -> Result<(), SE>;
|
fn create_dir_all(&self, _: &PathBuf) -> Result<(), SE>;
|
||||||
|
|
||||||
|
fn exists(&self, &PathBuf) -> Result<bool, SE>;
|
||||||
|
|
||||||
fn new_instance(&self, p: PathBuf) -> Box<FileAbstractionInstance>;
|
fn new_instance(&self, p: PathBuf) -> Box<FileAbstractionInstance>;
|
||||||
|
|
||||||
fn drain(&self) -> Result<Drain, SE>;
|
fn drain(&self) -> Result<Drain, SE>;
|
||||||
|
|
|
@ -115,6 +115,10 @@ impl<W: Write, M: Mapper> FileAbstraction for StdIoFileAbstraction<W, M> {
|
||||||
self.0.new_instance(p)
|
self.0.new_instance(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn exists(&self, p: &PathBuf) -> Result<bool, SE> {
|
||||||
|
self.0.exists(p)
|
||||||
|
}
|
||||||
|
|
||||||
fn drain(&self) -> Result<Drain, SE> {
|
fn drain(&self) -> Result<Drain, SE> {
|
||||||
self.0.drain()
|
self.0.drain()
|
||||||
}
|
}
|
||||||
|
|
|
@ -136,6 +136,10 @@ impl<W: Write, M: Mapper> FileAbstraction for StdoutFileAbstraction<W, M> {
|
||||||
self.mem.new_instance(p)
|
self.mem.new_instance(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn exists(&self, p: &PathBuf) -> Result<bool, SE> {
|
||||||
|
self.mem.exists(p)
|
||||||
|
}
|
||||||
|
|
||||||
fn drain(&self) -> Result<Drain, SE> {
|
fn drain(&self) -> Result<Drain, SE> {
|
||||||
self.backend_cloned().map(Drain::new)
|
self.backend_cloned().map(Drain::new)
|
||||||
}
|
}
|
||||||
|
|
|
@ -755,6 +755,10 @@ impl Store {
|
||||||
let old_id_pb = try!(old_id.clone().with_base(self.path().clone()).into_pathbuf());
|
let old_id_pb = try!(old_id.clone().with_base(self.path().clone()).into_pathbuf());
|
||||||
let new_id_pb = try!(new_id.clone().with_base(self.path().clone()).into_pathbuf());
|
let new_id_pb = try!(new_id.clone().with_base(self.path().clone()).into_pathbuf());
|
||||||
|
|
||||||
|
if try!(self.backend.exists(&new_id_pb)) {
|
||||||
|
return Err(SE::from_kind(SEK::EntryAlreadyExists(new_id.clone())));
|
||||||
|
}
|
||||||
|
|
||||||
match self.backend.rename(&old_id_pb, &new_id_pb) {
|
match self.backend.rename(&old_id_pb, &new_id_pb) {
|
||||||
Err(e) => return Err(e).chain_err(|| SEK::EntryRenameError(old_id_pb, new_id_pb)),
|
Err(e) => return Err(e).chain_err(|| SEK::EntryRenameError(old_id_pb, new_id_pb)),
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
|
|
Loading…
Reference in a new issue