Browse Source

Consistency between pre- and post- transfer target folder creation

(cherry picked from commit 61a9514fe90be69a69b455725f39b69ac31145aa)

Source commit: 49520a8d7261e3bcecb8499b8194434e19c49772
Martin Prikryl 5 years ago
parent
commit
3510e0cfdf
2 changed files with 21 additions and 23 deletions
  1. 20 22
      source/core/Terminal.cpp
  2. 1 1
      source/core/Terminal.h

+ 20 - 22
source/core/Terminal.cpp

@@ -6929,18 +6929,27 @@ void __fastcall TTerminal::SourceRobust(
   while (RobustLoop.Retry());
 }
 //---------------------------------------------------------------------------
-void __fastcall TTerminal::CreateTargetDirectory(
+bool __fastcall TTerminal::CreateTargetDirectory(
   const UnicodeString & DirectoryPath, int Attrs, const TCopyParamType * CopyParam)
 {
-  TRemoteProperties Properties;
-  if (CopyParam->PreserveRights)
+  TRemoteFile * File = NULL;
+  bool DoCreate =
+    !FileExists(DirectoryPath, &File) ||
+    !File->IsDirectory; // just try to create and make it fail
+  delete File;
+  if (DoCreate)
   {
-    Properties.Valid = Properties.Valid << vpRights;
-    Properties.Rights = CopyParam->RemoteFileRights(Attrs);
+    TRemoteProperties Properties;
+    if (CopyParam->PreserveRights)
+    {
+      Properties.Valid = Properties.Valid << vpRights;
+      Properties.Rights = CopyParam->RemoteFileRights(Attrs);
+    }
+    Properties.Valid = Properties.Valid << vpEncrypt;
+    Properties.Encrypt = CopyParam->EncryptNewFiles;
+    CreateDirectory(DirectoryPath, &Properties);
   }
-  Properties.Valid = Properties.Valid << vpEncrypt;
-  Properties.Encrypt = CopyParam->EncryptNewFiles;
-  CreateDirectory(DirectoryPath, &Properties);
+  return DoCreate;
 }
 //---------------------------------------------------------------------------
 void __fastcall TTerminal::DirectorySource(
@@ -6955,14 +6964,13 @@ void __fastcall TTerminal::DirectorySource(
   OperationProgress->SetFile(DirectoryName);
 
   bool PostCreateDir = FLAGCLEAR(Flags, tfPreCreateDir);
-  // WebDAV and SFTP
+  // WebDAV, SFTP and S3
   if (!PostCreateDir)
   {
     // This is originally a code for WebDAV, SFTP used a slightly different logic,
     // but functionally it should be very similar.
-    if (!FileExists(DestFullName))
+    if (CreateTargetDirectory(DestFullName, Attrs, CopyParam))
     {
-      CreateTargetDirectory(DestFullName, Attrs, CopyParam);
       Flags |= tfNewDirectory;
     }
   }
@@ -7005,17 +7013,7 @@ void __fastcall TTerminal::DirectorySource(
     // FTP
     if (PostCreateDir)
     {
-      TRemoteFile * File = NULL;
-      // ignore non-fatal error when the directory already exists
-      bool DoCreate =
-        !FileExists(DestFullName, &File) ||
-        !File->IsDirectory; // just try to create and make it fail
-      delete File;
-
-      if (DoCreate)
-      {
-        CreateTargetDirectory(DestFullName, Attrs, CopyParam);
-      }
+      CreateTargetDirectory(DestFullName, Attrs, CopyParam);
     }
 
     // TODO : Delete also read-only directories.

+ 1 - 1
source/core/Terminal.h

@@ -256,7 +256,7 @@ private:
   bool __fastcall GetStoredCredentialsTried();
   inline bool __fastcall InTransaction();
   void __fastcall SaveCapabilities(TFileSystemInfo & FileSystemInfo);
-  void __fastcall CreateTargetDirectory(const UnicodeString & DirectoryPath, int Attrs, const TCopyParamType * CopyParam);
+  bool __fastcall CreateTargetDirectory(const UnicodeString & DirectoryPath, int Attrs, const TCopyParamType * CopyParam);
   static UnicodeString __fastcall SynchronizeModeStr(TSynchronizeMode Mode);
   static UnicodeString __fastcall SynchronizeParamsStr(int Params);