Browse Source

Issue 2260 – Failure when trying to synchronize files by checksum on server that does not support it

https://winscp.net/tracker/2260

Source commit: d23d1a3ca251922e98b128ea807f120a690fe517
Martin Prikryl 1 year ago
parent
commit
e782da2c87

+ 5 - 0
source/core/Common.cpp

@@ -4534,6 +4534,11 @@ void NotImplemented()
   throw Exception(L"Not implemented");
 }
 //---------------------------------------------------------------------------
+void NotSupported()
+{
+  throw Exception(MainInstructions(LoadStr(NOTSUPPORTED)));
+}
+//---------------------------------------------------------------------------
 UnicodeString GetDividerLine()
 {
   return UnicodeString::StringOfChar(L'-', 27);

+ 1 - 0
source/core/Common.h

@@ -201,6 +201,7 @@ UnicodeString GetEnvironmentInfo();
 void SetStringValueEvenIfEmpty(TStrings * Strings, const UnicodeString & Name, const UnicodeString & Value);
 UnicodeString __fastcall GetAncestorProcessName(int Levels = 1);
 UnicodeString GetAncestorProcessNames();
+void NotSupported();
 void NotImplemented();
 UnicodeString GetDividerLine();
 //---------------------------------------------------------------------------

+ 1 - 1
source/core/S3FileSystem.cpp

@@ -1370,7 +1370,7 @@ void __fastcall TS3FileSystem::RenameFile(
 {
   if (DebugAlwaysTrue(File != NULL) && File->IsDirectory)
   {
-    throw Exception(LoadStr(NOTSUPPORTED));
+    NotSupported();
   }
   CopyFile(FileName, File, NewName, Overwrite);
   TRmSessionAction DummyAction(FTerminal->ActionLog, FileName);

+ 7 - 5
source/core/Script.cpp

@@ -928,11 +928,6 @@ void __fastcall TScript::CheckSession()
   }
 }
 //---------------------------------------------------------------------------
-void __fastcall TScript::NotSupported()
-{
-  throw Exception(LoadStr(NOTSUPPORTED));
-}
-//---------------------------------------------------------------------------
 void __fastcall TScript::CheckMultiFilesToOne(TStrings * FileList, const UnicodeString & Target, bool Unix)
 {
   UnicodeString Name;
@@ -2067,6 +2062,13 @@ void __fastcall TScript::SynchronizeProc(TScriptProcParams * Parameters)
 
     CheckParams(Parameters);
 
+    if (FLAGSET(SynchronizeParams, TTerminal::spByChecksum) &&
+        (!FTerminal->IsCapable[fcCalculatingChecksum] &&
+         !FTerminal->IsCapable[fcSecondaryShell]))
+    {
+      NotSupported();
+    }
+
     PrintLine(LoadStr(SCRIPT_SYNCHRONIZE_COLLECTING));
 
     TSynchronizeChecklist * Checklist =

+ 0 - 1
source/core/Script.h

@@ -188,7 +188,6 @@ private:
   void __fastcall CheckDefaultCopyParam();
   bool __fastcall HasNonDefaultCopyParams();
   void __fastcall CheckDefaultSynchronizeParams();
-  void __fastcall NotSupported();
   void __fastcall CheckMultiFilesToOne(TStrings * FileList, const UnicodeString & Target, bool Unix);
   void __fastcall LogOption(const UnicodeString & LogStr);
   void __fastcall DoMvOrCp(TScriptProcParams * Parameters, TFSCapability Capability, bool Cp);

+ 2 - 2
source/core/Terminal.cpp

@@ -7325,7 +7325,7 @@ bool __fastcall TTerminal::CopyToRemote(
 
   if ((CopyParam->OnTransferIn != NULL) && !FFileSystem->IsCapable(fcTransferIn))
   {
-    throw Exception(LoadStr(NOTSUPPORTED));
+    NotSupported();
   }
 
   try
@@ -7885,7 +7885,7 @@ bool __fastcall TTerminal::CopyToLocal(
 
   if ((CopyParam->OnTransferOut != NULL) && !FFileSystem->IsCapable(fcTransferOut))
   {
-    throw Exception(LoadStr(NOTSUPPORTED));
+    NotSupported();
   }
 
   FDestFileName = L"";

+ 7 - 2
source/forms/CustomScpExplorer.cpp

@@ -7022,8 +7022,13 @@ bool __fastcall TCustomScpExplorerForm::EnsureCommandSessionFallback(TFSCapabili
 
   if (!Result)
   {
-    DebugAssert(Terminal->IsCapable[fcSecondaryShell]);
-    if (!GUIConfiguration->ConfirmCommandSession)
+    // We might get here for example when "checksum" synchronization is requested from command-line
+    // on server that supports
+    if (!Terminal->IsCapable[fcSecondaryShell])
+    {
+      NotSupported();
+    }
+    else if (!GUIConfiguration->ConfirmCommandSession)
     {
       Result = true;
     }