Browse Source

Issue 2266 – Hang when canceling connection while reading remote directory

https://winscp.net/tracker/2266
(cherry picked from commit c1b26228bc0a2fedd142dde276bfc3d67fd5d75c)

Source commit: 0d288961d2ce00774d08b547d47149f42f09c7d8
Martin Prikryl 1 year ago
parent
commit
e01a19ab4c
2 changed files with 8 additions and 3 deletions
  1. 7 3
      source/windows/TerminalManager.cpp
  2. 1 0
      source/windows/TerminalManager.h

+ 7 - 3
source/windows/TerminalManager.cpp

@@ -80,6 +80,7 @@ __fastcall TTerminalManager::TTerminalManager() :
   FPendingConfigurationChange = 0;
   FKeepAuthenticateForm = false;
   FUpdating = 0;
+  FOpeningTerminal = NULL;
 
   FApplicationsEvents.reset(new TApplicationEvents(Application));
   FApplicationsEvents->OnException = ApplicationException;
@@ -312,6 +313,8 @@ void __fastcall TTerminalManager::DoConnectTerminal(TTerminal * Terminal, bool R
   UnicodeString OrigRemoteDirectory = Terminal->SessionData->RemoteDirectory;
   try
   {
+    TValueRestorer<TTerminal *> OpeningTerminalRestorer(FOpeningTerminal);
+    FOpeningTerminal = Terminal;
     TTerminalThread * TerminalThread = new TTerminalThread(Terminal);
     TerminalThread->AllowAbandon = (Terminal == ActiveTerminal);
     try
@@ -1297,11 +1300,12 @@ void __fastcall TTerminalManager::TerminalShowExtendedException(
 static TDateTime DirectoryReadingProgressDelay(0, 0, 1, 500);
 //---------------------------------------------------------------------------
 void __fastcall TTerminalManager::TerminalReadDirectoryProgress(
-  TObject * /*Sender*/, int Progress, int ResolvedLinks, bool & Cancel)
+  TObject * Sender, int Progress, int ResolvedLinks, bool & Cancel)
 {
+  DebugAlwaysTrue((Sender == FOpeningTerminal) == (FAuthenticateForm != NULL));
   if (Progress == 0)
   {
-    if (ScpExplorer != NULL)
+    if ((ScpExplorer != NULL) && (Sender != FOpeningTerminal))
     {
       // See also TCustomScpExplorerForm::RemoteDirViewBusy
       ScpExplorer->LockWindow();
@@ -1329,7 +1333,7 @@ void __fastcall TTerminalManager::TerminalReadDirectoryProgress(
     }
     else
     {
-      if (ScpExplorer != NULL)
+      if ((ScpExplorer != NULL) && (Sender != FOpeningTerminal))
       {
         ScpExplorer->UnlockWindow();
       }

+ 1 - 0
source/windows/TerminalManager.h

@@ -129,6 +129,7 @@ private:
   bool FKeepAuthenticateForm;
   int FUpdating;
   int FMaxSessions;
+  TTerminal * FOpeningTerminal;
 
   bool __fastcall ConnectActiveTerminalImpl(bool Reopen);
   bool __fastcall ConnectActiveTerminal();