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
|
||||
/// 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
|
||||
use ssh2::{FileStat, Session, Sftp};
|
||||
use std::io::{Read, Seek, Write};
|
||||
use std::io::{Read, Write};
|
||||
use std::net::TcpStream;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::time::{Duration, SystemTime};
|
||||
@@ -433,7 +433,7 @@ impl FileTransfer for SftpFileTransfer {
|
||||
/// ### recv_file
|
||||
///
|
||||
/// 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() {
|
||||
None => Err(FileTransferError::new(FileTransferErrorType::UninitializedSession)),
|
||||
Some(sftp) => {
|
||||
@@ -444,15 +444,7 @@ impl FileTransfer for SftpFileTransfer {
|
||||
};
|
||||
// Open remote file
|
||||
match sftp.open(remote_path.as_path()) {
|
||||
Ok(mut 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))
|
||||
}
|
||||
Ok(file) => Ok(Box::new(file)),
|
||||
Err(err) => Err(FileTransferError::new_ex(FileTransferErrorType::NoSuchFileOrDirectory, format!("{}", err))),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -299,7 +299,7 @@ impl FileTransferActivity {
|
||||
Ok(mut local_file) => {
|
||||
// Download file from remote
|
||||
match self.client.recv_file(file.abs_path.as_path()) {
|
||||
Ok((mut rhnd, file_size)) => {
|
||||
Ok(mut rhnd) => {
|
||||
// Set popup progress
|
||||
self.input_mode = InputMode::Popup(PopupType::Progress(format!(
|
||||
"Downloading \"{}\"...",
|
||||
@@ -340,7 +340,7 @@ impl FileTransferActivity {
|
||||
),
|
||||
}
|
||||
// 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)
|
||||
if last_progress_val + 0.5 >= self.transfer_progress {
|
||||
// Draw
|
||||
|
||||
Reference in New Issue
Block a user