Changed FTP library from ftp4 to suppaftp; Handle directory already exists on FTP transfer; mkdir already exists test units

This commit is contained in:
veeso
2021-08-23 11:11:14 +02:00
parent 81482b47f4
commit 7390bb58c5
10 changed files with 218 additions and 553 deletions

View File

@@ -554,13 +554,14 @@ impl FileTransfer for SftpFileTransfer {
/// ### mkdir
///
/// Make directory
/// In case the directory already exists, it must return an Error of kind `FileTransferErrorType::DirectoryAlreadyExists`
fn mkdir(&mut self, dir: &Path) -> Result<(), FileTransferError> {
match self.sftp.as_ref() {
Some(sftp) => {
// Make directory
let path: PathBuf = self.get_abs_path(PathBuf::from(dir).as_path());
// If directory already exists, return Err
if let Ok(_) = sftp.stat(path.as_path()) {
if sftp.stat(path.as_path()).is_ok() {
error!("Directory {} already exists", path.display());
return Err(FileTransferError::new(
FileTransferErrorType::DirectoryAlreadyExists,
@@ -846,6 +847,15 @@ mod tests {
assert!(client.list_dir(&Path::new("/config")).unwrap().len() >= 4);
// Make directory
assert!(client.mkdir(PathBuf::from("/tmp/omar").as_path()).is_ok());
// Remake directory (should report already exists)
assert_eq!(
client
.mkdir(PathBuf::from("/tmp/omar").as_path())
.err()
.unwrap()
.kind(),
FileTransferErrorType::DirectoryAlreadyExists
);
// Make directory (err)
assert!(client
.mkdir(PathBuf::from("/root/aaaaa/pommlar").as_path())