summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiayi Zhao <jeff.no.zhao@gmail.com>2019-06-27 22:23:09 -0400
committerJiayi Zhao <jeff.no.zhao@gmail.com>2019-06-27 22:23:09 -0400
commite04a0635c0732a6b04893f9d8b49529c221b76a0 (patch)
tree53364c42839798b320a2eaa48706fe71a222264b
parenta140825eb453173323df75eba546f1fb7c9dc47b (diff)
populate_to_root now returns a Result
-rw-r--r--src/commands/change_directory.rs2
-rw-r--r--src/commands/rename_file.rs2
-rw-r--r--src/history.rs29
-rw-r--r--src/tab.rs4
4 files changed, 17 insertions, 20 deletions
diff --git a/src/commands/change_directory.rs b/src/commands/change_directory.rs
index 6a63e7c..27fa809 100644
--- a/src/commands/change_directory.rs
+++ b/src/commands/change_directory.rs
@@ -33,7 +33,7 @@ impl ChangeDirectory {
curr_tab
.history
- .populate_to_root(&curr_tab.curr_path, &context.config_t.sort_option);
+ .populate_to_root(&curr_tab.curr_path, &context.config_t.sort_option)?;
let mut new_curr_list = curr_tab
.history
diff --git a/src/commands/rename_file.rs b/src/commands/rename_file.rs
index cca52a2..a43de07 100644
--- a/src/commands/rename_file.rs
+++ b/src/commands/rename_file.rs
@@ -33,7 +33,7 @@ impl RenameFile {
path: &path::PathBuf,
context: &mut JoshutoContext,
view: &JoshutoView,
- ) -> Result<(), std::io::Error> {
+ ) -> std::io::Result<()> {
let new_path = &self.path;
if new_path.exists() {
let err =
diff --git a/src/history.rs b/src/history.rs
index 47b440c..3dc6687 100644
--- a/src/history.rs
+++ b/src/history.rs
@@ -5,7 +5,7 @@ use crate::fs::JoshutoDirList;
use crate::sort;
pub trait DirectoryHistory {
- fn populate_to_root(&mut self, pathbuf: &PathBuf, sort_option: &sort::SortOption);
+ fn populate_to_root(&mut self, pathbuf: &PathBuf, sort_option: &sort::SortOption) -> std::io::Result<()>;
fn pop_or_create(
&mut self,
path: &Path,
@@ -22,32 +22,29 @@ pub trait DirectoryHistory {
pub type JoshutoHistory = HashMap<PathBuf, JoshutoDirList>;
impl DirectoryHistory for JoshutoHistory {
- fn populate_to_root(&mut self, pathbuf: &PathBuf, sort_option: &sort::SortOption) {
+ fn populate_to_root(&mut self, pathbuf: &PathBuf, sort_option: &sort::SortOption) -> std::io::Result<()> {
let mut ancestors = pathbuf.ancestors();
match ancestors.next() {
None => {}
Some(mut ancestor) => {
for curr in ancestors {
- match JoshutoDirList::new(curr.to_path_buf().clone(), sort_option) {
- Ok(mut s) => {
- let index = s.contents.iter().enumerate().find_map(|(i, dir)| {
- if dir.file_path() == ancestor {
- Some(i)
- } else {
- None
- }
- });
- if let Some(i) = index {
- s.index = Some(i);
- }
- self.insert(curr.to_path_buf(), s);
+ let mut dirlist = JoshutoDirList::new(curr.to_path_buf().clone(), sort_option)?;
+ let index = dirlist.contents.iter().enumerate().find_map(|(i, dir)| {
+ if dir.file_path() == ancestor {
+ Some(i)
+ } else {
+ None
}
- Err(e) => eprintln!("populate_to_root: {}", e),
+ });
+ if let Some(i) = index {
+ dirlist.index = Some(i);
}
+ self.insert(curr.to_path_buf(), dirlist);
ancestor = curr;
}
}
}
+ Ok(())
}
fn pop_or_create(
diff --git a/src/tab.rs b/src/tab.rs
index ce2f274..95dfb3e 100644
--- a/src/tab.rs
+++ b/src/tab.rs
@@ -19,9 +19,9 @@ pub struct JoshutoTab {
}
impl JoshutoTab {
- pub fn new(curr_path: PathBuf, sort_option: &sort::SortOption) -> Result<Self, std::io::Error> {
+ pub fn new(curr_path: PathBuf, sort_option: &sort::SortOption) -> std::io::Result<Self> {
let mut history = JoshutoHistory::new();
- history.populate_to_root(&curr_path, sort_option);
+ history.populate_to_root(&curr_path, sort_option)?;
let curr_list = history.pop_or_create(&curr_path, sort_option)?;