Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions stl/inc/filesystem
Original file line number Diff line number Diff line change
Expand Up @@ -2111,12 +2111,14 @@ namespace filesystem {
directory_entry(const directory_entry&) = default;
directory_entry(directory_entry&&) noexcept = default;
explicit directory_entry(const filesystem::path& _Path_arg) : _Cached_data{}, _Path(_Path_arg) {
(void) _Refresh(_Cached_data, _Path);
refresh();
}

directory_entry(const filesystem::path& _Path_arg, error_code& _Ec) : _Cached_data{}, _Path(_Path_arg) {
_Ec.clear();
(void) _Refresh(_Cached_data, _Path);
refresh(_Ec);
if (_Ec) {
_Path.clear();
}
}

~directory_entry() = default;
Expand All @@ -2128,35 +2130,39 @@ namespace filesystem {
// [fs.dir.entry.mods], modifiers
void assign(const filesystem::path& _Path_arg) {
_Path.assign(_Path_arg);
(void) _Refresh(_Cached_data, _Path);
refresh();
}

void assign(const filesystem::path& _Path_arg, error_code& _Ec) {
_Ec.clear(); // for exception safety
_Path.assign(_Path_arg);
(void) _Refresh(_Cached_data, _Path);
refresh(_Ec);
}

void replace_filename(const filesystem::path& _Path_arg) {
_Path.replace_filename(_Path_arg);
(void) _Refresh(_Cached_data, _Path);
refresh();
}

void replace_filename(const filesystem::path& _Path_arg, error_code& _Ec) {
_Ec.clear(); // for exception safety
_Path.replace_filename(_Path_arg);
(void) _Refresh(_Cached_data, _Path);
refresh(_Ec);
}

void refresh() {
const auto _Error = _Refresh(_Cached_data, _Path);
if (_Error != __std_win_error::_Success) {
if (_Error != __std_win_error::_Success && !__std_is_file_not_found(_Error)) {
_Throw_fs_error("directory_entry::refresh", _Error, _Path);
}
}

void refresh(error_code& _Ec) noexcept {
_Ec = _Make_ec(_Refresh(_Cached_data, _Path));
_Ec.clear();
const auto _Error = _Refresh(_Cached_data, _Path);
if (_Error != __std_win_error::_Success && !__std_is_file_not_found(_Error)) {
_Ec = _Make_ec(_Error);
}
}

#if _HAS_CXX20
Expand Down
6 changes: 5 additions & 1 deletion tests/std/tests/P0218R1_filesystem/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,11 @@ void test_directory_entry() {
EXPECT(!nonexistentEntryEc.exists());
EXPECT(good(ec));

EXPECT(throws_filesystem_error([&] { nonexistentEntryEc.refresh(); }, "directory_entry::refresh", nonexistent));
// Also test GH-232 "<filesystem>: directory_entry(const path& p, error_code& ec) does not return error code"
nonexistentEntry.refresh();

nonexistentEntryEc.refresh(ec);
EXPECT(good(ec));
}

directory_entry goodEntry(filePath, ec);
Expand Down