diff options
author | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2019-04-24 10:36:49 -0400 |
---|---|---|
committer | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2019-04-24 10:36:49 -0400 |
commit | 6e95a6600679e6787a56ec5ef2a88fe0fbcf031f (patch) | |
tree | 4495e3a2bbb12b96b0b767ab1b844040c7cc4c71 /src/history.rs | |
parent | e9a0d00d46ba4955f7d45d12aa412462e3daab39 (diff) |
add more error handling
- optimize/cleanup code
Diffstat (limited to 'src/history.rs')
-rw-r--r-- | src/history.rs | 17 |
1 files changed, 5 insertions, 12 deletions
diff --git a/src/history.rs b/src/history.rs index 0981b9d..92ddd60 100644 --- a/src/history.rs +++ b/src/history.rs @@ -64,25 +64,18 @@ impl DirHistory { path: &Path, sort_option: &sort::SortOption, ) -> Result<&mut structs::JoshutoDirList, std::io::Error> { - let pathbuf = path.to_path_buf(); - match self.map.entry(pathbuf.clone()) { + match self.map.entry(path.to_path_buf().clone()) { Entry::Occupied(mut entry) => { let dir_entry = entry.get_mut(); if dir_entry.need_update() { - dir_entry.update_contents(&sort_option); + dir_entry.update_contents(&sort_option)?; } + Ok(entry.into_mut()) } Entry::Vacant(entry) => { let s = structs::JoshutoDirList::new(path.to_path_buf(), &sort_option)?; - entry.insert(s); + Ok(entry.insert(s)) } - }; - match self.map.get_mut(&pathbuf) { - Some(s) => Ok(s), - None => Err(std::io::Error::new( - std::io::ErrorKind::NotFound, - "Can't find file", - )), } } @@ -95,6 +88,6 @@ impl DirHistory { pub fn depecrate_all_entries(&mut self) { self.map .iter_mut() - .for_each(|(_, v)| v.update_needed = true); + .for_each(|(_, v)| v.depreciate()); } } |