[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:
parent
7b5f216e01
commit
b2997517bb
6 changed files with 42 additions and 49 deletions
|
@ -108,7 +108,7 @@ impl FileAbstraction for FSFileAbstraction {
|
||||||
if let Some(p) = to.parent() {
|
if let Some(p) = to.parent() {
|
||||||
if !p.exists() {
|
if !p.exists() {
|
||||||
debug!("Creating: {:?}", p);
|
debug!("Creating: {:?}", p);
|
||||||
let _ = create_dir_all(&p).context(EM::DirNotCreated)?;
|
create_dir_all(&p).context(EM::DirNotCreated)?;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
debug!("Failed to find parent. This looks like it will fail now");
|
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>> {
|
fn open_file<A: AsRef<Path>>(p: A) -> ::std::io::Result<Option<File>> {
|
||||||
match OpenOptions::new().write(true).read(true).open(p) {
|
match OpenOptions::new().write(true).read(true).open(p) {
|
||||||
Err(e) => match e.kind() {
|
Err(e) => match e.kind() {
|
||||||
::std::io::ErrorKind::NotFound => return Ok(None),
|
::std::io::ErrorKind::NotFound => Ok(None),
|
||||||
_ => return Err(e),
|
_ => Err(e),
|
||||||
},
|
},
|
||||||
Ok(file) => Ok(Some(file))
|
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());
|
trace!("'{}' is directory = {}", parent.display(), parent.is_dir());
|
||||||
if !parent.is_dir() {
|
if !parent.is_dir() {
|
||||||
trace!("Implicitely creating directory: {:?}", parent);
|
trace!("Implicitely creating directory: {:?}", parent);
|
||||||
let _ = create_dir_all(parent)?;
|
create_dir_all(parent)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
OpenOptions::new().write(true).read(true).create(true).open(p)
|
OpenOptions::new().write(true).read(true).create(true).open(p)
|
||||||
|
|
|
@ -79,14 +79,11 @@ impl FileAbstractionInstance for InMemoryFileAbstractionInstance {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_file_content(&mut self, buf: &Entry) -> Result<()> {
|
fn write_file_content(&mut self, buf: &Entry) -> Result<()> {
|
||||||
match *self {
|
let absent_path = &self.absent_path;
|
||||||
InMemoryFileAbstractionInstance { ref absent_path, .. } => {
|
let mut mtx = self.fs_abstraction.lock().expect("Locking Mutex failed");
|
||||||
let mut mtx = self.fs_abstraction.lock().expect("Locking Mutex failed");
|
let backend = mtx.get_mut();
|
||||||
let backend = mtx.get_mut();
|
let _ = backend.insert(absent_path.clone(), buf.clone());
|
||||||
let _ = backend.insert(absent_path.clone(), buf.clone());
|
Ok(())
|
||||||
return Ok(());
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,12 +98,11 @@ impl InMemoryFileAbstraction {
|
||||||
&self.virtual_filesystem
|
&self.virtual_filesystem
|
||||||
}
|
}
|
||||||
|
|
||||||
fn backend_cloned<'a>(&'a self) -> Result<HashMap<PathBuf, Entry>> {
|
fn backend_cloned(&self) -> Result<HashMap<PathBuf, Entry>> {
|
||||||
self.virtual_filesystem
|
self.virtual_filesystem
|
||||||
.lock()
|
.lock()
|
||||||
.map_err(|_| Error::from(EM::LockError))
|
.map_err(|_| Error::from(EM::LockError))
|
||||||
.map(|mtx| mtx.deref().borrow().clone())
|
.map(|mtx| mtx.deref().borrow().clone())
|
||||||
.into()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -172,7 +168,7 @@ impl FileAbstraction for InMemoryFileAbstraction {
|
||||||
self.backend_cloned().map(Drain::new)
|
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);
|
debug!("Draining into : {:?}", self);
|
||||||
let mut mtx = self.backend()
|
let mut mtx = self.backend()
|
||||||
.lock()
|
.lock()
|
||||||
|
|
|
@ -46,7 +46,7 @@ pub(crate) trait FileAbstraction : Debug {
|
||||||
fn new_instance(&self, p: PathBuf) -> Box<dyn FileAbstractionInstance>;
|
fn new_instance(&self, p: PathBuf) -> Box<dyn FileAbstractionInstance>;
|
||||||
|
|
||||||
fn drain(&self) -> Result<Drain>;
|
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>>;
|
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())
|
Drain::new(HashMap::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn iter<'a>(&'a mut self) -> DrainIter<'a> {
|
pub fn iter(&mut self) -> DrainIter<'_> {
|
||||||
DrainIter(self.0.drain())
|
DrainIter(self.0.drain())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -148,7 +148,6 @@ pub struct Store {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Store {
|
impl Store {
|
||||||
|
|
||||||
/// Create a new Store object
|
/// Create a new Store object
|
||||||
///
|
///
|
||||||
/// This opens a Store in `location`. The store_config is used to check whether creating the
|
/// 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 {
|
let store = Store {
|
||||||
location: location.clone(),
|
location: location.clone(),
|
||||||
entries: Arc::new(RwLock::new(HashMap::new())),
|
entries: Arc::new(RwLock::new(HashMap::new())),
|
||||||
backend: backend,
|
backend,
|
||||||
};
|
};
|
||||||
|
|
||||||
debug!("Store building succeeded");
|
debug!("Store building succeeded");
|
||||||
|
@ -491,7 +490,7 @@ impl Store {
|
||||||
}
|
}
|
||||||
|
|
||||||
debug!("Seems like {:?} is on the FS", pb);
|
debug!("Seems like {:?} is on the FS", pb);
|
||||||
let _ = self
|
self
|
||||||
.backend
|
.backend
|
||||||
.remove_file(&pb)
|
.remove_file(&pb)
|
||||||
.context(EM::FileError)
|
.context(EM::FileError)
|
||||||
|
@ -608,7 +607,7 @@ impl Store {
|
||||||
}
|
}
|
||||||
debug!("New entry does not yet exist on filesystem. Good.");
|
debug!("New entry does not yet exist on filesystem. Good.");
|
||||||
|
|
||||||
let _ = self
|
self
|
||||||
.backend
|
.backend
|
||||||
.rename(&old_id_pb, &new_id_pb)
|
.rename(&old_id_pb, &new_id_pb)
|
||||||
.context({
|
.context({
|
||||||
|
@ -621,12 +620,14 @@ impl Store {
|
||||||
|
|
||||||
// assert enforced through check hsmap.contains_key(&new_id) above.
|
// assert enforced through check hsmap.contains_key(&new_id) above.
|
||||||
// Should therefor never fail
|
// Should therefor never fail
|
||||||
assert!(hsmap
|
let hsmap_does_not_have_key = hsmap
|
||||||
.remove(&old_id)
|
.remove(&old_id)
|
||||||
.and_then(|mut entry| {
|
.and_then(|mut entry| {
|
||||||
entry.id = new_id.clone().into();
|
entry.id = new_id.clone();
|
||||||
hsmap.insert(new_id.clone().into(), entry)
|
hsmap.insert(new_id.clone(), entry)
|
||||||
}).is_none())
|
})
|
||||||
|
.is_none();
|
||||||
|
assert!(hsmap_does_not_have_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
debug!("Moved");
|
debug!("Moved");
|
||||||
|
@ -642,7 +643,7 @@ impl Store {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check whether the store has the Entry pointed to by the StoreId `id`
|
/// 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|
|
let cache_has_entry = |id: &StoreId|
|
||||||
self.entries
|
self.entries
|
||||||
.read()
|
.read()
|
||||||
|
@ -660,7 +661,6 @@ impl Store {
|
||||||
pub fn path(&self) -> &PathBuf {
|
pub fn path(&self) -> &PathBuf {
|
||||||
&self.location
|
&self.location
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Debug for Store {
|
impl Debug for Store {
|
||||||
|
@ -986,13 +986,13 @@ mod test {
|
||||||
assert!(has_imag_version_in_main_section(&Value::Table(map)).is_err());
|
assert!(has_imag_version_in_main_section(&Value::Table(map)).is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
static TEST_ENTRY : &'static str = "---
|
static TEST_ENTRY : &str = "---
|
||||||
[imag]
|
[imag]
|
||||||
version = '0.0.3'
|
version = '0.0.3'
|
||||||
---
|
---
|
||||||
Hai";
|
Hai";
|
||||||
|
|
||||||
static TEST_ENTRY_TNL : &'static str = "---
|
static TEST_ENTRY_TNL : &str = "---
|
||||||
[imag]
|
[imag]
|
||||||
version = '0.0.3'
|
version = '0.0.3'
|
||||||
---
|
---
|
||||||
|
@ -1129,14 +1129,12 @@ mod store_tests {
|
||||||
|
|
||||||
for n in 1..100 {
|
for n in 1..100 {
|
||||||
let s = format!("test-{}", n % 50);
|
let s = format!("test-{}", n % 50);
|
||||||
store.create(PathBuf::from(s.clone()))
|
if let Ok(entry) = store.create(PathBuf::from(s.clone())) {
|
||||||
.ok()
|
assert!(entry.verify().is_ok());
|
||||||
.map(|entry| {
|
let loc = entry.get_location().clone().with_base(store.path()).into_pathbuf().unwrap();
|
||||||
assert!(entry.verify().is_ok());
|
assert!(loc.starts_with("/"));
|
||||||
let loc = entry.get_location().clone().with_base(store.path()).into_pathbuf().unwrap();
|
assert!(loc.ends_with(s));
|
||||||
assert!(loc.starts_with("/"));
|
}
|
||||||
assert!(loc.ends_with(s));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1176,8 +1174,8 @@ mod store_tests {
|
||||||
|
|
||||||
for n in 1..100 {
|
for n in 1..100 {
|
||||||
match store.get(PathBuf::from(format!("test-{}", n))) {
|
match store.get(PathBuf::from(format!("test-{}", n))) {
|
||||||
Ok(None) => assert!(true),
|
Ok(None) => {},
|
||||||
_ => assert!(false),
|
_ => panic!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1188,8 +1186,8 @@ mod store_tests {
|
||||||
|
|
||||||
for n in 1..100 {
|
for n in 1..100 {
|
||||||
match store.delete(PathBuf::from(format!("test-{}", n))) {
|
match store.delete(PathBuf::from(format!("test-{}", n))) {
|
||||||
Err(_) => assert!(true),
|
Err(_) => {},
|
||||||
_ => assert!(false),
|
_ => panic!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1237,4 +1235,3 @@ mod store_tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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)
|
StoreIdWithBase(base, self.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -265,7 +265,7 @@ impl StoreIdIterator {
|
||||||
StoreIdIterator { iter }
|
StoreIdIterator { iter }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_store<'a>(self, store: &'a Store) -> StoreIdIteratorWithStore<'a> {
|
pub fn with_store(self, store: &Store) -> StoreIdIteratorWithStore<'_> {
|
||||||
StoreIdIteratorWithStore(self, store)
|
StoreIdIteratorWithStore(self, store)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,11 +55,11 @@ pub fn entry_buffer_to_header_content(buf: &str) -> Result<(Value, String)> {
|
||||||
header_consumed = true;
|
header_consumed = true;
|
||||||
// do not further process the line
|
// do not further process the line
|
||||||
} else if !header_consumed {
|
} else if !header_consumed {
|
||||||
let _ = writeln!(header, "{}", line).context(EM::FormatError)?;
|
writeln!(header, "{}", line).context(EM::FormatError)?;
|
||||||
} else if iter.peek().is_some() {
|
} else if iter.peek().is_some() {
|
||||||
let _ = writeln!(content, "{}", line).context(EM::FormatError)?;
|
writeln!(content, "{}", line).context(EM::FormatError)?;
|
||||||
} else {
|
} else {
|
||||||
let _ = write!(content, "{}", line).context(EM::FormatError)?;
|
write!(content, "{}", line).context(EM::FormatError)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue