From c814ad9fc846de446a08831fc7a878265a28714f Mon Sep 17 00:00:00 2001 From: Hamid Reza Arzaghi Date: Mon, 5 Oct 2020 22:30:21 +0330 Subject: [PATCH 01/15] fix error_code on directory_entry constructor --- stl/inc/filesystem | 5 ++++- tests/std/tests/P0218R1_filesystem/test.cpp | 6 ++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/stl/inc/filesystem b/stl/inc/filesystem index 948ac146e73..a8a3f7d3d08 100644 --- a/stl/inc/filesystem +++ b/stl/inc/filesystem @@ -2139,7 +2139,10 @@ namespace filesystem { 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; diff --git a/tests/std/tests/P0218R1_filesystem/test.cpp b/tests/std/tests/P0218R1_filesystem/test.cpp index 0ff4f084c32..2f09fbf853e 100644 --- a/tests/std/tests/P0218R1_filesystem/test.cpp +++ b/tests/std/tests/P0218R1_filesystem/test.cpp @@ -994,12 +994,10 @@ void test_directory_entry() { EXPECT(!nonexistentEntry.exists()); directory_entry nonexistentEntryEc(nonexistent, ec); - EXPECT(nonexistentEntryEc.path() == nonexistent); + EXPECT(nonexistentEntryEc.path() == path()); // Test VSO-892890 "std::filesystem::directory_entry constructor initializes wrong state" EXPECT(!nonexistentEntryEc.exists()); - EXPECT(good(ec)); - - EXPECT(throws_filesystem_error([&] { nonexistentEntryEc.refresh(); }, "directory_entry::refresh", nonexistent)); + EXPECT(bad(ec)); } directory_entry goodEntry(filePath, ec); From eee1397ba55e39104d390ac795e1858baf8828c8 Mon Sep 17 00:00:00 2001 From: Hamid Reza Arzaghi Date: Tue, 6 Oct 2020 01:00:17 +0330 Subject: [PATCH 02/15] fix similar issue in some other functions --- stl/inc/filesystem | 6 +++--- tests/std/tests/P0218R1_filesystem/test.cpp | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/stl/inc/filesystem b/stl/inc/filesystem index a8a3f7d3d08..448ec7d07d0 100644 --- a/stl/inc/filesystem +++ b/stl/inc/filesystem @@ -2160,7 +2160,7 @@ namespace filesystem { 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) { @@ -2171,7 +2171,7 @@ namespace filesystem { 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() { @@ -2202,7 +2202,7 @@ namespace filesystem { return _Path; } - operator const filesystem::path &() const noexcept { + operator const filesystem::path&() const noexcept { return _Path; } diff --git a/tests/std/tests/P0218R1_filesystem/test.cpp b/tests/std/tests/P0218R1_filesystem/test.cpp index 2f09fbf853e..29f4905991d 100644 --- a/tests/std/tests/P0218R1_filesystem/test.cpp +++ b/tests/std/tests/P0218R1_filesystem/test.cpp @@ -1214,10 +1214,10 @@ void test_directory_entry() { for (auto&& nonexistent : nonexistentPaths) { cachingEntry.assign(nonexistent); // no fail cachingEntry.assign(nonexistent, ec); - EXPECT(good(ec)); + EXPECT(bad(ec)); cachingEntry.replace_filename(L"Exist2"sv); // no fail cachingEntry.replace_filename(L"Exist2"sv, ec); - EXPECT(good(ec)); + EXPECT(bad(ec)); } remove(changingPath, ec); From 02ad81c74b594e69220b5e9a17e282b1b81e128e Mon Sep 17 00:00:00 2001 From: Hamid Reza Arzaghi Date: Tue, 6 Oct 2020 01:17:24 +0330 Subject: [PATCH 03/15] add empty line --- stl/inc/filesystem | 1 + 1 file changed, 1 insertion(+) diff --git a/stl/inc/filesystem b/stl/inc/filesystem index 448ec7d07d0..0c26daae1ad 100644 --- a/stl/inc/filesystem +++ b/stl/inc/filesystem @@ -4379,3 +4379,4 @@ _STL_RESTORE_CLANG_WARNINGS #endif // _HAS_CXX17 #endif // _STL_COMPILER_PREPROCESSOR #endif // _FILESYSTEM_ + From dca45f37de91c4a1d0b784402e4e29ca8396c51a Mon Sep 17 00:00:00 2001 From: Hamid Reza Arzaghi Date: Tue, 6 Oct 2020 01:18:18 +0330 Subject: [PATCH 04/15] try trigger Azure pipeline --- stl/inc/filesystem | 1 - 1 file changed, 1 deletion(-) diff --git a/stl/inc/filesystem b/stl/inc/filesystem index 0c26daae1ad..448ec7d07d0 100644 --- a/stl/inc/filesystem +++ b/stl/inc/filesystem @@ -4379,4 +4379,3 @@ _STL_RESTORE_CLANG_WARNINGS #endif // _HAS_CXX17 #endif // _STL_COMPILER_PREPROCESSOR #endif // _FILESYSTEM_ - From b44a978ef9e4ea955063466d1e02fc7abcc9e1e8 Mon Sep 17 00:00:00 2001 From: Hamid Reza Arzaghi Date: Tue, 6 Oct 2020 01:25:08 +0330 Subject: [PATCH 05/15] clang format --- stl/inc/filesystem | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stl/inc/filesystem b/stl/inc/filesystem index 448ec7d07d0..67da1384364 100644 --- a/stl/inc/filesystem +++ b/stl/inc/filesystem @@ -2202,7 +2202,7 @@ namespace filesystem { return _Path; } - operator const filesystem::path&() const noexcept { + operator const filesystem::path &() const noexcept { return _Path; } From e3c3a396b890626f4c6e775276173a66eeaf9fc8 Mon Sep 17 00:00:00 2001 From: Hamid Reza Arzaghi Date: Tue, 6 Oct 2020 21:15:17 +0330 Subject: [PATCH 06/15] Update test.cpp --- tests/std/tests/P0218R1_filesystem/test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/std/tests/P0218R1_filesystem/test.cpp b/tests/std/tests/P0218R1_filesystem/test.cpp index 29f4905991d..7cf7db95cc4 100644 --- a/tests/std/tests/P0218R1_filesystem/test.cpp +++ b/tests/std/tests/P0218R1_filesystem/test.cpp @@ -994,7 +994,7 @@ void test_directory_entry() { EXPECT(!nonexistentEntry.exists()); directory_entry nonexistentEntryEc(nonexistent, ec); - EXPECT(nonexistentEntryEc.path() == path()); + EXPECT(nonexistentEntryEc.path() == path{}); // Test VSO-892890 "std::filesystem::directory_entry constructor initializes wrong state" EXPECT(!nonexistentEntryEc.exists()); EXPECT(bad(ec)); From b78a0d75bcdf8082dbbabd56d913979ba6f03a5b Mon Sep 17 00:00:00 2001 From: Hamid Reza Arzaghi Date: Wed, 16 Dec 2020 04:53:05 +0330 Subject: [PATCH 07/15] Follow the Standard in non-error_code methods --- stl/inc/filesystem | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stl/inc/filesystem b/stl/inc/filesystem index 67da1384364..99563d79552 100644 --- a/stl/inc/filesystem +++ b/stl/inc/filesystem @@ -2134,7 +2134,7 @@ 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) { @@ -2154,7 +2154,7 @@ 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) { @@ -2165,7 +2165,7 @@ namespace filesystem { 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) { From af7f57ec3342b6a10aa0784f02a8ca246ea2efe2 Mon Sep 17 00:00:00 2001 From: Hamid Reza Arzaghi Date: Wed, 16 Dec 2020 04:55:35 +0330 Subject: [PATCH 08/15] Modify some tests to match with the Standard expectations --- tests/std/tests/P0218R1_filesystem/test.cpp | 67 ++++++++++++--------- 1 file changed, 39 insertions(+), 28 deletions(-) diff --git a/tests/std/tests/P0218R1_filesystem/test.cpp b/tests/std/tests/P0218R1_filesystem/test.cpp index 7cf7db95cc4..52699802992 100644 --- a/tests/std/tests/P0218R1_filesystem/test.cpp +++ b/tests/std/tests/P0218R1_filesystem/test.cpp @@ -988,14 +988,11 @@ void test_directory_entry() { EXPECT(!default_entry.exists()); for (auto&& nonexistent : nonexistentPaths) { - directory_entry nonexistentEntry(nonexistent); - EXPECT(nonexistentEntry.path() == nonexistent); - // Test VSO-892890 "std::filesystem::directory_entry constructor initializes wrong state" - EXPECT(!nonexistentEntry.exists()); + EXPECT( + throws_filesystem_error([&] { directory_entry nonexistentEntry(nonexistent); }, "refresh"sv, nonexistent)); directory_entry nonexistentEntryEc(nonexistent, ec); EXPECT(nonexistentEntryEc.path() == path{}); - // Test VSO-892890 "std::filesystem::directory_entry constructor initializes wrong state" EXPECT(!nonexistentEntryEc.exists()); EXPECT(bad(ec)); } @@ -1158,20 +1155,22 @@ void test_directory_entry() { EXPECT(bEntry >= aEntry); EXPECT(aEntry >= aEntry); - directory_entry cachingEntry(cachePath); + // cachePath does not exist. So cachingEntry should remain empty: + directory_entry cachingEntry(cachePath, ec); + EXPECT(bad(ec)); // here, we are not cached: EXPECT(cachingEntry.file_size(ec) == static_cast(-1)); EXPECT(bad(ec)); - // assert that the above error was not cached: + // assert that directory_entry does not initilized and nothing cached: create_file_containing(cachePath, L"abcdef"); - EXPECT(cachingEntry.file_size(ec) == 6); - EXPECT(good(ec)); - EXPECT(cachingEntry.last_write_time(ec) != file_time_type::min()); - EXPECT(good(ec)); - EXPECT(cachingEntry.hard_link_count(ec) != static_cast(-1)); - EXPECT(good(ec)); - EXPECT(cachingEntry.is_regular_file(ec)); - EXPECT(good(ec)); + EXPECT(cachingEntry.file_size(ec) == static_cast(-1)); + EXPECT(bad(ec)); + EXPECT(cachingEntry.last_write_time(ec) == file_time_type::min()); + EXPECT(bad(ec)); + EXPECT(cachingEntry.hard_link_count(ec) == static_cast(-1)); + EXPECT(bad(ec)); + EXPECT(cachingEntry.is_regular_file(ec) == false); + EXPECT(bad(ec)); // assert that none of the above accesses restored caching: remove(cachePath, ec); EXPECT(good(ec)); @@ -1185,18 +1184,19 @@ void test_directory_entry() { EXPECT(bad(ec)); // restore caching: create_file_containing(cachePath, L"abcdef"); - cachingEntry.refresh(); + cachingEntry.refresh(ec); + EXPECT(bad(ec)); remove(cachePath, ec); EXPECT(good(ec)); // assert that the following succeed because the values are cached, even though the file is gone - EXPECT(cachingEntry.file_size(ec) == 6); - EXPECT(good(ec)); - EXPECT(cachingEntry.last_write_time(ec) != file_time_type::min()); - EXPECT(good(ec)); - EXPECT(cachingEntry.hard_link_count(ec) != static_cast(-1)); - EXPECT(good(ec)); - EXPECT(cachingEntry.is_regular_file(ec)); - EXPECT(good(ec)); + EXPECT(cachingEntry.file_size(ec) == static_cast(-1)); + EXPECT(bad(ec)); + EXPECT(cachingEntry.last_write_time(ec) == file_time_type::min()); + EXPECT(bad(ec)); + EXPECT(cachingEntry.hard_link_count(ec) == static_cast(-1)); + EXPECT(bad(ec)); + EXPECT(cachingEntry.is_regular_file(ec) == false); + EXPECT(bad(ec)); #if _HAS_CXX20 // break caching again, and assert that things aren't cached cachingEntry.clear_cache(); @@ -1210,14 +1210,25 @@ void test_directory_entry() { EXPECT(bad(ec)); #endif // _HAS_CXX20 - // assert that mutating the path doesn't fail even though the target doesn't exist + // assert that mutating the path to a non-existing target change the path and then fail for (auto&& nonexistent : nonexistentPaths) { - cachingEntry.assign(nonexistent); // no fail + EXPECT(throws_filesystem_error([&] { cachingEntry.assign(nonexistent); }, "refresh"sv, nonexistent)); + EXPECT(cachingEntry.path() == nonexistent); + cachingEntry.assign("reset the path", ec); + EXPECT(bad(ec)); cachingEntry.assign(nonexistent, ec); EXPECT(bad(ec)); - cachingEntry.replace_filename(L"Exist2"sv); // no fail - cachingEntry.replace_filename(L"Exist2"sv, ec); + EXPECT(cachingEntry.path() == nonexistent); + + path otherPath = nonexistent; + otherPath.replace_filename(L"Exist2"sv); + EXPECT(throws_filesystem_error( + [&] { cachingEntry.replace_filename(otherPath.filename().c_str()); }, "refresh"sv, otherPath.c_str())); + EXPECT(cachingEntry.path() == otherPath); + otherPath.replace_filename(L"Exist3"sv); + cachingEntry.replace_filename(otherPath.filename().c_str(), ec); EXPECT(bad(ec)); + EXPECT(cachingEntry.path() == otherPath); } remove(changingPath, ec); From 4c23fcf94c9a8375aa4ed7549992091f7bc064bf Mon Sep 17 00:00:00 2001 From: Hamid Reza Arzaghi Date: Wed, 16 Dec 2020 15:32:36 +0330 Subject: [PATCH 09/15] add an empty line --- tests/std/tests/P0218R1_filesystem/test.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/std/tests/P0218R1_filesystem/test.cpp b/tests/std/tests/P0218R1_filesystem/test.cpp index 52699802992..0f639fd2a31 100644 --- a/tests/std/tests/P0218R1_filesystem/test.cpp +++ b/tests/std/tests/P0218R1_filesystem/test.cpp @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + #define _SILENCE_CXX20_U8PATH_DEPRECATION_WARNING #include #include From cb918a8564274b64ec34c71fc853bf4551cf5ad2 Mon Sep 17 00:00:00 2001 From: Hamid Reza Arzaghi Date: Wed, 16 Dec 2020 15:33:40 +0330 Subject: [PATCH 10/15] try to re-trigger the Azure pipeline --- tests/std/tests/P0218R1_filesystem/test.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/std/tests/P0218R1_filesystem/test.cpp b/tests/std/tests/P0218R1_filesystem/test.cpp index 0f639fd2a31..52699802992 100644 --- a/tests/std/tests/P0218R1_filesystem/test.cpp +++ b/tests/std/tests/P0218R1_filesystem/test.cpp @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - #define _SILENCE_CXX20_U8PATH_DEPRECATION_WARNING #include #include From 888d39b72f8b9342e73dbdf9ba75510723846963 Mon Sep 17 00:00:00 2001 From: Hamid Reza Arzaghi Date: Fri, 18 Dec 2020 02:44:15 +0330 Subject: [PATCH 11/15] Revert wrong modifications in tests --- tests/std/tests/P0218R1_filesystem/test.cpp | 67 +++++++++------------ 1 file changed, 28 insertions(+), 39 deletions(-) diff --git a/tests/std/tests/P0218R1_filesystem/test.cpp b/tests/std/tests/P0218R1_filesystem/test.cpp index 52699802992..7cf7db95cc4 100644 --- a/tests/std/tests/P0218R1_filesystem/test.cpp +++ b/tests/std/tests/P0218R1_filesystem/test.cpp @@ -988,11 +988,14 @@ void test_directory_entry() { EXPECT(!default_entry.exists()); for (auto&& nonexistent : nonexistentPaths) { - EXPECT( - throws_filesystem_error([&] { directory_entry nonexistentEntry(nonexistent); }, "refresh"sv, nonexistent)); + directory_entry nonexistentEntry(nonexistent); + EXPECT(nonexistentEntry.path() == nonexistent); + // Test VSO-892890 "std::filesystem::directory_entry constructor initializes wrong state" + EXPECT(!nonexistentEntry.exists()); directory_entry nonexistentEntryEc(nonexistent, ec); EXPECT(nonexistentEntryEc.path() == path{}); + // Test VSO-892890 "std::filesystem::directory_entry constructor initializes wrong state" EXPECT(!nonexistentEntryEc.exists()); EXPECT(bad(ec)); } @@ -1155,22 +1158,20 @@ void test_directory_entry() { EXPECT(bEntry >= aEntry); EXPECT(aEntry >= aEntry); - // cachePath does not exist. So cachingEntry should remain empty: - directory_entry cachingEntry(cachePath, ec); - EXPECT(bad(ec)); + directory_entry cachingEntry(cachePath); // here, we are not cached: EXPECT(cachingEntry.file_size(ec) == static_cast(-1)); EXPECT(bad(ec)); - // assert that directory_entry does not initilized and nothing cached: + // assert that the above error was not cached: create_file_containing(cachePath, L"abcdef"); - EXPECT(cachingEntry.file_size(ec) == static_cast(-1)); - EXPECT(bad(ec)); - EXPECT(cachingEntry.last_write_time(ec) == file_time_type::min()); - EXPECT(bad(ec)); - EXPECT(cachingEntry.hard_link_count(ec) == static_cast(-1)); - EXPECT(bad(ec)); - EXPECT(cachingEntry.is_regular_file(ec) == false); - EXPECT(bad(ec)); + EXPECT(cachingEntry.file_size(ec) == 6); + EXPECT(good(ec)); + EXPECT(cachingEntry.last_write_time(ec) != file_time_type::min()); + EXPECT(good(ec)); + EXPECT(cachingEntry.hard_link_count(ec) != static_cast(-1)); + EXPECT(good(ec)); + EXPECT(cachingEntry.is_regular_file(ec)); + EXPECT(good(ec)); // assert that none of the above accesses restored caching: remove(cachePath, ec); EXPECT(good(ec)); @@ -1184,19 +1185,18 @@ void test_directory_entry() { EXPECT(bad(ec)); // restore caching: create_file_containing(cachePath, L"abcdef"); - cachingEntry.refresh(ec); - EXPECT(bad(ec)); + cachingEntry.refresh(); remove(cachePath, ec); EXPECT(good(ec)); // assert that the following succeed because the values are cached, even though the file is gone - EXPECT(cachingEntry.file_size(ec) == static_cast(-1)); - EXPECT(bad(ec)); - EXPECT(cachingEntry.last_write_time(ec) == file_time_type::min()); - EXPECT(bad(ec)); - EXPECT(cachingEntry.hard_link_count(ec) == static_cast(-1)); - EXPECT(bad(ec)); - EXPECT(cachingEntry.is_regular_file(ec) == false); - EXPECT(bad(ec)); + EXPECT(cachingEntry.file_size(ec) == 6); + EXPECT(good(ec)); + EXPECT(cachingEntry.last_write_time(ec) != file_time_type::min()); + EXPECT(good(ec)); + EXPECT(cachingEntry.hard_link_count(ec) != static_cast(-1)); + EXPECT(good(ec)); + EXPECT(cachingEntry.is_regular_file(ec)); + EXPECT(good(ec)); #if _HAS_CXX20 // break caching again, and assert that things aren't cached cachingEntry.clear_cache(); @@ -1210,25 +1210,14 @@ void test_directory_entry() { EXPECT(bad(ec)); #endif // _HAS_CXX20 - // assert that mutating the path to a non-existing target change the path and then fail + // assert that mutating the path doesn't fail even though the target doesn't exist for (auto&& nonexistent : nonexistentPaths) { - EXPECT(throws_filesystem_error([&] { cachingEntry.assign(nonexistent); }, "refresh"sv, nonexistent)); - EXPECT(cachingEntry.path() == nonexistent); - cachingEntry.assign("reset the path", ec); - EXPECT(bad(ec)); + cachingEntry.assign(nonexistent); // no fail cachingEntry.assign(nonexistent, ec); EXPECT(bad(ec)); - EXPECT(cachingEntry.path() == nonexistent); - - path otherPath = nonexistent; - otherPath.replace_filename(L"Exist2"sv); - EXPECT(throws_filesystem_error( - [&] { cachingEntry.replace_filename(otherPath.filename().c_str()); }, "refresh"sv, otherPath.c_str())); - EXPECT(cachingEntry.path() == otherPath); - otherPath.replace_filename(L"Exist3"sv); - cachingEntry.replace_filename(otherPath.filename().c_str(), ec); + cachingEntry.replace_filename(L"Exist2"sv); // no fail + cachingEntry.replace_filename(L"Exist2"sv, ec); EXPECT(bad(ec)); - EXPECT(cachingEntry.path() == otherPath); } remove(changingPath, ec); From e95a83a486159a0a01a978847bb200da72ff1478 Mon Sep 17 00:00:00 2001 From: Hamid Reza Arzaghi Date: Fri, 18 Dec 2020 04:37:19 +0330 Subject: [PATCH 12/15] Modify refersh --- stl/inc/filesystem | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stl/inc/filesystem b/stl/inc/filesystem index 99563d79552..6ecff22bc17 100644 --- a/stl/inc/filesystem +++ b/stl/inc/filesystem @@ -2176,7 +2176,7 @@ namespace filesystem { 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) == false) { _Throw_fs_error("directory_entry::refresh", _Error, _Path); } } From f1f827e30a26c92afee0ac864229aa6d7ba77b91 Mon Sep 17 00:00:00 2001 From: Hamid Reza Arzaghi Date: Sat, 19 Dec 2020 20:04:27 +0330 Subject: [PATCH 13/15] refresh() and refresh(ec) should behave identically --- stl/inc/filesystem | 7 +++++-- tests/std/tests/P0218R1_filesystem/test.cpp | 8 ++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/stl/inc/filesystem b/stl/inc/filesystem index 6ecff22bc17..94522b6922d 100644 --- a/stl/inc/filesystem +++ b/stl/inc/filesystem @@ -2138,7 +2138,6 @@ namespace filesystem { } directory_entry(const filesystem::path& _Path_arg, error_code& _Ec) : _Cached_data{}, _Path(_Path_arg) { - _Ec.clear(); refresh(_Ec); if (_Ec) { _Path.clear(); @@ -2182,7 +2181,11 @@ namespace filesystem { } 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) == false) { + _Ec = _Make_ec(_Error); + } } #if _HAS_CXX20 diff --git a/tests/std/tests/P0218R1_filesystem/test.cpp b/tests/std/tests/P0218R1_filesystem/test.cpp index 7cf7db95cc4..9ed9b7a24a3 100644 --- a/tests/std/tests/P0218R1_filesystem/test.cpp +++ b/tests/std/tests/P0218R1_filesystem/test.cpp @@ -994,10 +994,10 @@ void test_directory_entry() { EXPECT(!nonexistentEntry.exists()); directory_entry nonexistentEntryEc(nonexistent, ec); - EXPECT(nonexistentEntryEc.path() == path{}); + EXPECT(nonexistentEntryEc.path() == nonexistent); // Test VSO-892890 "std::filesystem::directory_entry constructor initializes wrong state" EXPECT(!nonexistentEntryEc.exists()); - EXPECT(bad(ec)); + EXPECT(good(ec)); } directory_entry goodEntry(filePath, ec); @@ -1214,10 +1214,10 @@ void test_directory_entry() { for (auto&& nonexistent : nonexistentPaths) { cachingEntry.assign(nonexistent); // no fail cachingEntry.assign(nonexistent, ec); - EXPECT(bad(ec)); + EXPECT(good(ec)); cachingEntry.replace_filename(L"Exist2"sv); // no fail cachingEntry.replace_filename(L"Exist2"sv, ec); - EXPECT(bad(ec)); + EXPECT(good(ec)); } remove(changingPath, ec); From af7aed338d4d3c5b81a0b5c8996f348a6f014a12 Mon Sep 17 00:00:00 2001 From: Hamid Reza Arzaghi Date: Thu, 2 Jun 2022 11:59:07 +0800 Subject: [PATCH 14/15] Apply suggestions from code review Co-authored-by: nicole mazzuca <83086508+strega-nil-ms@users.noreply.github.com> --- stl/inc/filesystem | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stl/inc/filesystem b/stl/inc/filesystem index 94522b6922d..c726529576c 100644 --- a/stl/inc/filesystem +++ b/stl/inc/filesystem @@ -2175,7 +2175,7 @@ namespace filesystem { void refresh() { const auto _Error = _Refresh(_Cached_data, _Path); - if (_Error != __std_win_error::_Success && __std_is_file_not_found(_Error) == false) { + if (_Error != __std_win_error::_Success && !__std_is_file_not_found(_Error)) { _Throw_fs_error("directory_entry::refresh", _Error, _Path); } } @@ -2183,7 +2183,7 @@ namespace filesystem { void refresh(error_code& _Ec) noexcept { _Ec.clear(); const auto _Error = _Refresh(_Cached_data, _Path); - if (_Error != __std_win_error::_Success && __std_is_file_not_found(_Error) == false) { + if (_Error != __std_win_error::_Success && !__std_is_file_not_found(_Error)) { _Ec = _Make_ec(_Error); } } From caafcb937a170b9da9796ed5323438a3f5e37b5c Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Fri, 3 Jun 2022 20:24:07 -0700 Subject: [PATCH 15/15] Test refresh() and refresh(ec). --- tests/std/tests/P0218R1_filesystem/test.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/std/tests/P0218R1_filesystem/test.cpp b/tests/std/tests/P0218R1_filesystem/test.cpp index cb9ef2afc21..9140c01a10d 100644 --- a/tests/std/tests/P0218R1_filesystem/test.cpp +++ b/tests/std/tests/P0218R1_filesystem/test.cpp @@ -995,6 +995,12 @@ void test_directory_entry() { // Test VSO-892890 "std::filesystem::directory_entry constructor initializes wrong state" EXPECT(!nonexistentEntryEc.exists()); EXPECT(good(ec)); + + // Also test GH-232 ": 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);