summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiayi Zhao <jeff.no.zhao@gmail.com>2019-04-19 18:02:52 -0400
committerJiayi Zhao <jeff.no.zhao@gmail.com>2019-04-19 18:02:52 -0400
commit7380fd2a60b8153815a10dfd9a2e27513b3f7cad (patch)
treeac45b609e2f3c5ade5cb4f081faa64d0853e908b
parent023bd5ff25421ff6d4296d738f8be1addbddb316 (diff)
fix only copying a single file over and subsequent ones get an invalid path
- changed selection.rs to work with new methods in struct
-rw-r--r--src/commands/cursor_move.rs6
-rw-r--r--src/commands/file_operations.rs27
-rw-r--r--src/commands/rename_file.rs5
-rw-r--r--src/commands/selection.rs16
4 files changed, 24 insertions, 30 deletions
diff --git a/src/commands/cursor_move.rs b/src/commands/cursor_move.rs
index 4a3dea4..ec80c0d 100644
--- a/src/commands/cursor_move.rs
+++ b/src/commands/cursor_move.rs
@@ -16,9 +16,9 @@ impl CursorMove {
Some(_) => {
let dir_len = curr_list.contents.len();
/*
- if index == dir_len - 1 {
- return;
- }
+ if index == dir_len - 1 {
+ return;
+ }
*/
if new_index >= dir_len {
new_index = dir_len - 1;
diff --git a/src/commands/file_operations.rs b/src/commands/file_operations.rs
index b8ad4c4..7abb5a5 100644
--- a/src/commands/file_operations.rs
+++ b/src/commands/file_operations.rs
@@ -167,7 +167,7 @@ impl JoshutoRunnable for PasteFiles {
};
if let Ok(s) = thread {
- ncurses::timeout(-1);
+ ncurses::timeout(0);
context.threads.push(s);
}
Ok(())
@@ -192,14 +192,14 @@ impl PasteFiles {
let src_ino;
let paths = SELECTED_FILES.lock().unwrap().take();
match paths {
- Some(s) => {
- if s.len() == 0 {
+ Some(paths) => {
+ if paths.len() == 0 {
return Err(std::io::Error::new(
std::io::ErrorKind::Other,
"no files selected",
));
}
- src_ino = s[0].metadata()?.st_dev();
+ src_ino = paths[0].metadata()?.st_dev();
let tab_src = TAB_SRC.load(atomic::Ordering::SeqCst);
let tab_dest = context.curr_tab_index;
@@ -212,9 +212,9 @@ impl PasteFiles {
let handle = if dest_ino == src_ino {
- thread::spawn(move || fs_rename_thread(options, tx, destination, s))
+ thread::spawn(move || fs_rename_thread(options, tx, destination, paths))
} else {
- thread::spawn(move || fs_cut_thread(options, tx, destination, s))
+ thread::spawn(move || fs_cut_thread(options, tx, destination, paths))
};
let thread = FileOperationThread {
@@ -226,10 +226,10 @@ impl PasteFiles {
Ok(thread)
}
None => {
- return Err(std::io::Error::new(
+ Err(std::io::Error::new(
std::io::ErrorKind::Other,
"no files selected",
- ));
+ ))
}
}
}
@@ -248,15 +248,15 @@ impl PasteFiles {
let paths = SELECTED_FILES.lock().unwrap().take();
match paths {
- Some(s) => {
- if s.len() == 0 {
+ Some(paths) => {
+ if paths.len() == 0 {
Err(std::io::Error::new(
std::io::ErrorKind::Other,
"no files selected",
))
} else {
let handle =
- thread::spawn(move || fs_copy_thread(options, tx, destination, s));
+ thread::spawn(move || fs_copy_thread(options, tx, destination, paths));
let thread = FileOperationThread {
tab_src,
@@ -378,6 +378,8 @@ fn fs_cut_thread(options: fs_extra::dir::CopyOptions,
std::fs::copy(&path, &destination)?;
std::fs::remove_file(&path)?;
}
+
+ destination.pop();
progress_info.bytes_finished += 1;
match tx.send(progress_info.clone()) {
_ => {}
@@ -399,7 +401,7 @@ fn fs_copy_thread(
let mut destination = dest;
- for path in paths {
+ for path in &paths {
let file_name = path.file_name().unwrap().to_os_string();
if path.symlink_metadata()?.is_dir() {
@@ -449,6 +451,7 @@ fn fs_copy_thread(
}
std::fs::copy(&path, &destination)?;
}
+ destination.pop();
progress_info.bytes_finished += 1;
match tx.send(progress_info.clone()) {
_ => {}
diff --git a/src/commands/rename_file.rs b/src/commands/rename_file.rs
index 844b7f0..2c4ea00 100644
--- a/src/commands/rename_file.rs
+++ b/src/commands/rename_file.rs
@@ -1,7 +1,7 @@
use std::fs;
use std::path;
-use crate::commands::{CursorMove, JoshutoCommand, JoshutoRunnable, Search};
+use crate::commands::{JoshutoCommand, JoshutoRunnable};
use crate::context::JoshutoContext;
use crate::error::JoshutoError;
use crate::preview;
@@ -117,9 +117,6 @@ impl JoshutoRunnable for RenameFile {
if let Some(file_name) = file_name {
if let Some(path) = path {
let res = self.rename_file(&path, context, view, file_name.clone());
- if let Some(index) = Search::search(context.curr_tab_ref(), &file_name) {
- CursorMove::cursor_move(index, context, view);
- }
preview::preview_file(
&mut context.tabs[context.curr_tab_index],
view,
diff --git a/src/commands/selection.rs b/src/commands/selection.rs
index e4237e3..ecc960f 100644
--- a/src/commands/selection.rs
+++ b/src/commands/selection.rs
@@ -39,19 +39,13 @@ impl JoshutoRunnable for SelectFiles {
view: &JoshutoView,
) -> Result<(), JoshutoError> {
if self.toggle && !self.all {
- let mut selected = false;
-
if let Some(s) = context.tabs[context.curr_tab_index].curr_list.as_mut() {
- s.curr_toggle_select();
- selected = true;
- }
- if selected {
- CursorMoveInc::new(1).execute(context, view)
- } else {
- Ok(())
+ if let Some(s) = s.get_curr_mut() {
+ s.selected = !s.selected;
+ return CursorMoveInc::new(1).execute(context, view);
+ }
}
- } else {
- Ok(())
}
+ return Ok(());
}
}