瀏覽代碼

Bug 1922: Do not use a transfer via temporary file for files that would exceed system length limit with the temporary extension

https://winscp.net/tracker/1922
(cherry picked from commit 7f1aaa1b1aef761a83d2040dea5ce704a9bb7bb7)

Source commit: 55d66d21af80d2328e2b2bfd170ea962c34d7904
Martin Prikryl 5 年之前
父節點
當前提交
d8a274d910
共有 4 個文件被更改,包括 21 次插入11 次删除
  1. 15 6
      source/core/CopyParam.cpp
  2. 1 1
      source/core/CopyParam.h
  3. 3 2
      source/core/FtpFileSystem.cpp
  4. 2 2
      source/core/SftpFileSystem.cpp

+ 15 - 6
source/core/CopyParam.cpp

@@ -775,15 +775,24 @@ int __fastcall TCopyParamType::LocalFileAttrs(const TRights & Rights) const
   return Result;
 }
 //---------------------------------------------------------------------------
-bool __fastcall TCopyParamType::AllowResume(__int64 Size) const
+bool __fastcall TCopyParamType::AllowResume(__int64 Size, const UnicodeString & FileName) const
 {
-  switch (ResumeSupport)
+  bool Result;
+  if (FileName.Length() + UnicodeString(PARTIAL_EXT).Length() > 255) // it's a different limit than MAX_PATH
   {
-    case rsOn: return true;
-    case rsOff: return false;
-    case rsSmart: return (Size >= ResumeThreshold);
-    default: DebugFail(); return false;
+    Result = false;
+  }
+  else
+  {
+    switch (ResumeSupport)
+    {
+      case rsOn: Result = true; break;
+      case rsOff: Result = false; break;
+      case rsSmart: Result = (Size >= ResumeThreshold); break;
+      default: DebugFail(); Result = false; break;
+    }
   }
+  return Result;
 }
 //---------------------------------------------------------------------------
 bool __fastcall TCopyParamType::AllowAnyTransfer() const

+ 1 - 1
source/core/CopyParam.h

@@ -100,7 +100,7 @@ public:
   TRights __fastcall RemoteFileRights(int Attrs) const;
   bool __fastcall UseAsciiTransfer(UnicodeString FileName, TOperationSide Side,
     const TFileMasks::TParams & Params) const;
-  bool __fastcall AllowResume(__int64 Size) const;
+  bool __fastcall AllowResume(__int64 Size, const UnicodeString & FileName) const;
   bool __fastcall ResumeTransfer(UnicodeString FileName) const;
   UnicodeString __fastcall ValidLocalFileName(UnicodeString FileName) const;
   UnicodeString __fastcall ValidLocalPath(UnicodeString Path) const;

+ 3 - 2
source/core/FtpFileSystem.cpp

@@ -3669,9 +3669,10 @@ bool __fastcall TFTPFileSystem::HandleAsynchRequestOverwrite(
         }
       }
 
+      bool AllowResume = UserData.CopyParam->AllowResume(FileParams.SourceSize, UnicodeString());
+      bool AutoResume = UserData.AutoResume;
       if (ConfirmOverwrite(SourceFullFileName, TargetFileName, OverwriteMode, OperationProgress,
-            (NoFileParams ? NULL : &FileParams), UserData.CopyParam, UserData.Params,
-            UserData.AutoResume && UserData.CopyParam->AllowResume(FileParams.SourceSize)))
+            (NoFileParams ? NULL : &FileParams), UserData.CopyParam, UserData.Params, AutoResume))
       {
         switch (OverwriteMode)
         {

+ 2 - 2
source/core/SftpFileSystem.cpp

@@ -4502,7 +4502,7 @@ void __fastcall TSFTPFileSystem::Source(
   // should we check for interrupted transfer?
   ResumeAllowed =
     !OperationProgress->AsciiTransfer &&
-    CopyParam->AllowResume(OperationProgress->LocalSize) &&
+    CopyParam->AllowResume(OperationProgress->LocalSize, DestFileName) &&
     IsCapable(fcRename) &&
     !FTerminal->IsEncryptingFiles() &&
     (CopyParam->OnTransferIn == NULL);
@@ -5260,7 +5260,7 @@ void __fastcall TSFTPFileSystem::Sink(
   bool ResumeAllowed =
     FLAGCLEAR(Params, cpTemporary) &&
     !OperationProgress->AsciiTransfer &&
-    CopyParam->AllowResume(OperationProgress->TransferSize) &&
+    CopyParam->AllowResume(OperationProgress->TransferSize, DestFileName) &&
     !FTerminal->IsEncryptingFiles() &&
     (CopyParam->OnTransferOut == NULL);