mirror of
https://github.com/veeso/termscp.git
synced 2025-12-07 09:36:00 -08:00
Wait, file_size in recv is completely useless
This commit is contained in:
@@ -196,5 +196,5 @@ pub trait FileTransfer {
|
|||||||
///
|
///
|
||||||
/// Receive file from remote with provided name
|
/// Receive file from remote with provided name
|
||||||
/// Returns file and its size
|
/// Returns file and its size
|
||||||
fn recv_file(&self, file_name: &Path) -> Result<(Box<dyn Read>, usize), FileTransferError>;
|
fn recv_file(&self, file_name: &Path) -> Result<Box<dyn Read>, FileTransferError>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ use crate::fs::{FsDirectory, FsEntry, FsFile};
|
|||||||
|
|
||||||
// Includes
|
// Includes
|
||||||
use ssh2::{FileStat, Session, Sftp};
|
use ssh2::{FileStat, Session, Sftp};
|
||||||
use std::io::{Read, Seek, Write};
|
use std::io::{Read, Write};
|
||||||
use std::net::TcpStream;
|
use std::net::TcpStream;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::time::{Duration, SystemTime};
|
use std::time::{Duration, SystemTime};
|
||||||
@@ -433,7 +433,7 @@ impl FileTransfer for SftpFileTransfer {
|
|||||||
/// ### recv_file
|
/// ### recv_file
|
||||||
///
|
///
|
||||||
/// Receive file from remote with provided name
|
/// Receive file from remote with provided name
|
||||||
fn recv_file(&self, file_name: &Path) -> Result<(Box<dyn Read>, usize), FileTransferError> {
|
fn recv_file(&self, file_name: &Path) -> Result<Box<dyn Read>, FileTransferError> {
|
||||||
match self.sftp.as_ref() {
|
match self.sftp.as_ref() {
|
||||||
None => Err(FileTransferError::new(FileTransferErrorType::UninitializedSession)),
|
None => Err(FileTransferError::new(FileTransferErrorType::UninitializedSession)),
|
||||||
Some(sftp) => {
|
Some(sftp) => {
|
||||||
@@ -444,15 +444,7 @@ impl FileTransfer for SftpFileTransfer {
|
|||||||
};
|
};
|
||||||
// Open remote file
|
// Open remote file
|
||||||
match sftp.open(remote_path.as_path()) {
|
match sftp.open(remote_path.as_path()) {
|
||||||
Ok(mut file) => {
|
Ok(file) => Ok(Box::new(file)),
|
||||||
let file_size: usize =
|
|
||||||
file.seek(std::io::SeekFrom::End(0)).unwrap_or(0) as usize;
|
|
||||||
// rewind
|
|
||||||
if let Err(err) = file.seek(std::io::SeekFrom::Start(0)) {
|
|
||||||
return Err(FileTransferError::new(FileTransferErrorType::IoErr(err)));
|
|
||||||
}
|
|
||||||
Ok((Box::new(file), file_size))
|
|
||||||
}
|
|
||||||
Err(err) => Err(FileTransferError::new_ex(FileTransferErrorType::NoSuchFileOrDirectory, format!("{}", err))),
|
Err(err) => Err(FileTransferError::new_ex(FileTransferErrorType::NoSuchFileOrDirectory, format!("{}", err))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -299,7 +299,7 @@ impl FileTransferActivity {
|
|||||||
Ok(mut local_file) => {
|
Ok(mut local_file) => {
|
||||||
// Download file from remote
|
// Download file from remote
|
||||||
match self.client.recv_file(file.abs_path.as_path()) {
|
match self.client.recv_file(file.abs_path.as_path()) {
|
||||||
Ok((mut rhnd, file_size)) => {
|
Ok(mut rhnd) => {
|
||||||
// Set popup progress
|
// Set popup progress
|
||||||
self.input_mode = InputMode::Popup(PopupType::Progress(format!(
|
self.input_mode = InputMode::Popup(PopupType::Progress(format!(
|
||||||
"Downloading \"{}\"...",
|
"Downloading \"{}\"...",
|
||||||
@@ -340,7 +340,7 @@ impl FileTransferActivity {
|
|||||||
),
|
),
|
||||||
}
|
}
|
||||||
// Set progress
|
// Set progress
|
||||||
self.set_progress(total_bytes_written, file_size);
|
self.set_progress(total_bytes_written, file.size);
|
||||||
// Draw only if a significant progress has been made (performance improvement)
|
// Draw only if a significant progress has been made (performance improvement)
|
||||||
if last_progress_val + 0.5 >= self.transfer_progress {
|
if last_progress_val + 0.5 >= self.transfer_progress {
|
||||||
// Draw
|
// Draw
|
||||||
|
|||||||
Reference in New Issue
Block a user