소스 검색

Bug 2078: When transferring a growing file, after its original size is reached, the Session.FileTransferProgress event starts being triggered continuously

https://winscp.net/tracker/2078

Source commit: 3f6718b70e793a8d7972db88870716f18ec313cd
Martin Prikryl 3 년 전
부모
커밋
b7dc14c954
2개의 변경된 파일34개의 추가작업 그리고 19개의 파일을 삭제
  1. 32 19
      source/core/Script.cpp
  2. 2 0
      source/core/Script.h

+ 32 - 19
source/core/Script.cpp

@@ -2242,10 +2242,12 @@ void __fastcall TManagementScript::PrintProgress(bool First, const UnicodeString
 void __fastcall TManagementScript::ResetTransfer()
 {
   TScript::ResetTransfer();
-  FLastProgressFile = L"";
+  FLastProgressFile = EmptyStr;
   FLastProgressTime = 0;
   FLastProgressEventTime = 0;
-  FLastProgressMessage = L"";
+  FLastProgressEventDoneFileName = EmptyStr;
+  FLastProgressOverallDone = false;
+  FLastProgressMessage = EmptyStr;
 }
 //---------------------------------------------------------------------------
 bool __fastcall TManagementScript::QueryCancel()
@@ -2331,25 +2333,36 @@ void __fastcall TManagementScript::TerminalOperationProgress(
 
       time_t Time = time(NULL);
 
-      if ((OnProgress != NULL) && WantsProgress &&
-          (DoPrint || (FLastProgressEventTime != Time) || ProgressData.IsTransferDone()))
+      if ((OnProgress != NULL) && WantsProgress)
       {
-        FLastProgressEventTime = Time;
-
-        TScriptProgress Progress;
-        Progress.Operation = ProgressData.Operation;
-        Progress.Side = ProgressData.Side;
-        Progress.FileName = ProgressData.FullFileName;
-        Progress.Directory = ProgressData.Directory;
-        Progress.OverallProgress = ProgressData.OverallProgress();
-        Progress.FileProgress = ProgressData.TransferProgress();
-        Progress.CPS = ProgressData.CPS();
-        Progress.Cancel = false;
-        OnProgress(this, Progress);
-
-        if (Progress.Cancel)
+        int OverallProgress = ProgressData.OverallProgress();
+        bool OverallDone = (OverallProgress == 100);
+
+        if (DoPrint ||
+            (FLastProgressEventTime != Time) ||
+            (ProgressData.IsTransferDone() && (FLastProgressEventDoneFileName != ProgressData.FullFileName)) ||
+            (OverallDone && !FLastProgressOverallDone))
         {
-          ProgressData.SetCancel(csCancel);
+          FLastProgressEventTime = Time;
+          // When transferring a growing file, we would report the progress constantly
+          FLastProgressEventDoneFileName = ProgressData.IsTransferDone() ? ProgressData.FullFileName : EmptyStr;
+          FLastProgressOverallDone = OverallDone;
+
+          TScriptProgress Progress;
+          Progress.Operation = ProgressData.Operation;
+          Progress.Side = ProgressData.Side;
+          Progress.FileName = ProgressData.FullFileName;
+          Progress.Directory = ProgressData.Directory;
+          Progress.OverallProgress = OverallProgress;
+          Progress.FileProgress = ProgressData.TransferProgress();
+          Progress.CPS = ProgressData.CPS();
+          Progress.Cancel = false;
+          OnProgress(this, Progress);
+
+          if (Progress.Cancel)
+          {
+            ProgressData.SetCancel(csCancel);
+          }
         }
       }
 

+ 2 - 0
source/core/Script.h

@@ -228,6 +228,8 @@ protected:
   UnicodeString FLastProgressMessage;
   time_t FLastProgressTime;
   time_t FLastProgressEventTime;
+  UnicodeString FLastProgressEventDoneFileName;
+  bool FLastProgressOverallDone;
   bool FContinue;
 
   virtual void __fastcall ResetTransfer();