]> git.saurik.com Git - wxWidgets.git/commitdiff
Don't change file access time implicitly when setting it explicitly.
authorVadim Zeitlin <vadim@wxwidgets.org>
Tue, 24 Nov 2009 00:01:25 +0000 (00:01 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Tue, 24 Nov 2009 00:01:25 +0000 (00:01 +0000)
wxFileHandle helper class used in wxFileName::SetTimes() under MSW modified
the file access time by setting it to the current time because it opened the
file in a wrong mode.

Closes #10567.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62705 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/common/filename.cpp

index 09b31fd33501345e8c1bd4fb9972c6bbeec9e583..090850d8d830f9fea2e8790417c8a86b3d4b82c1 100644 (file)
@@ -160,17 +160,21 @@ class wxFileHandle
 public:
     enum OpenMode
     {
-        Read,
-        Write
+        ReadAttr,
+        WriteAttr
     };
 
     wxFileHandle(const wxString& filename, OpenMode mode, int flags = 0)
     {
+        // be careful and use FILE_{READ,WRITE}_ATTRIBUTES here instead of the
+        // usual GENERIC_{READ,WRITE} as we don't want the file access time to
+        // be changed when we open it because this class is used for setting
+        // access time (see #10567)
         m_hFile = ::CreateFile
                     (
                      filename.fn_str(),             // name
-                     mode == Read ? GENERIC_READ    // access mask
-                                  : GENERIC_WRITE,
+                     mode == ReadAttr ? FILE_READ_ATTRIBUTES    // access mask
+                                      : FILE_WRITE_ATTRIBUTES,
                      FILE_SHARE_READ |              // sharing mode
                      FILE_SHARE_WRITE,              // (allow everything)
                      NULL,                          // no secutity attr
@@ -181,7 +185,7 @@ public:
 
         if ( m_hFile == INVALID_HANDLE_VALUE )
         {
-            if ( mode == Read )
+            if ( mode == ReadAttr )
             {
                 wxLogSysError(_("Failed to open '%s' for reading"),
                               filename.c_str());
@@ -2331,7 +2335,7 @@ bool wxFileName::SetTimes(const wxDateTime *dtAccess,
         flags = 0;
     }
 
-    wxFileHandle fh(path, wxFileHandle::Write, flags);
+    wxFileHandle fh(path, wxFileHandle::WriteAttr, flags);
     if ( fh.IsOk() )
     {
         if ( ::SetFileTime(fh,
@@ -2415,7 +2419,7 @@ bool wxFileName::GetTimes(wxDateTime *dtAccess,
     }
     else // file
     {
-        wxFileHandle fh(GetFullPath(), wxFileHandle::Read);
+        wxFileHandle fh(GetFullPath(), wxFileHandle::ReadAttr);
         if ( fh.IsOk() )
         {
             ok = ::GetFileTime(fh,
@@ -2485,7 +2489,7 @@ wxULongLong wxFileName::GetSize(const wxString &filename)
     // TODO
     return wxInvalidSize;
 #elif defined(__WIN32__)
-    wxFileHandle f(filename, wxFileHandle::Read);
+    wxFileHandle f(filename, wxFileHandle::ReadAttr);
     if (!f.IsOk())
         return wxInvalidSize;