fixed recursive remove FTP

This commit is contained in:
veeso
2021-06-13 09:47:17 +02:00
parent 59eb7f7935
commit 542123ce04
2 changed files with 41 additions and 10 deletions

View File

@@ -24,6 +24,7 @@ Released on FIXME: ??
- Bugfix: - Bugfix:
- Fixed broken input cursor when typing UTF8 characters (tui-realm 0.3.2) - Fixed broken input cursor when typing UTF8 characters (tui-realm 0.3.2)
- Fixed [Issue 43](https://github.com/veeso/termscp/issues/43): Could not remove non-empty directories in FTP
- Fixed [Issue 39](https://github.com/veeso/termscp/issues/39): Help panels as `ScrollTable` to allow displaying entire content on small screens - Fixed [Issue 39](https://github.com/veeso/termscp/issues/39): Help panels as `ScrollTable` to allow displaying entire content on small screens
- Fixed [Issue 37](https://github.com/veeso/termscp/issues/37): progress bar not visible when editing remote files - Fixed [Issue 37](https://github.com/veeso/termscp/issues/37): progress bar not visible when editing remote files
- Dependencies: - Dependencies:

View File

@@ -629,23 +629,36 @@ impl FileTransfer for FtpFileTransfer {
)); ));
} }
info!("Removing entry {}", fsentry.get_abs_path().display()); info!("Removing entry {}", fsentry.get_abs_path().display());
let wrkdir: PathBuf = self.pwd()?;
match fsentry { match fsentry {
// Match fs entry... // Match fs entry...
FsEntry::File(file) => { FsEntry::File(file) => {
debug!("entry is a file; removing file"); // Go to parent directory
if let Some(parent_dir) = file.abs_path.parent() {
debug!("Changing wrkdir to {}", parent_dir.display());
self.change_dir(parent_dir)?;
}
debug!("entry is a file; removing file {}", file.abs_path.display());
// Remove file directly // Remove file directly
match self.stream.as_mut().unwrap().rm(file.name.as_ref()) { let result = self
Ok(_) => Ok(()), .stream
Err(err) => Err(FileTransferError::new_ex( .as_mut()
FileTransferErrorType::PexError, .unwrap()
err.to_string(), .rm(file.name.as_ref())
)), .map(|_| ())
.map_err(|e| {
FileTransferError::new_ex(FileTransferErrorType::PexError, e.to_string())
});
// Go to source directory
match self.change_dir(wrkdir.as_path()) {
Err(err) => Err(err),
Ok(_) => result,
} }
} }
FsEntry::Directory(dir) => { FsEntry::Directory(dir) => {
// Get directory files // Get directory files
debug!("Entry is a directory; iterating directory entries"); debug!("Entry is a directory; iterating directory entries");
match self.list_dir(dir.abs_path.as_path()) { let result = match self.list_dir(dir.abs_path.as_path()) {
Ok(files) => { Ok(files) => {
// Remove recursively files // Remove recursively files
debug!("Removing {} entries from directory...", files.len()); debug!("Removing {} entries from directory...", files.len());
@@ -658,9 +671,21 @@ impl FileTransfer for FtpFileTransfer {
} }
} }
// Once all files in directory have been deleted, remove directory // Once all files in directory have been deleted, remove directory
debug!("Finally removing directory {}", dir.name); debug!("Finally removing directory {}...", dir.name);
// Enter parent directory
if let Some(parent_dir) = dir.abs_path.parent() {
debug!(
"Changing wrkdir to {} to delete directory {}",
parent_dir.display(),
dir.name
);
self.change_dir(parent_dir)?;
}
match self.stream.as_mut().unwrap().rmdir(dir.name.as_str()) { match self.stream.as_mut().unwrap().rmdir(dir.name.as_str()) {
Ok(_) => Ok(()), Ok(_) => {
debug!("Removed {}", dir.abs_path.display());
Ok(())
}
Err(err) => Err(FileTransferError::new_ex( Err(err) => Err(FileTransferError::new_ex(
FileTransferErrorType::PexError, FileTransferErrorType::PexError,
err.to_string(), err.to_string(),
@@ -671,6 +696,11 @@ impl FileTransfer for FtpFileTransfer {
FileTransferErrorType::DirStatFailed, FileTransferErrorType::DirStatFailed,
err.to_string(), err.to_string(),
)), )),
};
// Restore directory
match self.change_dir(wrkdir.as_path()) {
Err(err) => Err(err),
Ok(_) => result,
} }
} }
} }