summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJiayi Zhao <jeff.no.zhao@gmail.com>2019-06-23 23:39:36 -0400
committerJiayi Zhao <jeff.no.zhao@gmail.com>2019-06-23 23:39:36 -0400
commita140825eb453173323df75eba546f1fb7c9dc47b (patch)
tree34460244a3d89a9e6e302911be2f3c7cdd9a8f46 /src
parenta50ab8c76f8467e7f023a9d6098b50027c35c3a6 (diff)
make use of std::io::Result
Diffstat (limited to 'src')
-rw-r--r--src/commands/delete_files.rs7
-rw-r--r--src/commands/file_operations.rs8
-rw-r--r--src/commands/mod.rs1
-rw-r--r--src/commands/open_file.rs2
-rw-r--r--src/commands/reload_dir.rs2
-rw-r--r--src/commands/tab_switch.rs2
-rw-r--r--src/fs/dirlist.rs14
-rw-r--r--src/fs/entry.rs4
-rw-r--r--src/fs/fs_extra_extra.rs5
-rw-r--r--src/fs/metadata.rs4
-rw-r--r--src/history.rs8
-rw-r--r--src/run.rs4
-rw-r--r--src/ui.rs2
13 files changed, 25 insertions, 38 deletions
diff --git a/src/commands/delete_files.rs b/src/commands/delete_files.rs
index 4d7924b..045798f 100644
--- a/src/commands/delete_files.rs
+++ b/src/commands/delete_files.rs
@@ -20,7 +20,7 @@ impl DeleteFiles {
"delete_files"
}
- pub fn remove_files(paths: &[&path::PathBuf]) -> Result<(), std::io::Error> {
+ pub fn remove_files(paths: &[&path::PathBuf]) -> std::io::Result<()> {
for path in paths {
if let Ok(metadata) = fs::symlink_metadata(path) {
if metadata.is_dir() {
@@ -33,10 +33,7 @@ impl DeleteFiles {
Ok(())
}
- fn delete_files(
- context: &mut JoshutoContext,
- view: &JoshutoView,
- ) -> Result<(), std::io::Error> {
+ fn delete_files(context: &mut JoshutoContext, view: &JoshutoView) -> std::io::Result<()> {
ui::wprint_msg(&view.bot_win, "Delete selected files? (Y/n)");
ncurses::timeout(-1);
ncurses::doupdate();
diff --git a/src/commands/file_operations.rs b/src/commands/file_operations.rs
index d878904..441f615 100644
--- a/src/commands/file_operations.rs
+++ b/src/commands/file_operations.rs
@@ -33,7 +33,7 @@ impl LocalState {
TAB_SRC.store(tab_index, atomic::Ordering::Release);
}
- pub fn repopulated_selected_files(dirlist: &JoshutoDirList) -> Result<(), std::io::Error> {
+ pub fn repopulated_selected_files(dirlist: &JoshutoDirList) -> std::io::Result<()> {
let selected = dirlist.get_selected_paths();
if selected.is_empty() {
Err(std::io::Error::new(
@@ -50,12 +50,6 @@ impl LocalState {
}
}
-#[derive(Clone, Debug)]
-pub struct CopyOptions {
- pub overwrite: bool,
- pub skip_exist: bool,
-}
-
pub struct FileOperationThread<T, Q> {
pub tab_src: usize,
pub tab_dest: usize,
diff --git a/src/commands/mod.rs b/src/commands/mod.rs
index 0d7f82c..b249072 100644
--- a/src/commands/mod.rs
+++ b/src/commands/mod.rs
@@ -149,6 +149,7 @@ pub fn from_args(command: &str, args: &[&str]) -> Result<Box<JoshutoCommand>, Ke
"open_file_with" => Ok(Box::new(self::OpenFileWith::new())),
"paste_files" => {
let mut options = fs_extra::dir::CopyOptions::new();
+ options.buffer_size = 1024 * 1024 * 4;
for arg in args {
match *arg {
"--overwrite" => options.overwrite = true,
diff --git a/src/commands/open_file.rs b/src/commands/open_file.rs
index bdc8e44..f622b0b 100644
--- a/src/commands/open_file.rs
+++ b/src/commands/open_file.rs
@@ -77,7 +77,7 @@ impl OpenFile {
Ok(())
}
- fn open_directory(path: &Path, context: &mut JoshutoContext) -> Result<(), std::io::Error> {
+ fn open_directory(path: &Path, context: &mut JoshutoContext) -> std::io::Result<()> {
std::env::set_current_dir(path)?;
let curr_tab = &mut context.tabs[context.curr_tab_index];
diff --git a/src/commands/reload_dir.rs b/src/commands/reload_dir.rs
index b0d5c7a..b69b2c5 100644
--- a/src/commands/reload_dir.rs
+++ b/src/commands/reload_dir.rs
@@ -17,7 +17,7 @@ impl ReloadDirList {
"reload_dir_list"
}
- pub fn reload(index: usize, context: &mut JoshutoContext) -> Result<(), std::io::Error> {
+ pub fn reload(index: usize, context: &mut JoshutoContext) -> std::io::Result<()> {
let curr_tab = &mut context.tabs[index];
let sort_option = &context.config_t.sort_option;
curr_tab.curr_list.update_contents(sort_option)?;
diff --git a/src/commands/tab_switch.rs b/src/commands/tab_switch.rs
index e7bc4a3..64760c6 100644
--- a/src/commands/tab_switch.rs
+++ b/src/commands/tab_switch.rs
@@ -23,7 +23,7 @@ impl TabSwitch {
new_index: usize,
context: &mut JoshutoContext,
view: &JoshutoView,
- ) -> Result<(), std::io::Error> {
+ ) -> std::io::Result<()> {
context.curr_tab_index = new_index;
let path = &context.curr_tab_ref().curr_path;
env::set_current_dir(path)?;
diff --git a/src/fs/dirlist.rs b/src/fs/dirlist.rs
index fe468ce..3733374 100644
--- a/src/fs/dirlist.rs
+++ b/src/fs/dirlist.rs
@@ -15,10 +15,7 @@ pub struct JoshutoDirList {
}
impl JoshutoDirList {
- pub fn new(
- path: path::PathBuf,
- sort_option: &sort::SortOption,
- ) -> Result<Self, std::io::Error> {
+ pub fn new(path: path::PathBuf, sort_option: &sort::SortOption) -> std::io::Result<Self> {
let mut contents = read_dir_list(path.as_path(), sort_option)?;
contents.sort_by(&sort_option.compare_func());
@@ -49,10 +46,7 @@ impl JoshutoDirList {
&self.path
}
- pub fn update_contents(
- &mut self,
- sort_option: &sort::SortOption,
- ) -> Result<(), std::io::Error> {
+ pub fn update_contents(&mut self, sort_option: &sort::SortOption) -> std::io::Result<()> {
let sort_func = sort_option.compare_func();
let mut contents = read_dir_list(&self.path, sort_option)?;
contents.sort_by(&sort_func);
@@ -125,7 +119,7 @@ impl JoshutoDirList {
fn read_dir_list(
path: &path::Path,
sort_option: &sort::SortOption,
-) -> Result<Vec<JoshutoDirEntry>, std::io::Error> {
+) -> std::io::Result<Vec<JoshutoDirEntry>> {
let filter_func = sort_option.filter_func();
let results: Vec<JoshutoDirEntry> = fs::read_dir(path)?
.filter(filter_func)
@@ -134,7 +128,7 @@ fn read_dir_list(
Ok(results)
}
-fn map_entry_default(result: Result<fs::DirEntry, std::io::Error>) -> Option<JoshutoDirEntry> {
+fn map_entry_default(result: std::io::Result<fs::DirEntry>) -> Option<JoshutoDirEntry> {
match result {
Ok(direntry) => match JoshutoDirEntry::from(&direntry) {
Ok(s) => Some(s),
diff --git a/src/fs/entry.rs b/src/fs/entry.rs
index 7015534..4b6fd79 100644
--- a/src/fs/entry.rs
+++ b/src/fs/entry.rs
@@ -1,4 +1,4 @@
-use std::{fs, io, path};
+use std::{fs, path};
use crate::fs::JoshutoMetadata;
@@ -12,7 +12,7 @@ pub struct JoshutoDirEntry {
}
impl JoshutoDirEntry {
- pub fn from(direntry: &fs::DirEntry) -> Result<Self, io::Error> {
+ pub fn from(direntry: &fs::DirEntry) -> std::io::Result<Self> {
let name = match direntry.file_name().into_string() {
Ok(s) => s,
Err(_) => {
diff --git a/src/fs/fs_extra_extra.rs b/src/fs/fs_extra_extra.rs
index a2492cc..9bc3458 100644
--- a/src/fs/fs_extra_extra.rs
+++ b/src/fs/fs_extra_extra.rs
@@ -16,7 +16,7 @@ fn rename_filename_conflict(mut path: path::PathBuf) -> path::PathBuf {
}
pub fn fs_copy_with_progress<P, Q, F>(
- paths: &Vec<P>,
+ paths: &[P],
to: Q,
mut options: fs_extra::dir::CopyOptions,
mut progress_handler: F,
@@ -80,6 +80,7 @@ where
let dir_handler = |info: fs_extra::dir::TransitProcess| {
info_process.copied_bytes = result + info.copied_bytes;
info_process.state = info.state;
+ info_process.file_name = info.file_name;
let result = progress_handler(info_process.clone());
match result {
fs_extra::dir::TransitProcessResult::OverwriteAll => {
@@ -159,7 +160,7 @@ where
}
pub fn fs_cut_with_progress<P, Q, F>(
- paths: &Vec<P>,
+ paths: &[P],
to: Q,
mut options: fs_extra::dir::CopyOptions,
mut progress_handler: F,
diff --git a/src/fs/metadata.rs b/src/fs/metadata.rs
index fb85a6e..f3fea53 100644
--- a/src/fs/metadata.rs
+++ b/src/fs/metadata.rs
@@ -1,4 +1,4 @@
-use std::{fs, io, path, time};
+use std::{fs, path, time};
#[derive(Clone, Debug)]
pub struct JoshutoMetadata {
@@ -13,7 +13,7 @@ pub struct JoshutoMetadata {
}
impl JoshutoMetadata {
- pub fn from(path: &path::Path) -> Result<Self, io::Error> {
+ pub fn from(path: &path::Path) -> std::io::Result<Self> {
#[cfg(unix)]
use std::os::unix::fs::MetadataExt;
diff --git a/src/history.rs b/src/history.rs
index fb2eeeb..47b440c 100644
--- a/src/history.rs
+++ b/src/history.rs
@@ -10,12 +10,12 @@ pub trait DirectoryHistory {
&mut self,
path: &Path,
sort_option: &sort::SortOption,
- ) -> Result<JoshutoDirList, std::io::Error>;
+ ) -> std::io::Result<JoshutoDirList>;
fn get_mut_or_create(
&mut self,
path: &Path,
sort_option: &sort::SortOption,
- ) -> Result<&mut JoshutoDirList, std::io::Error>;
+ ) -> std::io::Result<&mut JoshutoDirList>;
fn depreciate_all_entries(&mut self);
}
@@ -54,7 +54,7 @@ impl DirectoryHistory for JoshutoHistory {
&mut self,
path: &Path,
sort_option: &sort::SortOption,
- ) -> Result<JoshutoDirList, std::io::Error> {
+ ) -> std::io::Result<JoshutoDirList> {
match self.remove(&path.to_path_buf()) {
Some(mut dirlist) => {
if dirlist.need_update() {
@@ -79,7 +79,7 @@ impl DirectoryHistory for JoshutoHistory {
&mut self,
path: &Path,
sort_option: &sort::SortOption,
- ) -> Result<&mut JoshutoDirList, std::io::Error> {
+ ) -> std::io::Result<&mut JoshutoDirList> {
match self.entry(path.to_path_buf().clone()) {
Entry::Occupied(entry) => {
/*
diff --git a/src/run.rs b/src/run.rs
index 09e403c..58dfc15 100644
--- a/src/run.rs
+++ b/src/run.rs
@@ -51,7 +51,7 @@ fn reload_tab(
index: usize,
context: &mut JoshutoContext,
view: &JoshutoView,
-) -> Result<(), std::io::Error> {
+) -> std::io::Result<()> {
ReloadDirList::reload(index, context)?;
if index == context.curr_tab_index {
let dirty_tab = &mut context.tabs[index];
@@ -86,7 +86,7 @@ fn join_thread(
Ok(())
}
-fn process_threads(context: &mut JoshutoContext, view: &JoshutoView) -> Result<(), std::io::Error> {
+fn process_threads(context: &mut JoshutoContext, view: &JoshutoView) -> std::io::Result<()> {
let thread_wait_duration: time::Duration = time::Duration::from_millis(100);
for i in 0..context.threads.len() {
match &context.threads[i].recv_timeout(&thread_wait_duration) {
diff --git a/src/ui.rs b/src/ui.rs
index 8da858f..578be47 100644
--- a/src/ui.rs
+++ b/src/ui.rs
@@ -350,7 +350,7 @@ pub fn show_fs_operation_progress(
) {
let percentage: f64 = process_info.copied_bytes as f64 / process_info.total_bytes as f64;
- let cols: i32 = (win.cols as f64 * percentage) as i32;
+ let cols: i32 = (f64::from(win.cols) * percentage) as i32;
ncurses::mvwchgat(
win.win,
0,