This page is a snapshot from the LWG issues list, see theLibrary Active Issues List for more information and the meaning ofResolved status.
directory_entry::status is not allowed to be cached as a quality-of-implementation issueSection: 31.12.10.4[fs.dir.entry.obs]Status:ResolvedSubmitter: Billy O'NealOpened: 2016-03-03Last modified: 2020-09-06
Priority:2
View all otherissues in [fs.dir.entry.obs].
View all issues withResolved status.
Discussion:
To fix multi-threading problems indirectory_entry, caching behaviorwas removed from the type. This is bad for performance reasons,because the values can no longer be cached from the result ofreaddiron POSIX platforms, or fromFindFirstFile/FindNextFile on Windows.
It appears that the intent was to allow implementers to fill in thevalues fordirectory_entry::status insidedirectory_iterator, but ascurrently specified:
Returns:status(path()[, ec]).This is not allowed to be cached, because the target of the path canchange. For example, consider the following program:
#include <stdio.h>#include <stdlib.h>#include <filesystem>#include <fstream>using namespace std;namespace fs = ::std::filesystem;void verify(const bool b, const char * const msg) { if (!b) { printf("fail: %s\n", msg); exit(1); }}void touch_file(const char * const filename) { ofstream f(filename); f << '\n' << endl; verify(f.good(), "File write failed");}int main() { fs::remove_all("subDir"); fs::create_directory("subDir"); fs::create_directory("subDir/child"); touch_file("subDir/child/child"); fs::current_path("./subDir"); fs::directory_iterator dir("."); ++dir; fs::directory_entry entry = *dir; verify(entry == "./child", "unexpected subdirectory"); //enumerating "subDir" returned the directory "child" fs::file_status status = entry.status(); verify(status.type() == fs::file_type::directory, "subDir/child was not a directory"); fs::current_path("./child"); status = entry.status(); // REQUIRED to re-stat() on POSIX, // GetFileAttributes() on Windows verify(status.type() == fs::file_type::regular, "subDir/child/child was not a regular file"); return 0;}directory_entry should be re-specified to allow implementers to cache the value ofstatus(path) at the timeirectory_iterator was incremented to avoid repeatedstat() /GetFileAttributes calls. (This may mean additional constructors are necessary fordirectory_entry as well)
[2016-04, Issues Telecon]
Beman is working on a paper to address this.
[2016-08, Beman comments]
This will be resolved byP0317R1, Directory Entry Caching for Filesystem.
Fri AM: Moved to Tentatively Resolved
Proposed resolution: