mirror of
https://github.com/veeso/termscp.git
synced 2025-12-07 09:36:00 -08:00
If transfer error reason is Abrupted or IO, then stat created file and remove it
This commit is contained in:
@@ -52,16 +52,16 @@ use thiserror::Error;
|
|||||||
/// Describes the reason that caused an error during a file transfer
|
/// Describes the reason that caused an error during a file transfer
|
||||||
#[derive(Error, Debug)]
|
#[derive(Error, Debug)]
|
||||||
enum TransferErrorReason {
|
enum TransferErrorReason {
|
||||||
#[error("Abrupted")]
|
#[error("File transfer aborted")]
|
||||||
Abrupted,
|
Abrupted,
|
||||||
#[error("Failed to seek file: {0}")]
|
#[error("Failed to seek file: {0}")]
|
||||||
CouldNotRewind(std::io::Error),
|
CouldNotRewind(std::io::Error),
|
||||||
#[error("I/O error on localhost: {0}")]
|
#[error("I/O error on localhost: {0}")]
|
||||||
LocalIOError(std::io::Error),
|
LocalIoError(std::io::Error),
|
||||||
#[error("Host error: {0}")]
|
#[error("Host error: {0}")]
|
||||||
HostError(HostError),
|
HostError(HostError),
|
||||||
#[error("I/O error on remote: {0}")]
|
#[error("I/O error on remote: {0}")]
|
||||||
RemoteIOError(std::io::Error),
|
RemoteIoError(std::io::Error),
|
||||||
#[error("File transfer error: {0}")]
|
#[error("File transfer error: {0}")]
|
||||||
FileTransferError(FileTransferError),
|
FileTransferError(FileTransferError),
|
||||||
}
|
}
|
||||||
@@ -182,9 +182,33 @@ impl FileTransferActivity {
|
|||||||
// If transfer was abrupted or there was an IO error on remote, remove file
|
// If transfer was abrupted or there was an IO error on remote, remove file
|
||||||
if matches!(
|
if matches!(
|
||||||
err,
|
err,
|
||||||
TransferErrorReason::Abrupted | TransferErrorReason::RemoteIOError(_)
|
TransferErrorReason::Abrupted | TransferErrorReason::RemoteIoError(_)
|
||||||
) {
|
) {
|
||||||
// TODO: make dummy fs entry
|
// Stat file on remote and remove it if exists
|
||||||
|
match self.client.stat(remote_path.as_path()) {
|
||||||
|
Err(err) => self.log(
|
||||||
|
LogLevel::Error,
|
||||||
|
format!(
|
||||||
|
"Could not remove created file {}: {}",
|
||||||
|
remote_path.display(),
|
||||||
|
err
|
||||||
|
)
|
||||||
|
.as_str(),
|
||||||
|
),
|
||||||
|
Ok(entry) => {
|
||||||
|
if let Err(err) = self.client.remove(&entry) {
|
||||||
|
self.log(
|
||||||
|
LogLevel::Error,
|
||||||
|
format!(
|
||||||
|
"Could not remove created file {}: {}",
|
||||||
|
remote_path.display(),
|
||||||
|
err
|
||||||
|
)
|
||||||
|
.as_str(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -293,7 +317,38 @@ impl FileTransferActivity {
|
|||||||
LogLevel::Error,
|
LogLevel::Error,
|
||||||
format!("Could not download file {}: {}", file.name, err),
|
format!("Could not download file {}: {}", file.name, err),
|
||||||
);
|
);
|
||||||
// TODO: delete file
|
// If transfer was abrupted or there was an IO error on remote, remove file
|
||||||
|
if matches!(
|
||||||
|
err,
|
||||||
|
TransferErrorReason::Abrupted | TransferErrorReason::LocalIoError(_)
|
||||||
|
) {
|
||||||
|
let local = &mut self.context.as_mut().unwrap().local;
|
||||||
|
// Stat file
|
||||||
|
match local.stat(local_file_path.as_path()) {
|
||||||
|
Err(err) => self.log(
|
||||||
|
LogLevel::Error,
|
||||||
|
format!(
|
||||||
|
"Could not remove created file {}: {}",
|
||||||
|
local_file_path.display(),
|
||||||
|
err
|
||||||
|
)
|
||||||
|
.as_str(),
|
||||||
|
),
|
||||||
|
Ok(entry) => {
|
||||||
|
if let Err(err) = local.remove(&entry) {
|
||||||
|
self.log(
|
||||||
|
LogLevel::Error,
|
||||||
|
format!(
|
||||||
|
"Could not remove created file {}: {}",
|
||||||
|
local_file_path.display(),
|
||||||
|
err
|
||||||
|
)
|
||||||
|
.as_str(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FsEntry::Directory(dir) => {
|
FsEntry::Directory(dir) => {
|
||||||
@@ -460,7 +515,7 @@ impl FileTransferActivity {
|
|||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
self.umount_progress_bar();
|
self.umount_progress_bar();
|
||||||
return Err(TransferErrorReason::RemoteIOError(
|
return Err(TransferErrorReason::RemoteIoError(
|
||||||
err,
|
err,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@@ -470,7 +525,7 @@ impl FileTransferActivity {
|
|||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
self.umount_progress_bar();
|
self.umount_progress_bar();
|
||||||
return Err(TransferErrorReason::LocalIOError(err));
|
return Err(TransferErrorReason::LocalIoError(err));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Increase progress
|
// Increase progress
|
||||||
@@ -563,7 +618,7 @@ impl FileTransferActivity {
|
|||||||
Ok(bytes) => buf_start += bytes,
|
Ok(bytes) => buf_start += bytes,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
self.umount_progress_bar();
|
self.umount_progress_bar();
|
||||||
return Err(TransferErrorReason::LocalIOError(
|
return Err(TransferErrorReason::LocalIoError(
|
||||||
err,
|
err,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@@ -573,7 +628,7 @@ impl FileTransferActivity {
|
|||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
self.umount_progress_bar();
|
self.umount_progress_bar();
|
||||||
return Err(TransferErrorReason::RemoteIOError(err));
|
return Err(TransferErrorReason::RemoteIoError(err));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Set progress
|
// Set progress
|
||||||
|
|||||||
Reference in New Issue
Block a user