[No-auto] lib/core/store: Fix Clippy warnings

Signed-off-by: flip1995 <hello@philkrones.com>
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
flip1995 2019-08-27 10:18:43 +02:00 committed by Matthias Beyer
parent 7b5f216e01
commit b2997517bb
6 changed files with 42 additions and 49 deletions

View file

@ -108,7 +108,7 @@ impl FileAbstraction for FSFileAbstraction {
if let Some(p) = to.parent() {
if !p.exists() {
debug!("Creating: {:?}", p);
let _ = create_dir_all(&p).context(EM::DirNotCreated)?;
create_dir_all(&p).context(EM::DirNotCreated)?;
}
} else {
debug!("Failed to find parent. This looks like it will fail now");
@ -204,8 +204,8 @@ impl PathIterBuilder for WalkDirPathIterBuilder {
fn open_file<A: AsRef<Path>>(p: A) -> ::std::io::Result<Option<File>> {
match OpenOptions::new().write(true).read(true).open(p) {
Err(e) => match e.kind() {
::std::io::ErrorKind::NotFound => return Ok(None),
_ => return Err(e),
::std::io::ErrorKind::NotFound => Ok(None),
_ => Err(e),
},
Ok(file) => Ok(Some(file))
}
@ -216,7 +216,7 @@ fn create_file<A: AsRef<Path>>(p: A) -> ::std::io::Result<File> {
trace!("'{}' is directory = {}", parent.display(), parent.is_dir());
if !parent.is_dir() {
trace!("Implicitely creating directory: {:?}", parent);
let _ = create_dir_all(parent)?;
create_dir_all(parent)?;
}
}
OpenOptions::new().write(true).read(true).create(true).open(p)

View file

@ -79,14 +79,11 @@ impl FileAbstractionInstance for InMemoryFileAbstractionInstance {
}
fn write_file_content(&mut self, buf: &Entry) -> Result<()> {
match *self {
InMemoryFileAbstractionInstance { ref absent_path, .. } => {
let mut mtx = self.fs_abstraction.lock().expect("Locking Mutex failed");
let backend = mtx.get_mut();
let _ = backend.insert(absent_path.clone(), buf.clone());
return Ok(());
},
};
let absent_path = &self.absent_path;
let mut mtx = self.fs_abstraction.lock().expect("Locking Mutex failed");
let backend = mtx.get_mut();
let _ = backend.insert(absent_path.clone(), buf.clone());
Ok(())
}
}
@ -101,12 +98,11 @@ impl InMemoryFileAbstraction {
&self.virtual_filesystem
}
fn backend_cloned<'a>(&'a self) -> Result<HashMap<PathBuf, Entry>> {
fn backend_cloned(&self) -> Result<HashMap<PathBuf, Entry>> {
self.virtual_filesystem
.lock()
.map_err(|_| Error::from(EM::LockError))
.map(|mtx| mtx.deref().borrow().clone())
.into()
}
}
@ -172,7 +168,7 @@ impl FileAbstraction for InMemoryFileAbstraction {
self.backend_cloned().map(Drain::new)
}
fn fill<'a>(&'a mut self, mut d: Drain) -> Result<()> {
fn fill(&mut self, mut d: Drain) -> Result<()> {
debug!("Draining into : {:?}", self);
let mut mtx = self.backend()
.lock()

View file

@ -46,7 +46,7 @@ pub(crate) trait FileAbstraction : Debug {
fn new_instance(&self, p: PathBuf) -> Box<dyn FileAbstractionInstance>;
fn drain(&self) -> Result<Drain>;
fn fill<'a>(&'a mut self, d: Drain) -> Result<()>;
fn fill(&mut self, d: Drain) -> Result<()>;
fn pathes_recursively<'a>(&self, basepath: PathBuf, storepath: &'a PathBuf, backend: Arc<dyn FileAbstraction>) -> Result<PathIterator<'a>>;
}
@ -74,7 +74,7 @@ impl Drain {
Drain::new(HashMap::new())
}
pub fn iter<'a>(&'a mut self) -> DrainIter<'a> {
pub fn iter(&mut self) -> DrainIter<'_> {
DrainIter(self.0.drain())
}

View file

