2 Commits

Author SHA1 Message Date
Christian Visintin
75943f2b93 feat: Changed file overwrite behaviour (#366)
Some checks failed
Linux / build (push) Has been cancelled
MacOS / build (push) Has been cancelled
Windows / build (push) Has been cancelled
Now the user can choose for each file whether to overwrite, skip or overwrite all/skip all.

closes #335
2025-11-09 19:00:17 +01:00
veeso
085ab721f9 build: remotefs-ssh 0.7.1
This version fixes compatibility with hosts which don't use bash/sh as the default shell.

closes #365
2025-11-09 17:38:50 +01:00
9 changed files with 222 additions and 260 deletions

View File

@@ -47,13 +47,15 @@
Released on 20/09/2025
- [Issue 331](https://github.com/veeso/termscp/issues/331): Added new `import-ssh-hosts` CLI subcommand to import all the hosts from the ssh config as bookmarks.
- [Issue 335](https://github.com/veeso/termscp/issues/335): Changed file overwrite behaviour
- Now the user can choose for each file whether to overwrite, skip or overwrite all/skip all.
- [Issue 354](https://github.com/veeso/termscp/issues/354):
- Removed error popup message if failed to check for updates.
- Prevent long timeouts when checking for updates if the network is down or the DNS is not working.
- [Issue 356](https://github.com/veeso/termscp/issues/356): Fixed SSH auth issue not trying with the password if any RSA key was found.
- [Issue 334](https://github.com/veeso/termscp/issues/334): SMB support for MacOS with vendored build of libsmbclient.
- [Issue 337](https://github.com/veeso/termscp/issues/337): Migrated to libssh.org on Linux and MacOS for better ssh agent support.
- [Issue 361](https://github.com/veeso/termscp/issues/361): Report a message while calculating total size of files to transfer.
- [Issue 354](https://github.com/veeso/termscp/issues/354):
- Removed error popup message if failed to check for updates.
- Prevent long timeouts when checking for updates if the network is down or the DNS is not working.
## 0.18.0

8
Cargo.lock generated
View File

@@ -1272,7 +1272,7 @@ dependencies = [
"libc",
"option-ext",
"redox_users",
"windows-sys 0.60.2",
"windows-sys 0.59.0",
]
[[package]]
@@ -2032,7 +2032,7 @@ dependencies = [
"js-sys",
"log",
"wasm-bindgen",
"windows-core 0.57.0",
"windows-core 0.61.2",
]
[[package]]
@@ -3553,9 +3553,9 @@ dependencies = [
[[package]]
name = "remotefs-ssh"
version = "0.7.0"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d29de4702886ae0e4433904d4f6f9b2ed2961d31d76a7e7bef58305097238eb6"
checksum = "5ca8b65fbd60801ac03973a41196b030fb04d1ce1af33d3c58c5bad94d46eb27"
dependencies = [
"chrono",
"lazy-regex",

View File

@@ -99,24 +99,16 @@ impl FileTransferActivity {
// Iter files
match self.browser.tab() {
FileExplorerTab::FindHostBridge | FileExplorerTab::HostBridge => {
if self.config().get_prompt_on_file_replace() {
// Check which file would be replaced
let existing_files: Vec<&File> = entries
.iter()
.filter(|(x, dest_path)| {
self.remote_file_exists(
Self::file_to_check_many(x, dest_path.as_path()).as_path(),
let super::save::TransferFilesWithOverwritesResult::FilesToTransfer(
entries,
) = self.get_files_to_transfer_with_overwrites(
entries,
super::save::CheckFileExists::Remote,
)
})
.map(|(x, _)| x)
.collect();
// Check whether to replace files
if !existing_files.is_empty()
&& !self.should_replace_files(existing_files)
{
else {
debug!("User cancelled file transfer due to overwrites");
return;
}
}
};
if let Err(err) = self.filetransfer_send(
TransferPayload::TransferQueue(entries),
dest_path.as_path(),
@@ -131,24 +123,16 @@ impl FileTransferActivity {
}
}
FileExplorerTab::FindRemote | FileExplorerTab::Remote => {
if self.config().get_prompt_on_file_replace() {
// Check which file would be replaced
let existing_files: Vec<&File> = entries
.iter()
.filter(|(x, dest_path)| {
self.host_bridge_file_exists(
Self::file_to_check_many(x, dest_path.as_path()).as_path(),
let super::save::TransferFilesWithOverwritesResult::FilesToTransfer(
entries,
) = self.get_files_to_transfer_with_overwrites(
entries,
super::save::CheckFileExists::HostBridge,
)
})
.map(|(x, _)| x)
.collect();
// Check whether to replace files
if !existing_files.is_empty()
&& !self.should_replace_files(existing_files)
{
else {
debug!("User cancelled file transfer due to overwrites");
return;
}
}
};
if let Err(err) = self.filetransfer_recv(
TransferPayload::TransferQueue(entries),
dest_path.as_path(),

View File

@@ -10,6 +10,37 @@ use super::{
TransferPayload,
};
enum GetFileToReplaceResult {
Replace(Vec<(File, PathBuf)>),
Cancel,
}
/// Result of getting files to transfer with overwrites.
///
/// - FilesToTransfer: files to transfer.
/// - Cancel: user cancelled the operation.
pub(crate) enum TransferFilesWithOverwritesResult {
FilesToTransfer(Vec<(File, PathBuf)>),
Cancel,
}
/// Decides whether to check file existence on host bridge or remote side.
pub(crate) enum CheckFileExists {
HostBridge,
Remote,
}
/// Options for all files replacement.
///
/// - ReplaceAll: user wants to replace all files.
/// - SkipAll: user wants to skip all files.
/// - Unset: no option set yet.
enum AllOpts {
ReplaceAll,
SkipAll,
Unset,
}
impl FileTransferActivity {
pub(crate) fn action_local_saveas(&mut self, input: String) {
self.local_send_file(TransferOpts::default().save_as(Some(input)));
@@ -60,22 +91,12 @@ impl FileTransferActivity {
dest_path.push(save_as);
}
// Iter files
if self.config().get_prompt_on_file_replace() {
// Check which file would be replaced
let existing_files: Vec<&File> = entries
.iter()
.filter(|(x, dest_path)| {
self.remote_file_exists(
Self::file_to_check_many(x, dest_path.as_path()).as_path(),
)
})
.map(|(x, _)| x)
.collect();
// Check whether to replace files
if !existing_files.is_empty() && !self.should_replace_files(existing_files) {
let TransferFilesWithOverwritesResult::FilesToTransfer(entries) =
self.get_files_to_transfer_with_overwrites(entries, CheckFileExists::Remote)
else {
debug!("User cancelled file transfer due to overwrites");
return;
}
}
};
if let Err(err) = self.filetransfer_send(
TransferPayload::TransferQueue(entries),
dest_path.as_path(),
@@ -128,23 +149,13 @@ impl FileTransferActivity {
if let Some(save_as) = opts.save_as {
dest_path.push(save_as);
}
// Iter files
if self.config().get_prompt_on_file_replace() {
// Check which file would be replaced
let existing_files: Vec<&File> = entries
.iter()
.filter(|(x, dest_path)| {
self.host_bridge_file_exists(
Self::file_to_check_many(x, dest_path.as_path()).as_path(),
)
})
.map(|(x, _)| x)
.collect();
// Check whether to replace files
if !existing_files.is_empty() && !self.should_replace_files(existing_files) {
let TransferFilesWithOverwritesResult::FilesToTransfer(entries) = self
.get_files_to_transfer_with_overwrites(entries, CheckFileExists::HostBridge)
else {
debug!("User cancelled file transfer due to overwrites");
return;
}
}
};
if let Err(err) = self.filetransfer_recv(
TransferPayload::TransferQueue(entries),
dest_path.as_path(),
@@ -172,11 +183,17 @@ impl FileTransferActivity {
self.mount_radio_replace(&file_name);
// Wait for answer
trace!("Asking user whether he wants to replace file {}", file_name);
if self.wait_for_pending_msg(&[
Msg::PendingAction(PendingActionMsg::CloseReplacePopups),
Msg::PendingAction(PendingActionMsg::TransferPendingFile),
]) == Msg::PendingAction(PendingActionMsg::TransferPendingFile)
{
if matches!(
self.wait_for_pending_msg(&[
Msg::PendingAction(PendingActionMsg::ReplaceCancel),
Msg::PendingAction(PendingActionMsg::ReplaceOverwrite),
Msg::PendingAction(PendingActionMsg::ReplaceSkip),
Msg::PendingAction(PendingActionMsg::ReplaceSkipAll),
Msg::PendingAction(PendingActionMsg::ReplaceOverwriteAll),
]),
Msg::PendingAction(PendingActionMsg::ReplaceOverwrite)
| Msg::PendingAction(PendingActionMsg::ReplaceOverwriteAll)
) {
trace!("User wants to replace file");
self.umount_radio_replace();
true
@@ -187,28 +204,76 @@ impl FileTransferActivity {
}
}
/// Set pending transfer for many files into storage and mount radio
pub(crate) fn should_replace_files(&mut self, files: Vec<&File>) -> bool {
let file_names: Vec<String> = files.iter().map(|x| x.name()).collect();
self.mount_radio_replace_many(file_names.as_slice());
// Wait for answer
/// Get files to replace
fn get_files_to_replace(&mut self, files: Vec<(File, PathBuf)>) -> GetFileToReplaceResult {
// keep only files the user want to replace
let mut files_to_replace = vec![];
let mut all_opts = AllOpts::Unset;
for (file, p) in files {
// Check for all opts
match all_opts {
AllOpts::ReplaceAll => {
trace!(
"Asking user whether he wants to replace files {:?}",
file_names
"User wants to replace all files, including file {}",
file.name()
);
if self.wait_for_pending_msg(&[
Msg::PendingAction(PendingActionMsg::CloseReplacePopups),
Msg::PendingAction(PendingActionMsg::TransferPendingFile),
]) == Msg::PendingAction(PendingActionMsg::TransferPendingFile)
{
trace!("User wants to replace files");
self.umount_radio_replace();
true
} else {
trace!("The user doesn't want replace file");
self.umount_radio_replace();
false
files_to_replace.push((file, p));
continue;
}
AllOpts::SkipAll => {
trace!(
"User wants to skip all files, including file {}",
file.name()
);
continue;
}
AllOpts::Unset => {}
}
let file_name = file.name();
self.mount_radio_replace(&file_name);
// Wait for answer
match self.wait_for_pending_msg(&[
Msg::PendingAction(PendingActionMsg::ReplaceCancel),
Msg::PendingAction(PendingActionMsg::ReplaceOverwrite),
Msg::PendingAction(PendingActionMsg::ReplaceSkip),
Msg::PendingAction(PendingActionMsg::ReplaceSkipAll),
Msg::PendingAction(PendingActionMsg::ReplaceOverwriteAll),
]) {
Msg::PendingAction(PendingActionMsg::ReplaceCancel) => {
trace!("The user cancelled the replace operation");
self.umount_radio_replace();
return GetFileToReplaceResult::Cancel;
}
Msg::PendingAction(PendingActionMsg::ReplaceOverwrite) => {
trace!("User wants to replace file {}", file_name);
files_to_replace.push((file, p));
}
Msg::PendingAction(PendingActionMsg::ReplaceOverwriteAll) => {
trace!(
"User wants to replace all files from now on, including file {}",
file_name
);
files_to_replace.push((file, p));
all_opts = AllOpts::ReplaceAll;
}
Msg::PendingAction(PendingActionMsg::ReplaceSkip) => {
trace!("The user skipped file {}", file_name);
}
Msg::PendingAction(PendingActionMsg::ReplaceSkipAll) => {
trace!(
"The user skipped all files from now on, including file {}",
file_name
);
all_opts = AllOpts::SkipAll;
}
_ => {}
}
self.umount_radio_replace();
}
GetFileToReplaceResult::Replace(files_to_replace)
}
/// Get file to check for path
@@ -224,4 +289,40 @@ impl FileTransferActivity {
p.push(e.name());
p
}
/// Get the files to transfer with overwrites.
///
/// Existing and unexisting files are splitted, and only existing files are prompted for replacement.
pub(crate) fn get_files_to_transfer_with_overwrites(
&mut self,
files: Vec<(File, PathBuf)>,
file_exists: CheckFileExists,
) -> TransferFilesWithOverwritesResult {
if !self.config().get_prompt_on_file_replace() {
return TransferFilesWithOverwritesResult::FilesToTransfer(files);
}
// unzip between existing and non-existing files
let (existing_files, new_files): (Vec<_>, Vec<_>) =
files.into_iter().partition(|(x, dest_path)| {
let p = Self::file_to_check_many(x, dest_path);
match file_exists {
CheckFileExists::Remote => self.remote_file_exists(p.as_path()),
CheckFileExists::HostBridge => self.host_bridge_file_exists(p.as_path()),
}
});
// filter only files to replace
let existing_files = match self.get_files_to_replace(existing_files) {
GetFileToReplaceResult::Replace(files) => files,
GetFileToReplaceResult::Cancel => {
return TransferFilesWithOverwritesResult::Cancel;
}
};
// merge back
TransferFilesWithOverwritesResult::FilesToTransfer(
existing_files.into_iter().chain(new_files).collect(),
)
}
}

View File

@@ -21,9 +21,8 @@ pub use popups::{
ATTR_FILES, ChmodPopup, CopyPopup, DeletePopup, DisconnectPopup, ErrorPopup, FatalPopup,
FileInfoPopup, FilterPopup, GotoPopup, KeybindingsPopup, MkdirPopup, NewfilePopup,
OpenWithPopup, ProgressBarFull, ProgressBarPartial, QuitPopup, RenamePopup, ReplacePopup,
ReplacingFilesListPopup, SaveAsPopup, SortingPopup, StatusBarLocal, StatusBarRemote,
SymlinkPopup, SyncBrowsingMkdirPopup, WaitPopup, WalkdirWaitPopup, WatchedPathsList,
WatcherPopup,
SaveAsPopup, SortingPopup, StatusBarLocal, StatusBarRemote, SymlinkPopup,
SyncBrowsingMkdirPopup, WaitPopup, WalkdirWaitPopup, WatchedPathsList, WatcherPopup,
};
pub use transfer::{ExplorerFind, ExplorerFuzzy, ExplorerLocal, ExplorerRemote};

View File

@@ -1196,7 +1196,7 @@ impl ReplacePopup {
.modifiers(BorderType::Rounded),
)
.foreground(color)
.choices(["Yes", "No"])
.choices(["Replace", "Skip", "Replace All", "Skip All", "Cancel"])
.title(text, Alignment::Center),
}
}
@@ -1205,9 +1205,6 @@ impl ReplacePopup {
impl Component<Msg, NoUserEvent> for ReplacePopup {
fn on(&mut self, ev: Event<NoUserEvent>) -> Option<Msg> {
match ev {
Event::Keyboard(KeyEvent { code: Key::Tab, .. }) => {
Some(Msg::Ui(UiMsg::ReplacePopupTabbed))
}
Event::Keyboard(KeyEvent {
code: Key::Left, ..
}) => {
@@ -1221,102 +1218,36 @@ impl Component<Msg, NoUserEvent> for ReplacePopup {
Some(Msg::None)
}
Event::Keyboard(KeyEvent { code: Key::Esc, .. }) => {
Some(Msg::PendingAction(PendingActionMsg::CloseReplacePopups))
Some(Msg::PendingAction(PendingActionMsg::ReplaceCancel))
}
Event::Keyboard(KeyEvent {
code: Key::Char('y'),
modifiers: KeyModifiers::NONE,
}) => Some(Msg::PendingAction(PendingActionMsg::TransferPendingFile)),
}) => Some(Msg::PendingAction(PendingActionMsg::ReplaceOverwrite)),
Event::Keyboard(KeyEvent {
code: Key::Char('n'),
modifiers: KeyModifiers::NONE,
}) => Some(Msg::PendingAction(PendingActionMsg::CloseReplacePopups)),
}) => Some(Msg::PendingAction(PendingActionMsg::ReplaceSkip)),
Event::Keyboard(KeyEvent {
code: Key::Enter, ..
}) => {
if matches!(
self.perform(Cmd::Submit),
CmdResult::Submit(State::One(StateValue::Usize(0)))
) {
Some(Msg::PendingAction(PendingActionMsg::TransferPendingFile))
} else {
Some(Msg::PendingAction(PendingActionMsg::CloseReplacePopups))
}) => match self.perform(Cmd::Submit) {
CmdResult::Submit(State::One(StateValue::Usize(0))) => {
Some(Msg::PendingAction(PendingActionMsg::ReplaceOverwrite))
}
CmdResult::Submit(State::One(StateValue::Usize(1))) => {
Some(Msg::PendingAction(PendingActionMsg::ReplaceSkip))
}
_ => None,
CmdResult::Submit(State::One(StateValue::Usize(2))) => {
Some(Msg::PendingAction(PendingActionMsg::ReplaceOverwriteAll))
}
CmdResult::Submit(State::One(StateValue::Usize(3))) => {
Some(Msg::PendingAction(PendingActionMsg::ReplaceSkipAll))
}
CmdResult::Submit(State::One(StateValue::Usize(4))) => {
Some(Msg::PendingAction(PendingActionMsg::ReplaceCancel))
}
#[derive(MockComponent)]
pub struct ReplacingFilesListPopup {
component: List,
}
impl ReplacingFilesListPopup {
pub fn new(files: &[String], color: Color) -> Self {
Self {
component: List::default()
.borders(
Borders::default()
.color(color)
.modifiers(BorderType::Rounded),
)
.scroll(true)
.step(4)
.highlighted_color(color)
.highlighted_str("")
.title(
"The following files are going to be replaced",
Alignment::Center,
)
.rows(files.iter().map(|x| vec![TextSpan::from(x)]).collect()),
}
}
}
impl Component<Msg, NoUserEvent> for ReplacingFilesListPopup {
fn on(&mut self, ev: Event<NoUserEvent>) -> Option<Msg> {
match ev {
Event::Keyboard(KeyEvent { code: Key::Esc, .. }) => {
Some(Msg::PendingAction(PendingActionMsg::CloseReplacePopups))
}
Event::Keyboard(KeyEvent { code: Key::Tab, .. }) => {
Some(Msg::Ui(UiMsg::ReplacePopupTabbed))
}
Event::Keyboard(KeyEvent {
code: Key::Down, ..
}) => {
self.perform(Cmd::Move(Direction::Down));
Some(Msg::None)
}
Event::Keyboard(KeyEvent { code: Key::Up, .. }) => {
self.perform(Cmd::Move(Direction::Up));
Some(Msg::None)
}
Event::Keyboard(KeyEvent {
code: Key::PageDown,
..
}) => {
self.perform(Cmd::Scroll(Direction::Down));
Some(Msg::None)
}
Event::Keyboard(KeyEvent {
code: Key::PageUp, ..
}) => {
self.perform(Cmd::Scroll(Direction::Up));
Some(Msg::None)
}
Event::Keyboard(KeyEvent {
code: Key::Home, ..
}) => {
self.perform(Cmd::GoTo(Position::Begin));
Some(Msg::None)
}
Event::Keyboard(KeyEvent { code: Key::End, .. }) => {
self.perform(Cmd::GoTo(Position::End));
Some(Msg::None)
}
_ => Some(Msg::None),
},
_ => None,
}
}

View File

@@ -72,7 +72,6 @@ enum Id {
QuitPopup,
RenamePopup,
ReplacePopup,
ReplacingFilesListPopup,
SaveAsPopup,
SortingPopup,
StatusBarHostBridge,
@@ -98,10 +97,14 @@ enum Msg {
#[derive(Debug, PartialEq)]
enum PendingActionMsg {
CloseReplacePopups,
CloseSyncBrowsingMkdirPopup,
MakePendingDirectory,
TransferPendingFile,
/// Replace file popup
ReplaceCancel,
ReplaceOverwrite,
ReplaceOverwriteAll,
ReplaceSkip,
ReplaceSkipAll,
}
#[derive(Debug, PartialEq)]
@@ -171,8 +174,8 @@ enum UiMsg {
MarkAll,
/// Clear all marks
MarkClear,
Quit,
ReplacePopupTabbed,
ShowChmodPopup,
ShowCopyPopup,
ShowDeletePopup,

View File

@@ -5,7 +5,6 @@
// locals
// externals
use remotefs::fs::File;
use tuirealm::props::{AttrValue, Attribute};
use tuirealm::{State, StateValue, Update};
use super::actions::SelectedFile;
@@ -504,15 +503,6 @@ impl FileTransferActivity {
self.disconnect_and_quit();
self.umount_quit();
}
UiMsg::ReplacePopupTabbed => {
if let Ok(Some(AttrValue::Flag(true))) =
self.app.query(&Id::ReplacePopup, Attribute::Focus)
{
assert!(self.app.active(&Id::ReplacingFilesListPopup).is_ok());
} else {
assert!(self.app.active(&Id::ReplacePopup).is_ok());
}
}
UiMsg::ShowChmodPopup => {
let selected_file = match self.browser.tab() {
#[cfg(posix)]

View File

@@ -269,29 +269,10 @@ impl FileTransferActivity {
// make popup
self.app.view(&Id::DeletePopup, f, popup);
} else if self.app.mounted(&Id::ReplacePopup) {
// NOTE: handle extended / normal modes
if self.is_radio_replace_extended() {
let popup = Popup(Size::Percentage(50), Size::Percentage(50)).draw_in(f.area());
f.render_widget(Clear, popup);
let popup_chunks = Layout::default()
.direction(Direction::Vertical)
.constraints(
[
Constraint::Percentage(85), // List
Constraint::Percentage(15), // Radio
]
.as_ref(),
)
.split(popup);
self.app
.view(&Id::ReplacingFilesListPopup, f, popup_chunks[0]);
self.app.view(&Id::ReplacePopup, f, popup_chunks[1]);
} else {
let popup = Popup(Size::Percentage(50), Size::Unit(3)).draw_in(f.area());
f.render_widget(Clear, popup);
// make popup
self.app.view(&Id::ReplacePopup, f, popup);
}
} else if self.app.mounted(&Id::DisconnectPopup) {
let popup = Popup(Size::Percentage(30), Size::Unit(3)).draw_in(f.area());
f.render_widget(Clear, popup);
@@ -944,37 +925,8 @@ impl FileTransferActivity {
assert!(self.app.active(&Id::ReplacePopup).is_ok());
}
pub(super) fn mount_radio_replace_many(&mut self, files: &[String]) {
let warn_color = self.theme().misc_warn_dialog;
assert!(
self.app
.remount(
Id::ReplacingFilesListPopup,
Box::new(components::ReplacingFilesListPopup::new(files, warn_color)),
vec![],
)
.is_ok()
);
assert!(
self.app
.remount(
Id::ReplacePopup,
Box::new(components::ReplacePopup::new(None, warn_color)),
vec![],
)
.is_ok()
);
assert!(self.app.active(&Id::ReplacePopup).is_ok());
}
/// Returns whether radio replace is in "extended" mode (for many files)
pub(super) fn is_radio_replace_extended(&self) -> bool {
self.app.mounted(&Id::ReplacingFilesListPopup)
}
pub(super) fn umount_radio_replace(&mut self) {
let _ = self.app.umount(&Id::ReplacePopup);
let _ = self.app.umount(&Id::ReplacingFilesListPopup); // NOTE: replace anyway
}
pub(super) fn mount_file_info(&mut self, file: &File) {