From: Vadim Zeitlin Date: Tue, 24 Nov 2009 00:01:25 +0000 (+0000) Subject: Don't change file access time implicitly when setting it explicitly. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/f3c74c8df932f5cc610e836811086dfd91d29fc9?hp=a12bd55b0d412d2a557dc66f1a4aba1138471ee4 Don't change file access time implicitly when setting it explicitly. 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 --- diff --git a/src/common/filename.cpp b/src/common/filename.cpp index 09b31fd335..090850d8d8 100644 --- a/src/common/filename.cpp +++ b/src/common/filename.cpp @@ -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;