From 8dfccba0b81a89a6c0a4c68abde392a1bd33a0fc Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 1 Mar 2016 21:12:40 +0100 Subject: [PATCH 01/10] Remove unused "mut" from Store::retrieve_copy() --- libimagstore/src/store.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libimagstore/src/store.rs b/libimagstore/src/store.rs index 16121b62..4c8a18c1 100644 --- a/libimagstore/src/store.rs +++ b/libimagstore/src/store.rs @@ -211,12 +211,12 @@ impl Store { /// Retrieve a copy of a given entry, this cannot be used to mutate /// the one on disk pub fn retrieve_copy(&self, id: StoreId) -> Result { - let mut entries_lock = self.entries.write(); + let entries_lock = self.entries.write(); if entries_lock.is_err() { return Err(StoreError::new(StoreErrorKind::LockPoisoned, None)) } - let mut entries = entries_lock.unwrap(); + let entries = entries_lock.unwrap(); // if the entry is currently modified by the user, we cannot drop it if entries.get(&id).map(|e| e.is_borrowed()).unwrap_or(false) { From 4390c39a6c74d45e8154d4bf02b0bea6f5458ef4 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 1 Mar 2016 21:12:57 +0100 Subject: [PATCH 02/10] Remove unused "mut" from Store::delete() --- libimagstore/src/store.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libimagstore/src/store.rs b/libimagstore/src/store.rs index 4c8a18c1..889650ee 100644 --- a/libimagstore/src/store.rs +++ b/libimagstore/src/store.rs @@ -233,7 +233,7 @@ impl Store { return Err(StoreError::new(StoreErrorKind::StorePathOutsideStore, None)); } - let mut entries_lock = self.entries.write(); + let entries_lock = self.entries.write(); if entries_lock.is_err() { return Err(StoreError::new(StoreErrorKind::LockPoisoned, None)) } From 85e69f083e4efa06d41f4183e01c1b951c9b01aa Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 1 Mar 2016 21:13:35 +0100 Subject: [PATCH 03/10] Remove unused "mut" from EntryHeader::insert_with_sep() --- libimagstore/src/store.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libimagstore/src/store.rs b/libimagstore/src/store.rs index 889650ee..3d47d7cc 100644 --- a/libimagstore/src/store.rs +++ b/libimagstore/src/store.rs @@ -417,7 +417,7 @@ impl EntryHeader { let destination = destination.unwrap(); let path_to_dest = tokens[..(tokens.len() - 1)].into(); // N - 1 tokens - let mut value = EntryHeader::walk_header(&mut self.header, path_to_dest); // walk N-1 tokens + let value = EntryHeader::walk_header(&mut self.header, path_to_dest); // walk N-1 tokens if value.is_err() { return value.map(|_| false); } From 309e70df142b297d29b9af13db155d6dc1cde770 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 1 Mar 2016 21:13:56 +0100 Subject: [PATCH 04/10] Remove unused "mut" from EntryHeader::set_with_sep() --- libimagstore/src/store.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libimagstore/src/store.rs b/libimagstore/src/store.rs index 3d47d7cc..9a4be737 100644 --- a/libimagstore/src/store.rs +++ b/libimagstore/src/store.rs @@ -515,7 +515,7 @@ impl EntryHeader { debug!("destination = {:?}", destination); let path_to_dest = tokens[..(tokens.len() - 1)].into(); // N - 1 tokens - let mut value = EntryHeader::walk_header(&mut self.header, path_to_dest); // walk N-1 tokens + let value = EntryHeader::walk_header(&mut self.header, path_to_dest); // walk N-1 tokens if value.is_err() { return Err(value.err().unwrap()); } From ed3da38701b81d70e401ae4c21b130889f44bb62 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 1 Mar 2016 21:16:09 +0100 Subject: [PATCH 05/10] Remove unused "mut" from EntryHeader::read_with_sep() --- libimagstore/src/store.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libimagstore/src/store.rs b/libimagstore/src/store.rs index 9a4be737..4c733811 100644 --- a/libimagstore/src/store.rs +++ b/libimagstore/src/store.rs @@ -614,7 +614,7 @@ impl EntryHeader { let tokens = tokens.unwrap(); let mut header_clone = self.header.clone(); // we clone as READing is simpler this way - let mut value = EntryHeader::walk_header(&mut header_clone, tokens); // walk N-1 tokens + let value = EntryHeader::walk_header(&mut header_clone, tokens); // walk N-1 tokens if value.is_err() { let e = value.err().unwrap(); match e.err_type() { From 08c37c5fcb86ece612a3a7a8107a46cd1119972b Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 1 Mar 2016 21:16:23 +0100 Subject: [PATCH 06/10] Remove unused "mut" from EntryHeader::delete() --- libimagstore/src/store.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libimagstore/src/store.rs b/libimagstore/src/store.rs index 4c733811..1cc0d94d 100644 --- a/libimagstore/src/store.rs +++ b/libimagstore/src/store.rs @@ -642,7 +642,7 @@ impl EntryHeader { debug!("destination = {:?}", destination); let path_to_dest = tokens[..(tokens.len() - 1)].into(); // N - 1 tokens - let mut value = EntryHeader::walk_header(&mut self.header, path_to_dest); // walk N-1 tokens + let value = EntryHeader::walk_header(&mut self.header, path_to_dest); // walk N-1 tokens if value.is_err() { return Err(value.err().unwrap()); } From 38b9e15615db0b5fb285f0cd07b3877f914cd8f5 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 1 Mar 2016 21:19:15 +0100 Subject: [PATCH 07/10] Remove unreachable statement --- libimagstore/src/store.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/libimagstore/src/store.rs b/libimagstore/src/store.rs index 1cc0d94d..31af2c80 100644 --- a/libimagstore/src/store.rs +++ b/libimagstore/src/store.rs @@ -617,12 +617,11 @@ impl EntryHeader { let value = EntryHeader::walk_header(&mut header_clone, tokens); // walk N-1 tokens if value.is_err() { let e = value.err().unwrap(); - match e.err_type() { + return match e.err_type() { // We cannot find the header key, as there is no path to it - StoreErrorKind::HeaderKeyNotFound => return Ok(None), - _ => return Err(e), - } - return Err(e); + StoreErrorKind::HeaderKeyNotFound => Ok(None), + _ => Err(e), + }; } Ok(Some(value.unwrap().clone())) } From 1a8106dfd253d86c9e921ce0a6c0db6185faca0f Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 1 Mar 2016 21:20:53 +0100 Subject: [PATCH 08/10] Add missing error-forwarding --- libimagstore/src/store.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libimagstore/src/store.rs b/libimagstore/src/store.rs index 31af2c80..e46a578e 100644 --- a/libimagstore/src/store.rs +++ b/libimagstore/src/store.rs @@ -795,7 +795,7 @@ fn verify_header(t: &Table) -> Result<()> { fn verify_header_consistency(t: Table) -> EntryResult { use std::error::Error; if let Err(e) = verify_header(&t) { - Err(ParserError::new(ParserErrorKind::HeaderInconsistency, None)) + Err(ParserError::new(ParserErrorKind::HeaderInconsistency, Some(Box::new(e)))) } else { Ok(t) } From 22e9f8a93b907e7f9c64cc0e1d91c8344f278a83 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 1 Mar 2016 21:21:14 +0100 Subject: [PATCH 09/10] Remove unused import --- libimagstore/src/store.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/libimagstore/src/store.rs b/libimagstore/src/store.rs index e46a578e..22c38d62 100644 --- a/libimagstore/src/store.rs +++ b/libimagstore/src/store.rs @@ -793,7 +793,6 @@ fn verify_header(t: &Table) -> Result<()> { } fn verify_header_consistency(t: Table) -> EntryResult
{ - use std::error::Error; if let Err(e) = verify_header(&t) { Err(ParserError::new(ParserErrorKind::HeaderInconsistency, Some(Box::new(e)))) } else { From 74634227e027b240613973794ea83e66df65712c Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 1 Mar 2016 21:23:09 +0100 Subject: [PATCH 10/10] Use unused result --- libimagstore/src/lazyfile.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/libimagstore/src/lazyfile.rs b/libimagstore/src/lazyfile.rs index b613ad91..91f19922 100644 --- a/libimagstore/src/lazyfile.rs +++ b/libimagstore/src/lazyfile.rs @@ -58,10 +58,9 @@ impl LazyFile { LazyFile::File(ref mut f) => return { // We seek to the beginning of the file since we expect each // access to the file to be in a different context - f.seek(SeekFrom::Start(0)).map_err(|e| - StoreError::new( - StoreErrorKind::FileNotCreated, Some(Box::new(e)))); - Ok(f) + f.seek(SeekFrom::Start(0)) + .map_err(|e| StoreError::new(StoreErrorKind::FileNotCreated, Some(Box::new(e)))) + .map(|_| f) }, LazyFile::Absent(ref p) => { try!(open_file(p).map_err(|e| {