浏览代码

Bug 1832: Suppress errors when opened/edited files are locked

https://winscp.net/tracker/1832

Source commit: ef1115a9f283214d00e546b4dc1e14a792fe36d0
Martin Prikryl 5 年之前
父节点
当前提交
3c955b66ba
共有 1 个文件被更改,包括 40 次插入20 次删除
  1. 40 20
      source/windows/EditorManager.cpp

+ 40 - 20
source/windows/EditorManager.cpp

@@ -489,31 +489,51 @@ void __fastcall TEditorManager::CheckFileChange(int Index, bool Force)
     }
     }
     else
     else
     {
     {
-      FileData->UploadCompleteEvent = CreateEvent(NULL, false, false, NULL);
-      FUploadCompleteEvents.push_back(FileData->UploadCompleteEvent);
-
-      FileData->Timestamp = NewTimestamp;
-      FileData->Saves++;
-      if (FileData->Saves == 1)
+      bool Upload = true;
+      if (!Force)
       {
       {
-        Configuration->Usage->Inc(L"RemoteFilesSaved");
-      }
-      Configuration->Usage->Inc(L"RemoteFileSaves");
-
-      try
-      {
-        DebugAssert(OnFileChange != NULL);
-        OnFileChange(FileData->FileName, FileData->Data,
-          FileData->UploadCompleteEvent);
+        HANDLE Handle = CreateFile(ApiPath(FileData->FileName).c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
+        if (Handle == INVALID_HANDLE_VALUE)
+        {
+          int Error = GetLastError();
+          if (Error == ERROR_ACCESS_DENIED)
+          {
+            Upload = false;
+          }
+        }
+        else
+        {
+          CloseHandle(Handle);
+        }
       }
       }
-      catch(...)
+      if (Upload)
       {
       {
-        // upload failed (was not even started)
-        if (FileData->UploadCompleteEvent != INVALID_HANDLE_VALUE)
+        FileData->UploadCompleteEvent = CreateEvent(NULL, false, false, NULL);
+        FUploadCompleteEvents.push_back(FileData->UploadCompleteEvent);
+
+        FileData->Timestamp = NewTimestamp;
+        FileData->Saves++;
+        if (FileData->Saves == 1)
+        {
+          Configuration->Usage->Inc(L"RemoteFilesSaved");
+        }
+        Configuration->Usage->Inc(L"RemoteFileSaves");
+
+        try
+        {
+          DebugAssert(OnFileChange != NULL);
+          OnFileChange(FileData->FileName, FileData->Data,
+            FileData->UploadCompleteEvent);
+        }
+        catch(...)
         {
         {
-          UploadComplete(Index);
+          // upload failed (was not even started)
+          if (FileData->UploadCompleteEvent != INVALID_HANDLE_VALUE)
+          {
+            UploadComplete(Index);
+          }
+          throw;
         }
         }
-        throw;
       }
       }
     }
     }
   }
   }