Browse Source

Bug 1985: Files saved in external editors are not uploaded in timezones behind UTC

https://winscp.net/tracker/1985

Source commit: a0383adcb6919eed31bed101412901a44b24cb70
Martin Prikryl 4 years ago
parent
commit
5e6fbc6603
2 changed files with 8 additions and 2 deletions
  1. 7 2
      source/windows/EditorManager.cpp
  2. 1 0
      source/windows/EditorManager.h

+ 7 - 2
source/windows/EditorManager.cpp

@@ -249,7 +249,7 @@ void __fastcall TEditorManager::Check()
     TDateTime NewTimestamp;
     if (HasFileChanged(Index, NewTimestamp))
     {
-      TDateTime N = Now();
+      TDateTime N = NormalizeTimestamp(Now());
       // Let the editor finish writing to the file
       // (first to avoid uploading partially saved file, second
       // because the timestamp may change more than once during saving).
@@ -459,13 +459,18 @@ bool __fastcall TEditorManager::CloseFile(int Index, bool IgnoreErrors, bool Del
   return Result;
 }
 //---------------------------------------------------------------------------
+TDateTime TEditorManager::NormalizeTimestamp(const TDateTime & Timestamp)
+{
+  return TTimeZone::Local->ToUniversalTime(Timestamp);
+}
+//---------------------------------------------------------------------------
 bool TEditorManager::GetFileTimestamp(const UnicodeString & FileName, TDateTime & Timestamp)
 {
   TSearchRecSmart ASearchRec;
   bool Result = FileSearchRec(FileName, ASearchRec);
   if (Result)
   {
-    Timestamp = TTimeZone::Local->ToUniversalTime(ASearchRec.GetLastWriteTime());
+    Timestamp = NormalizeTimestamp(ASearchRec.GetLastWriteTime());
   }
   return Result;
 }

+ 1 - 0
source/windows/EditorManager.h

@@ -101,6 +101,7 @@ private:
   void __fastcall CheckFileChange(int Index, bool Force);
   int __fastcall FindFile(const TObject * Token);
   void __fastcall ReleaseFile(int Index);
+  TDateTime NormalizeTimestamp(const TDateTime & Timestamp);
   bool GetFileTimestamp(const UnicodeString & FileName, TDateTime & Timestamp);
 
   enum TWaitHandle { PROCESS, EVENT };