Prechádzať zdrojové kódy

Issue 2291 – Failure when trying to automate file synchronization by checksum on an SFTP server that does not support it natively

https://winscp.net/tracker/2291

Source commit: e41184d38b7fb153931146024e6794acd2b84d12
Martin Prikryl 1 rok pred
rodič
commit
5deca33acf
2 zmenil súbory, kde vykonal 46 pridanie a 33 odobranie
  1. 45 32
      source/core/Script.cpp
  2. 1 1
      source/core/Script.h

+ 45 - 32
source/core/Script.cpp

@@ -1097,7 +1097,7 @@ void __fastcall TScript::ResetTransfer()
 }
 //---------------------------------------------------------------------------
 bool __fastcall TScript::EnsureCommandSessionFallback(
-  TFSCapability Capability, TSessionAction & Action)
+  TFSCapability Capability, TSessionAction * Action)
 {
   bool Result = FTerminal->IsCapable[Capability] ||
     FTerminal->CommandSessionOpened;
@@ -1111,7 +1111,10 @@ bool __fastcall TScript::EnsureCommandSessionFallback(
     }
     catch(Exception & E)
     {
-      Action.Rollback(&E);
+      if (Action != NULL)
+      {
+        Action->Rollback(&E);
+      }
       HandleExtendedException(&E, FTerminal->CommandSession);
       Result = false;
     }
@@ -1169,7 +1172,7 @@ void __fastcall TScript::CallProc(TScriptProcParams * Parameters)
   // the actual call logging is done in TTerminal::AnyCommand
   TCallSessionAction Action(
     FTerminal->ActionLog, Parameters->ParamsStr, FTerminal->CurrentDirectory);
-  if (EnsureCommandSessionFallback(fcAnyCommand, Action))
+  if (EnsureCommandSessionFallback(fcAnyCommand, &Action))
   {
     Action.Cancel();
     FTerminal->AnyCommand(Parameters->ParamsStr, TerminalCaptureLog);
@@ -1218,7 +1221,7 @@ void __fastcall TScript::ChecksumProc(TScriptProcParams * Parameters)
   // this is used only to log failures to open separate shell session,
   // the actual call logging is done in TTerminal::CalculateFilesChecksum
   TChecksumSessionAction Action(FTerminal->ActionLog);
-  if (EnsureCommandSessionFallback(fcCalculatingChecksum, Action))
+  if (EnsureCommandSessionFallback(fcCalculatingChecksum, &Action))
   {
     Action.Cancel();
 
@@ -2062,50 +2065,60 @@ void __fastcall TScript::SynchronizeProc(TScriptProcParams * Parameters)
 
     CheckParams(Parameters);
 
+    bool Continue = true;
     if (FLAGSET(SynchronizeParams, TTerminal::spByChecksum) &&
-        (!FTerminal->IsCapable[fcCalculatingChecksum] &&
-         !FTerminal->IsCapable[fcSecondaryShell]))
+        !FTerminal->IsCapable[fcCalculatingChecksum])
     {
-      NotSupported();
+      if (!FTerminal->IsCapable[fcSecondaryShell])
+      {
+        NotSupported();
+      }
+      else
+      {
+        Continue = EnsureCommandSessionFallback(fcCalculatingChecksum, NULL);
+      }
     }
 
-    PrintLine(LoadStr(SCRIPT_SYNCHRONIZE_COLLECTING));
-
-    TSynchronizeChecklist * Checklist =
-      FTerminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
-        static_cast<TTerminal::TSynchronizeMode>(FSynchronizeMode),
-        &CopyParam, SynchronizeParams, OnTerminalSynchronizeDirectory, NULL);
-    try
+    if (Continue)
     {
-      bool AnyChecked = false;
-      for (int Index = 0; !AnyChecked && (Index < Checklist->Count); Index++)
-      {
-        AnyChecked = Checklist->Item[Index]->Checked;
-      }
+      PrintLine(LoadStr(SCRIPT_SYNCHRONIZE_COLLECTING));
 
-      if (AnyChecked)
+      TSynchronizeChecklist * Checklist =
+        FTerminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
+          static_cast<TTerminal::TSynchronizeMode>(FSynchronizeMode),
+          &CopyParam, SynchronizeParams, OnTerminalSynchronizeDirectory, NULL);
+      try
       {
-        if (Preview)
+        bool AnyChecked = false;
+        for (int Index = 0; !AnyChecked && (Index < Checklist->Count); Index++)
         {
-          PrintLine(LoadStr(SCRIPT_SYNCHRONIZE_CHECKLIST));
-          SynchronizePreview(LocalDirectory, RemoteDirectory, Checklist);
+          AnyChecked = Checklist->Item[Index]->Checked;
+        }
+
+        if (AnyChecked)
+        {
+          if (Preview)
+          {
+            PrintLine(LoadStr(SCRIPT_SYNCHRONIZE_CHECKLIST));
+            SynchronizePreview(LocalDirectory, RemoteDirectory, Checklist);
+          }
+          else
+          {
+            PrintLine(LoadStr(SCRIPT_SYNCHRONIZE_SYNCHRONIZING));
+            FTerminal->SynchronizeApply(
+              Checklist, &CopyParam, SynchronizeParams, OnTerminalSynchronizeDirectory, NULL, NULL, NULL, NULL);
+          }
         }
         else
         {
-          PrintLine(LoadStr(SCRIPT_SYNCHRONIZE_SYNCHRONIZING));
-          FTerminal->SynchronizeApply(
-            Checklist, &CopyParam, SynchronizeParams, OnTerminalSynchronizeDirectory, NULL, NULL, NULL, NULL);
+          NoMatch(LoadStr(SCRIPT_SYNCHRONIZE_NODIFFERENCE));
         }
       }
-      else
+      __finally
       {
-        NoMatch(LoadStr(SCRIPT_SYNCHRONIZE_NODIFFERENCE));
+        delete Checklist;
       }
     }
-    __finally
-    {
-      delete Checklist;
-    }
   }
   __finally
   {

+ 1 - 1
source/core/Script.h

@@ -115,7 +115,7 @@ protected:
   virtual void __fastcall ResetTransfer();
   virtual void __fastcall ConnectTerminal(TTerminal * ATerminal);
   bool __fastcall EnsureCommandSessionFallback(
-    TFSCapability Capability, TSessionAction & Action);
+    TFSCapability Capability, TSessionAction * Action);
   void __fastcall Print(const UnicodeString Str, bool Error = false);
   void __fastcall CheckSession();
   void __fastcall CheckParams(TScriptProcParams * Parameters);