Changed Callback for file transfer; mkdir using path instead of String
This commit is contained in:
parent
4e25e4d7b4
commit
4dc82d2ebb
|
@ -32,7 +32,7 @@ use crate::fs::FsEntry;
|
|||
pub mod sftp_transfer;
|
||||
|
||||
// Types
|
||||
type ProgressCallback = fn(bytes_written: usize, size: usize);
|
||||
pub type ProgressCallback = dyn Fn(usize, usize);
|
||||
|
||||
/// ## FileTransferProtocol
|
||||
///
|
||||
|
@ -125,7 +125,7 @@ pub trait FileTransfer {
|
|||
/// ### mkdir
|
||||
///
|
||||
/// Make directory
|
||||
fn mkdir(&self, dir: String) -> Result<(), FileTransferError>;
|
||||
fn mkdir(&self, dir: &Path) -> Result<(), FileTransferError>;
|
||||
|
||||
/// ### remove
|
||||
///
|
||||
|
@ -142,11 +142,11 @@ pub trait FileTransfer {
|
|||
/// Send file to remote
|
||||
/// File name is referred to the name of the file as it will be saved
|
||||
/// Data contains the file data
|
||||
fn send_file(&self, file_name: &Path, file: &mut File, prog_cb: Option<ProgressCallback>) -> Result<(), FileTransferError>;
|
||||
fn send_file(&self, file_name: &Path, file: &mut File, prog_cb: Option<Box<ProgressCallback>>) -> Result<(), FileTransferError>;
|
||||
|
||||
/// ### recv_file
|
||||
///
|
||||
/// Receive file from remote with provided name
|
||||
fn recv_file(&self, file_name: &Path, dest_file: &mut File, prog_cb: Option<ProgressCallback>) -> Result<(), FileTransferError>;
|
||||
fn recv_file(&self, file_name: &Path, dest_file: &mut File, prog_cb: Option<Box<ProgressCallback>>) -> Result<(), FileTransferError>;
|
||||
|
||||
}
|
||||
|
|
|
@ -313,7 +313,7 @@ impl FileTransfer for SftpFileTransfer {
|
|||
/// ### mkdir
|
||||
///
|
||||
/// Make directory
|
||||
fn mkdir(&self, dir: String) -> Result<(), FileTransferError> {
|
||||
fn mkdir(&self, dir: &Path) -> Result<(), FileTransferError> {
|
||||
match self.sftp.as_ref() {
|
||||
Some(sftp) => {
|
||||
// Make directory
|
||||
|
@ -399,7 +399,7 @@ impl FileTransfer for SftpFileTransfer {
|
|||
&self,
|
||||
file_name: &Path,
|
||||
file: &mut File,
|
||||
prog_cb: Option<ProgressCallback>,
|
||||
prog_cb: Option<Box<ProgressCallback>>,
|
||||
) -> Result<(), FileTransferError> {
|
||||
match self.sftp.as_ref() {
|
||||
None => Err(FileTransferError::UninitializedSession),
|
||||
|
@ -429,7 +429,7 @@ impl FileTransfer for SftpFileTransfer {
|
|||
return Err(FileTransferError::IoErr(err));
|
||||
}
|
||||
// Call callback
|
||||
if let Some(cb) = prog_cb {
|
||||
if let Some(ref cb) = prog_cb {
|
||||
cb(total_bytes_written, file_size);
|
||||
}
|
||||
}
|
||||
|
@ -452,7 +452,7 @@ impl FileTransfer for SftpFileTransfer {
|
|||
&self,
|
||||
file_name: &Path,
|
||||
dest_file: &mut File,
|
||||
prog_cb: Option<ProgressCallback>,
|
||||
prog_cb: Option<Box<ProgressCallback>>,
|
||||
) -> Result<(), FileTransferError> {
|
||||
match self.sftp.as_ref() {
|
||||
None => Err(FileTransferError::UninitializedSession),
|
||||
|
@ -487,7 +487,7 @@ impl FileTransfer for SftpFileTransfer {
|
|||
return Err(FileTransferError::IoErr(err));
|
||||
}
|
||||
// Call callback
|
||||
if let Some(cb) = prog_cb {
|
||||
if let Some(ref cb) = prog_cb {
|
||||
cb(total_bytes_written, file_size);
|
||||
}
|
||||
}
|
||||
|
@ -699,7 +699,7 @@ mod tests {
|
|||
.recv_file(
|
||||
PathBuf::from("readme.txt").as_path(),
|
||||
&mut dst_file_hnd,
|
||||
Some(progress_callback)
|
||||
Some(Box::new(progress_callback))
|
||||
)
|
||||
.is_ok());
|
||||
// Disconnect
|
||||
|
@ -733,7 +733,7 @@ mod tests {
|
|||
.recv_file(
|
||||
PathBuf::from("omar.txt").as_path(),
|
||||
&mut dst_file_hnd,
|
||||
Some(progress_callback)
|
||||
Some(Box::new(progress_callback))
|
||||
)
|
||||
.is_err());
|
||||
// Disconnect
|
||||
|
@ -770,7 +770,7 @@ mod tests {
|
|||
.recv_file(
|
||||
PathBuf::from("readme.txt").as_path(),
|
||||
&mut dst_file_hnd,
|
||||
Some(progress_callback)
|
||||
Some(Box::new(progress_callback))
|
||||
)
|
||||
.is_err());
|
||||
// Disconnect
|
||||
|
|
Loading…
Reference in a new issue