summaryrefslogtreecommitdiffstats
path: root/lib/core/libimagstore/src/file_abstraction/fs.rs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/core/libimagstore/src/file_abstraction/fs.rs')
-rw-r--r--lib/core/libimagstore/src/file_abstraction/fs.rs45
1 files changed, 16 insertions, 29 deletions
diff --git a/lib/core/libimagstore/src/file_abstraction/fs.rs b/lib/core/libimagstore/src/file_abstraction/fs.rs
index 5388a5c4..58350fca 100644
--- a/lib/core/libimagstore/src/file_abstraction/fs.rs
+++ b/lib/core/libimagstore/src/file_abstraction/fs.rs
@@ -22,8 +22,6 @@ use std::io::{Seek, SeekFrom, Read};
use std::path::{Path, PathBuf};
use std::sync::Arc;
-use libimagerror::errors::ErrorMsg as EM;
-
use super::FileAbstraction;
use super::FileAbstractionInstance;
use super::Drain;
@@ -33,9 +31,9 @@ use crate::file_abstraction::iter::PathIterator;
use crate::file_abstraction::iter::PathIterBuilder;
use walkdir::WalkDir;
-use failure::ResultExt;
-use failure::Fallible as Result;
-use failure::Error;
+use anyhow::Context;
+use anyhow::Result;
+use anyhow::Error;
#[derive(Debug)]
pub struct FSFileAbstractionInstance(PathBuf);
@@ -54,12 +52,11 @@ impl FileAbstractionInstance for FSFileAbstractionInstance {
Ok(Some(file)) => file,
};
- file.seek(SeekFrom::Start(0)).context(EM::FileNotSeeked)?;
+ file.seek(SeekFrom::Start(0))?;
let mut s = String::new();
file.read_to_string(&mut s)
- .context(EM::IO)
.map_err(Error::from)
.map(|_| s)
.and_then(|s: String| Entry::from_str(id, &s))
@@ -73,13 +70,12 @@ impl FileAbstractionInstance for FSFileAbstractionInstance {
use std::io::Write;
let buf = buf.to_str()?.into_bytes();
- let mut file = create_file(&self.0).context(EM::FileNotCreated)?;
+ let mut file = create_file(&self.0)?;
- file.seek(SeekFrom::Start(0)).context(EM::FileNotCreated)?;
- file.set_len(buf.len() as u64).context(EM::FileNotWritten)?;
- file.write_all(&buf)
- .context(EM::FileNotWritten)
- .map_err(Error::from)
+ file.seek(SeekFrom::Start(0))?;
+ file.set_len(buf.len() as u64)?;
+ file.write_all(&buf)?;
+ Ok(())
}
}
@@ -92,23 +88,18 @@ pub struct FSFileAbstraction {}
impl FileAbstraction for FSFileAbstraction {
fn remove_file(&self, path: &PathBuf) -> Result<()> {
- remove_file(path)
- .context(EM::FileNotRemoved)
- .map_err(Error::from)
+ remove_file(path).map_err(Error::from)
}
fn copy(&self, from: &PathBuf, to: &PathBuf) -> Result<()> {
- copy(from, to)
- .map(|_| ())
- .context(EM::FileNotCopied)
- .map_err(Error::from)
+ copy(from, to).map(|_| ()).map_err(Error::from)
}
fn rename(&self, from: &PathBuf, to: &PathBuf) -> Result<()> {
if let Some(p) = to.parent() {
if !p.exists() {
debug!("Creating: {:?}", p);
- create_dir_all(&p).context(EM::DirNotCreated)?;
+ create_dir_all(&p)?;
}
} else {
debug!("Failed to find parent. This looks like it will fail now");
@@ -116,16 +107,12 @@ impl FileAbstraction for FSFileAbstraction {
}
debug!("Renaming {:?} to {:?}", from, to);
- rename(from, to)
- .context(EM::FileNotRenamed)
- .map_err(Error::from)
+ rename(from, to).map_err(Error::from)
}
fn create_dir_all(&self, path: &PathBuf) -> Result<()> {
debug!("Creating: {:?}", path);
- create_dir_all(path)
- .context(EM::DirNotCreated)
- .map_err(Error::from)
+ create_dir_all(path).map_err(Error::from)
}
fn exists(&self, path: &PathBuf) -> Result<bool> {
@@ -183,7 +170,7 @@ impl PathIterBuilder for WalkDirPathIterBuilder {
.map(|r| {
trace!("Working in PathIterator with {:?}", r);
r.map(|e| PathBuf::from(e.path()))
- .context(format_err!("Error in Walkdir"))
+ .context(anyhow!("Error in Walkdir"))
.map_err(Error::from)
}))
}
@@ -194,7 +181,7 @@ impl PathIterBuilder for WalkDirPathIterBuilder {
debug!(" -> path : {:?}", self.basepath);
if !self.basepath.exists() {
- Err(format_err!("Does not exist: {}", self.basepath.display()))
+ Err(anyhow!("Does not exist: {}", self.basepath.display()))
} else {
Ok(())
}