Add file abstraction function to check whether path exists
This commit is contained in:
parent
d97b77c30c
commit
29e1107d3e
5 changed files with 21 additions and 0 deletions
|
@ -133,6 +133,10 @@ impl FileAbstraction for FSFileAbstraction {
|
|||
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> {
|
||||
Box::new(FSFileAbstractionInstance::Absent(p))
|
||||
}
|
||||
|
|
|
@ -152,6 +152,13 @@ impl FileAbstraction for InMemoryFileAbstraction {
|
|||
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> {
|
||||
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 create_dir_all(&self, _: &PathBuf) -> Result<(), SE>;
|
||||
|
||||
fn exists(&self, &PathBuf) -> Result<bool, SE>;
|
||||
|
||||
fn new_instance(&self, p: PathBuf) -> Box<FileAbstractionInstance>;
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
fn exists(&self, p: &PathBuf) -> Result<bool, SE> {
|
||||
self.0.exists(p)
|
||||
}
|
||||
|
||||
fn drain(&self) -> Result<Drain, SE> {
|
||||
self.0.drain()
|
||||
}
|
||||
|
|
|
@ -136,6 +136,10 @@ impl<W: Write, M: Mapper> FileAbstraction for StdoutFileAbstraction<W, M> {
|
|||
self.mem.new_instance(p)
|
||||
}
|
||||
|
||||
fn exists(&self, p: &PathBuf) -> Result<bool, SE> {
|
||||
self.mem.exists(p)
|
||||
}
|
||||
|
||||
fn drain(&self) -> Result<Drain, SE> {
|
||||
self.backend_cloned().map(Drain::new)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue