Fixed recursive recv from remote

This commit is contained in:
ChristianVisintin
2020-11-29 20:52:30 +01:00
parent 9b135200d7
commit f48fdc48dd

View File

@@ -297,7 +297,7 @@ impl FileTransferActivity {
/// Send fs entry to remote. /// Send fs entry to remote.
/// If dst_name is Some, entry will be saved with a different name. /// If dst_name is Some, entry will be saved with a different name.
/// If entry is a directory, this applies to directory only /// If entry is a directory, this applies to directory only
fn filetransfer_send(&mut self, entry: &FsEntry, dst_name: Option<String>) { fn filetransfer_send(&mut self, entry: &FsEntry, curr_remote_path: &Path, dst_name: Option<String>) {
// Write popup // Write popup
let file_name: String = match entry { let file_name: String = match entry {
FsEntry::Directory(dir) => dir.name.clone(), FsEntry::Directory(dir) => dir.name.clone(),
@@ -307,10 +307,12 @@ impl FileTransferActivity {
// Draw // Draw
self.draw(); self.draw();
// Get remote path // Get remote path
let remote_path: PathBuf = match dst_name { let mut remote_path: PathBuf = PathBuf::from(curr_remote_path);
let remote_file_name: PathBuf = match dst_name {
Some(s) => PathBuf::from(s.as_str()), Some(s) => PathBuf::from(s.as_str()),
None => PathBuf::from(file_name.as_str()), None => PathBuf::from(file_name.as_str()),
}; };
remote_path.push(remote_file_name);
// Match entry // Match entry
match entry { match entry {
FsEntry::File(file) => { FsEntry::File(file) => {
@@ -409,11 +411,11 @@ impl FileTransferActivity {
} }
FsEntry::Directory(dir) => { FsEntry::Directory(dir) => {
// Create directory on remote // Create directory on remote
match self.client.mkdir(dir.abs_path.as_path()) { match self.client.mkdir(remote_path.as_path()) {
Ok(_) => { Ok(_) => {
self.log( self.log(
LogLevel::Info, LogLevel::Info,
format!("Created directory \"{}\"", dir.abs_path.display()).as_ref(), format!("Created directory \"{}\"", remote_path.display()).as_ref(),
); );
// Get files in dir // Get files in dir
match self match self
@@ -427,7 +429,7 @@ impl FileTransferActivity {
// Iterate over files // Iterate over files
for entry in entries.iter() { for entry in entries.iter() {
// Send entry; name is always None after first call // Send entry; name is always None after first call
self.filetransfer_send(&entry, None); self.filetransfer_send(&entry, remote_path.as_path(), None);
} }
} }
Err(err) => self.log( Err(err) => self.log(
@@ -445,7 +447,7 @@ impl FileTransferActivity {
LogLevel::Error, LogLevel::Error,
format!( format!(
"Failed to create directory \"{}\": {}", "Failed to create directory \"{}\": {}",
dir.abs_path.display(), remote_path.display(),
err err
) )
.as_ref(), .as_ref(),
@@ -936,12 +938,20 @@ impl FileTransferActivity {
} }
} }
' ' => { ' ' => {
// Get pwd
let wrkdir: PathBuf = match self.client.pwd() {
Ok(p) => p,
Err(err) => {
self.log(LogLevel::Error, format!("Could not get current remote path: {}", err).as_ref());
return
}
};
// Get files // Get files
let files: Vec<FsEntry> = self.local.files.clone(); // Otherwise self is borrowed both as mutable and immutable... let files: Vec<FsEntry> = self.local.files.clone(); // Otherwise self is borrowed both as mutable and immutable...
// Get file at index // Get file at index
if let Some(entry) = files.get(self.local.index) { if let Some(entry) = files.get(self.local.index) {
// Call upload // Call upload
self.filetransfer_send(entry, None); self.filetransfer_send(entry, wrkdir.as_path(), None);
} }
} }
_ => { /* Nothing to do */ } _ => { /* Nothing to do */ }
@@ -1591,11 +1601,19 @@ impl FileTransferActivity {
fn callback_save_as(&mut self, input: String) { fn callback_save_as(&mut self, input: String) {
match self.tab { match self.tab {
FileExplorerTab::Local => { FileExplorerTab::Local => {
// Get pwd
let wrkdir: PathBuf = match self.client.pwd() {
Ok(p) => p,
Err(err) => {
self.log(LogLevel::Error, format!("Could not get current remote path: {}", err).as_ref());
return
}
};
let files: Vec<FsEntry> = self.local.files.clone(); let files: Vec<FsEntry> = self.local.files.clone();
// Get file at index // Get file at index
if let Some(entry) = files.get(self.local.index) { if let Some(entry) = files.get(self.local.index) {
// Call send (upload) // Call send (upload)
self.filetransfer_send(entry, Some(input)); self.filetransfer_send(entry, wrkdir.as_path(), Some(input));
} }
} }
FileExplorerTab::Remote => { FileExplorerTab::Remote => {