Browse Source

Retrieving seconds-precision timestamps using MDTM command, if the server provides them.

Part of Bug 1221

Source commit: 3d1017e1ffa7bd04e23f8f0db8a0d509420a728f
Martin Prikryl 10 years ago
parent
commit
d4eb2ce29b
2 changed files with 10 additions and 4 deletions
  1. 3 0
      source/core/FtpFileSystem.cpp
  2. 7 4
      source/filezilla/FtpControlSocket.cpp

+ 3 - 0
source/core/FtpFileSystem.cpp

@@ -2467,6 +2467,9 @@ void __fastcall TFTPFileSystem::AutoDetectTimeDifference(TRemoteFileList * FileL
         TDateTime UtcModification = UtcFile->Modification;
         delete UtcFile;
 
+        // MDTM returns seconds, trim those
+        UtcModification = ReduceDateTimePrecision(UtcModification, File->ModificationFmt);
+
         // Time difference between timestamp retrieved using MDTM (UTC converted to local timezone)
         // and using LIST (no conversion, expecting the server uses the same timezone as the client).
         // Note that FormatTimeZone reverses the value.

+ 7 - 4
source/filezilla/FtpControlSocket.cpp

@@ -4331,7 +4331,8 @@ bool CFtpControlSocket::HandleMdtm(int code, t_directory::t_direntry::t_date & d
     CString line = GetReply();
     if ( line.GetLength()>4  &&  line.Left(4) == L"213 " )
     {
-      int y=0, M=0, d=0, h=0, m=0;
+      int y=0, M=0, d=0, h=0, m=0, s=0;
+      bool hasseconds = false;
       line=line.Mid(4);
       y=_ttoi(line.Left(4));
       if (y && line.GetLength()>4)
@@ -4353,10 +4354,12 @@ bool CFtpControlSocket::HandleMdtm(int code, t_directory::t_direntry::t_date & d
               if (m && line.GetLength()>2)
               {
                 line=line.Mid(2);
+                s=_ttoi(line.Left(2));
+                hasseconds = true;
               }
             }
           }
-          if (M>0 && M<=12 && d>0 && d<=31 && h>=0 && h<24 && m>=0 && m<60)
+          if (M>0 && M<=12 && d>0 && d<=31 && h>=0 && h<24 && m>=0 && m<60 && s>=0 && s<60)
           {
             result = true;
             date.year = y;
@@ -4364,9 +4367,9 @@ bool CFtpControlSocket::HandleMdtm(int code, t_directory::t_direntry::t_date & d
             date.day = d;
             date.hour = h;
             date.minute = m;
-            date.second = 0;
+            date.second = s;
             date.hastime = true;
-            date.hasseconds = false;
+            date.hasseconds = hasseconds;
             date.hasdate = true;
             date.utc = true;
           }