Opened 8 years ago
Last modified 8 years ago
#11037 new Bugs
last_write_time doesn't work on Windows on files with custom access rights
Reported by: | anonymous | Owned by: | Beman Dawes |
---|---|---|---|
Milestone: | To Be Determined | Component: | filesystem |
Version: | Boost 1.55.0 | Severity: | Problem |
Keywords: | Cc: |
Description
last_write_time uses CreateFile internally with some minimal rights. Anyway, it doesn't have rights to read the last write time of "System Volume Information", even though such data are available i.e. for Windows Explorer. The right way to get descriptor for such file or folder is FindFirstFile.
Here's an example based on the answer from StackOverflow by Hans Passant:
std::size_t last_write_time(boost::filesystem::path const & path) {
WIN32_FIND_DATAW info; auto hdl = FindFirstFileW(path.wstring().c_str(), &info); if (hdl == INVALID_HANDLE_VALUE) return std::time_t(-1); std::time_t retval = to_time_t(info.ftLastWriteTime); FindClose(hdl); better use BOOST_SCOPE_EXIT two lines higher return retval;
}
Sorry, I've been expecting Markdown, not WikiFormatting. Anyway, code is still pretty readable :)