Browse Source

Bug 1790: Error when reopening a remote file whose local temporary copy has been deleted

https://winscp.net/tracker/1790
(cherry picked from commit 9fbbf457452e30adeb1edb373951975c379bc044)

Source commit: 380919a20912da855b38320b5a29ff4cb76785bd
Martin Prikryl 6 years ago
parent
commit
25473e8d3b
1 changed files with 8 additions and 3 deletions
  1. 8 3
      source/windows/EditorManager.cpp

+ 8 - 3
source/windows/EditorManager.cpp

@@ -116,9 +116,14 @@ bool __fastcall TEditorManager::CanAddFile(const UnicodeString RemoteDirectory,
           }
           else
           {
-            // get directory where the file already is so we download it there again
-            ExistingLocalRootDirectory = FileData->Data->LocalRootDirectory;
-            ExistingLocalDirectory = ExtractFilePath(FileData->FileName);
+            UnicodeString AExistingLocalDirectory = ExtractFilePath(FileData->FileName);
+            // If the temporary directory was deleted, behave like the file was never opened
+            if (DirectoryExists(AExistingLocalDirectory))
+            {
+              // get directory where the file already is so we download it there again
+              ExistingLocalRootDirectory = FileData->Data->LocalRootDirectory;
+              ExistingLocalDirectory = AExistingLocalDirectory;
+            }
             CloseFile(i, false, false); // do not delete file
             Result = true;
           }