summaryrefslogtreecommitdiffstats
path: root/lib/core/libimagstore/src/file_abstraction
diff options
context:
space:
mode:
Diffstat (limited to 'lib/core/libimagstore/src/file_abstraction')
-rw-r--r--lib/core/libimagstore/src/file_abstraction/fs.rs45
-rw-r--r--lib/core/libimagstore/src/file_abstraction/inmemory.rs10
-rw-r--r--lib/core/libimagstore/src/file_abstraction/iter.rs2
-rw-r--r--lib/core/libimagstore/src/file_abstraction/mod.rs2
4 files changed, 23 insertions, 36 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(())
}
diff --git a/lib/core/libimagstore/src/file_abstraction/inmemory.rs b/lib/core/libimagstore/src/file_abstraction/inmemory.rs
index 2deabcae..f6a0e289 100644
--- a/lib/core/libimagstore/src/file_abstraction/inmemory.rs
+++ b/lib/core/libimagstore/src/file_abstraction/inmemory.rs
@@ -24,11 +24,11 @@ use std::cell::RefCell;
use std::sync::Arc;
use std::ops::Deref;
-use libimagerror::errors::ErrorMsg as EM;
+use libimagerror::errors::Error as EM;
+
+use anyhow::Result;
+use anyhow::Error;
-use failure::Fallible as Result;
-use failure::Error;
-use failure::err_msg;
use super::FileAbstraction;
use super::FileAbstractionInstance;
@@ -140,7 +140,7 @@ impl FileAbstraction for InMemoryFileAbstraction {
let a = backend.remove(from).ok_or_else(|| EM::FileNotFound)?;
let new_entry = {
let new_location = if to.starts_with("/") {
- let s = to.to_str().map(String::from).ok_or_else(|| err_msg("Failed to convert path to str"))?;
+ let s = to.to_str().map(String::from).ok_or_else(|| anyhow!("Failed to convert path to str"))?;
PathBuf::from(s.replace("/", ""))
} else {
to.to_path_buf()
diff --git a/lib/core/libimagstore/src/file_abstraction/iter.rs b/lib/core/libimagstore/src/file_abstraction/iter.rs
index 14649ac9..e24177b1 100644
--- a/lib/core/libimagstore/src/file_abstraction/iter.rs
+++ b/lib/core/libimagstore/src/file_abstraction/iter.rs
@@ -21,7 +21,7 @@ use std::path::PathBuf;
use std::sync::Arc;
use std::fmt::Debug;
-use failure::Fallible as Result;
+use anyhow::Result;
use crate::storeid::StoreIdWithBase;
use crate::file_abstraction::FileAbstraction;
diff --git a/lib/core/libimagstore/src/file_abstraction/mod.rs b/lib/core/libimagstore/src/file_abstraction/mod.rs
index f277e0cf..a46151d6 100644
--- a/lib/core/libimagstore/src/file_abstraction/mod.rs
+++ b/lib/core/libimagstore/src/file_abstraction/mod.rs
@@ -22,7 +22,7 @@ use std::fmt::Debug;
use std::collections::HashMap;
use std::sync::Arc;
-use failure::Fallible as Result;
+use anyhow::Result;
use crate::store::Entry;
use crate::storeid::StoreIdWithBase;