diff options
author | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2019-04-02 21:12:22 -0400 |
---|---|---|
committer | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2019-04-02 21:12:22 -0400 |
commit | 37fa8efbd8691d89fcd22727e3720621fff3680c (patch) | |
tree | 8723b96b26f0d30ffa66f8408d5ca2cd93e4a858 /src/history.rs | |
parent | 554f06d72aeb639548314336b2318e14f8ffcc7e (diff) |
refactor sorting structs
- filtering hidden files is de-coupled from creating direntries
Diffstat (limited to 'src/history.rs')
-rw-r--r-- | src/history.rs | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/history.rs b/src/history.rs index 8ad6619..d803f88 100644 --- a/src/history.rs +++ b/src/history.rs @@ -15,11 +15,11 @@ impl DirHistory { } } - pub fn populate_to_root(&mut self, pathbuf: &PathBuf, sort_type: &sort::SortType) { + pub fn populate_to_root(&mut self, pathbuf: &PathBuf, sort_option: &sort::SortOption) { let mut ancestors = pathbuf.ancestors(); if let Some(mut ancestor) = ancestors.next() { for curr in ancestors { - match structs::JoshutoDirList::new(curr.to_path_buf().clone(), sort_type) { + match structs::JoshutoDirList::new(curr.to_path_buf().clone(), sort_option) { Ok(mut s) => { for (i, dirent) in s.contents.iter().enumerate() { if dirent.path == ancestor { @@ -39,18 +39,18 @@ impl DirHistory { pub fn pop_or_create( &mut self, path: &Path, - sort_type: &sort::SortType, + sort_option: &sort::SortOption, ) -> Result<structs::JoshutoDirList, std::io::Error> { match self.map.remove(&path.to_path_buf()) { Some(mut dir_entry) => { if dir_entry.need_update() { - dir_entry.update_contents(&sort_type)? + dir_entry.update_contents(&sort_option)? } Ok(dir_entry) } None => { let path_clone = path.to_path_buf(); - structs::JoshutoDirList::new(path_clone, &sort_type) + structs::JoshutoDirList::new(path_clone, &sort_option) } } } @@ -58,18 +58,18 @@ impl DirHistory { pub fn get_mut_or_create( &mut self, path: &Path, - sort_type: &sort::SortType, + sort_option: &sort::SortOption, ) -> Result<&mut structs::JoshutoDirList, std::io::Error> { let pathbuf = path.to_path_buf(); match self.map.entry(pathbuf.clone()) { Entry::Occupied(mut entry) => { let dir_entry = entry.get_mut(); if dir_entry.need_update() { - dir_entry.update_contents(&sort_type).unwrap(); + dir_entry.update_contents(&sort_option).unwrap(); } } Entry::Vacant(entry) => { - let s = structs::JoshutoDirList::new(path.to_path_buf(), &sort_type)?; + let s = structs::JoshutoDirList::new(path.to_path_buf(), &sort_option)?; entry.insert(s); } }; |