@ -148,7 +148,6 @@ pub struct Store {
}
impl Store {
/// Create a new Store object
///
/// This opens a Store in `location`. The store_config is used to check whether creating the
@ -210,7 +209,7 @@ impl Store {
let store = Store {
location: location.clone(),
entries: Arc::new(RwLock::new(HashMap::new())),
backend: backend,
backend,
};
debug!("Store building succeeded");
@ -491,7 +490,7 @@ impl Store {
}
debug!("Seems like {:?} is on the FS", pb);
let _ = self
self
.backend
.remove_file(&pb)
.context(EM::FileError)
@ -608,7 +607,7 @@ impl Store {
}
debug!("New entry does not yet exist on filesystem. Good.");
let _ = self
self
.backend
.rename(&old_id_pb, &new_id_pb)
.context({
@ -621,12 +620,14 @@ impl Store {
// assert enforced through check hsmap.contains_key(&new_id) above.
// Should therefor never fail
assert!(hsmap
.remove(&old_id)
.and_then(|mut entry| {
entry.id = new_id.clone().into();
hsmap.insert(new_id.clone().into(), entry)
}).is_none())
let hsmap_does_not_have_key = hsmap
.remove(&old_id)
.and_then(|mut entry| {
entry.id = new_id.clone();
hsmap.insert(new_id.clone(), entry)
})
.is_none();
assert!(hsmap_does_not_have_key);
}
debug!("Moved");
@ -642,7 +643,7 @@ impl Store {
}
/// Check whether the store has the Entry pointed to by the StoreId `id`
pub fn exists<'a>(&'a self, id: StoreId) -> Result<bool> {
pub fn exists(&self, id: StoreId) -> Result<bool> {
let cache_has_entry = |id: &StoreId|
self.entries
.read()
@ -660,7 +661,6 @@ impl Store {
pub fn path(&self) -> &PathBuf {
&self.location
}
}
impl Debug for Store {
@ -986,13 +986,13 @@ mod test {
assert!(has_imag_version_in_main_section(&Value::Table(map)).is_err());
}
static TEST_ENTRY : &'static str = "---
static TEST_ENTRY : &str = "---
[imag]
version = '0.0.3'
---
Hai";
static TEST_ENTRY_TNL : &'static str = "---
static TEST_ENTRY_TNL : &str = "---
[imag]
version = '0.0.3'
---
@ -1129,14 +1129,12 @@ mod store_tests {
for n in 1..100 {
let s = format!("test-{}", n % 50);
store.create(PathBuf::from(s.clone()))
.ok()
.map(|entry| {
assert!(entry.verify().is_ok());
let loc = entry.get_location().clone().with_base(store.path()).into_pathbuf().unwrap();
assert!(loc.starts_with("/"));
assert!(loc.ends_with(s));
});
if let Ok(entry) = store.create(PathBuf::from(s.clone())) {
assert!(entry.verify().is_ok());
let loc = entry.get_location().clone().with_base(store.path()).into_pathbuf().unwrap();
assert!(loc.starts_with("/"));
assert!(loc.ends_with(s));
}
}
}
@ -1176,8 +1174,8 @@ mod store_tests {
for n in 1..100 {
match store.get(PathBuf::from(format!("test-{}", n))) {
Ok(None) => assert!(true),
_ => assert!(false),
Ok(None) => {},
_ => panic!(),
}
}
}
@ -1188,8 +1186,8 @@ mod store_tests {
for n in 1..100 {
match store.delete(PathBuf::from(format!("test-{}", n))) {
Err(_) => assert!(true),
_ => assert!(false),
Err(_) => {},
_ => panic!(),
}
}
}
@ -1237,4 +1235,3 @@ mod store_tests {
}
}

View file

@ -59,7 +59,7 @@ impl StoreId {
}
}
pub(crate) fn with_base<'a>(self, base: &'a PathBuf) -> StoreIdWithBase<'a> {
pub(crate) fn with_base(self, base: &PathBuf) -> StoreIdWithBase<'_> {
StoreIdWithBase(base, self.0)
}
@ -265,7 +265,7 @@ impl StoreIdIterator {
StoreIdIterator { iter }
}
pub fn with_store<'a>(self, store: &'a Store) -> StoreIdIteratorWithStore<'a> {
pub fn with_store(self, store: &Store) -> StoreIdIteratorWithStore<'_> {
StoreIdIteratorWithStore(self, store)
}

View file

@ -55,11 +55,11 @@ pub fn entry_buffer_to_header_content(buf: &str) -> Result<(Value, String)> {
header_consumed = true;
// do not further process the line
} else if !header_consumed {
let _ = writeln!(header, "{}", line).context(EM::FormatError)?;
writeln!(header, "{}", line).context(EM::FormatError)?;
} else if iter.peek().is_some() {
let _ = writeln!(content, "{}", line).context(EM::FormatError)?;
writeln!(content, "{}", line).context(EM::FormatError)?;
} else {
let _ = write!(content, "{}", line).context(EM::FormatError)?;
write!(content, "{}", line).context(EM::FormatError)?;
}
}