Browse Source

Factoring out CheckOverwriteFileAndCreateTarget and FileTransferHandleDirectoryListing

Source commit: 0d9d7f19f748e6cffb0931db05fcd314814af3cb
Martin Prikryl 3 years ago
parent
commit
c9ff66a226
2 changed files with 42 additions and 68 deletions
  1. 39 67
      source/filezilla/FtpControlSocket.cpp
  2. 3 1
      source/filezilla/FtpControlSocket.h

+ 39 - 67
source/filezilla/FtpControlSocket.cpp

@@ -2895,25 +2895,7 @@ void CFtpControlSocket::FileTransfer(t_transferfile *transferfile/*=0*/,BOOL bFi
         }
         if (m_pDirectoryListing && i==m_pDirectoryListing->num)
         {
-          nReplyError = CheckOverwriteFile();
-          if (!nReplyError)
-          {
-            if (pData->transferfile.get)
-            {
-              CString path=pData->transferfile.localfile;
-              if (path.ReverseFind(L'\\')!=-1)
-              {
-                path=path.Left(path.ReverseFind(L'\\')+1);
-                CString path2;
-                while (path!=L"")
-                {
-                  path2+=path.Left(path.Find( L"\\" )+1);
-                  path=path.Mid(path.Find( L"\\" )+1);
-                  CreateDirectory(path2, 0);
-                }
-              }
-            }
-          }
+          nReplyError = CheckOverwriteFileAndCreateTarget();
         }
       }
       else
@@ -3312,31 +3294,7 @@ void CFtpControlSocket::FileTransfer(t_transferfile *transferfile/*=0*/,BOOL bFi
         else
           listing.path = pData->transferfile.remotepath;
 
-        SetDirectoryListing(&listing);
-
-        m_Operation.nOpState = FILETRANSFER_TYPE;
-        delete m_pTransferSocket;
-        m_pTransferSocket = 0;
-
-        nReplyError = CheckOverwriteFile();
-        if (!nReplyError)
-        {
-          if (pData->transferfile.get)
-          {
-            CString path=pData->transferfile.localfile;
-            if (path.ReverseFind(L'\\')!=-1)
-            {
-              path=path.Left(path.ReverseFind(L'\\')+1);
-              CString path2;
-              while (path!=L"")
-              {
-                path2+=path.Left(path.Find( L"\\" )+1);
-                path=path.Mid(path.Find( L"\\" )+1);
-                CreateDirectory(path2, 0);
-              }
-            }
-          }
-        }
+        nReplyError = FileTransferHandleDirectoryListing(&listing);
       }
       else if (code==4 || code==5) //LIST failed, try getting file information using SIZE and MDTM
       {
@@ -3366,29 +3324,7 @@ void CFtpControlSocket::FileTransfer(t_transferfile *transferfile/*=0*/,BOOL bFi
       }
       if (pData->nGotTransferEndReply && pData->pDirectoryListing)
       {
-        SetDirectoryListing(pData->pDirectoryListing);
-        delete m_pTransferSocket;
-        m_pTransferSocket=0;
-        m_Operation.nOpState=FILETRANSFER_TYPE;
-        nReplyError = CheckOverwriteFile();
-        if (!nReplyError)
-        {
-          if (pData->transferfile.get)
-          {
-            CString path=pData->transferfile.localfile;
-            if (path.ReverseFind(L'\\')!=-1)
-            {
-              path=path.Left(path.ReverseFind(L'\\')+1);
-              CString path2;
-              while (path!=L"")
-              {
-                path2+=path.Left(path.Find( L"\\" )+1);
-                path=path.Mid(path.Find( L"\\" )+1);
-                CreateDirectory(path2, 0);
-              }
-            }
-          }
-        }
+        nReplyError = FileTransferHandleDirectoryListing(pData->pDirectoryListing);
         pData->nGotTransferEndReply=0;
       }
       break;
@@ -4914,6 +4850,42 @@ public:
   }
 }
 
+int CFtpControlSocket::FileTransferHandleDirectoryListing(t_directory * pDirectory)
+{
+  SetDirectoryListing(pDirectory);
+
+  m_Operation.nOpState = FILETRANSFER_TYPE;
+  delete m_pTransferSocket;
+  m_pTransferSocket = 0;
+
+  return CheckOverwriteFileAndCreateTarget();
+}
+
+int CFtpControlSocket::CheckOverwriteFileAndCreateTarget()
+{
+  int nReplyError = CheckOverwriteFile();
+  if (!nReplyError)
+  {
+    CFileTransferData * pData = static_cast<CFileTransferData *>(m_Operation.pData);
+    if (pData->transferfile.get)
+    {
+      CString path = pData->transferfile.localfile;
+      if (path.ReverseFind(L'\\') != -1)
+      {
+        path = path.Left(path.ReverseFind(L'\\')+1);
+        CString path2;
+        while (path != L"")
+        {
+          path2 += path.Left(path.Find(L"\\") + 1);
+          path = path.Mid(path.Find(L"\\") + 1);
+          CreateDirectory(path2, 0);
+        }
+      }
+    }
+  }
+  return nReplyError;
+}
+
 int CFtpControlSocket::CheckOverwriteFile()
 {
   if (!m_Operation.pData)

+ 3 - 1
source/filezilla/FtpControlSocket.h

@@ -65,7 +65,6 @@ public:
 
   void SetAsyncRequestResult(int nAction, CAsyncRequestData * pData);
 
-  int CheckOverwriteFile();
   BOOL Create();
   void TransfersocketListenFinished(unsigned int ip, unsigned short port);
 
@@ -169,6 +168,9 @@ protected:
   _int64 GetSpeedLimit(CTime & time, int valType, int valValue);
 
   void SetDirectoryListing(t_directory * pDirectory, bool bSetWorkingDir = true);
+  int CheckOverwriteFile();
+  int CheckOverwriteFileAndCreateTarget();
+  int FileTransferHandleDirectoryListing(t_directory * pDirectory);
   t_directory * m_pDirectoryListing;
 
   CMainThread * m_pOwner;