summaryrefslogtreecommitdiff
path: root/src/common/fs
diff options
context:
space:
mode:
authorMorph <39850852+Morph1984@users.noreply.github.com>2021-06-11 02:20:36 -0400
committerMorph <39850852+Morph1984@users.noreply.github.com>2021-06-12 01:39:07 -0400
commitc978f3144cae1a59a612088aa99752bc74cf9e03 (patch)
treea3d41920a0f2a99dcf6506f4a7e503a2ce306a3c /src/common/fs
parent8b5655a98e380a38436bb6002c55d9ba9cf8f16d (diff)
common: fs: Use the normal directory iterator in *Recursively functions
MSVC's implementation of recursive_directory_iterator throws an exception on an error despite a std::error_code being passed into its constructor. This is most likely a bug in MSVC's implementation since directory_iterator does not throw an exception on an error. We can replace the usage of recursive_directory_iterator for now until MSVC fixes their implementation of it.
Diffstat (limited to 'src/common/fs')
-rw-r--r--src/common/fs/fs.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/common/fs/fs.cpp b/src/common/fs/fs.cpp
index d492480d9..d3159e908 100644
--- a/src/common/fs/fs.cpp
+++ b/src/common/fs/fs.cpp
@@ -321,7 +321,8 @@ bool RemoveDirContentsRecursively(const fs::path& path) {
std::error_code ec;
- for (const auto& entry : fs::recursive_directory_iterator(path, ec)) {
+ // TODO (Morph): Replace this with recursive_directory_iterator once it's fixed in MSVC.
+ for (const auto& entry : fs::directory_iterator(path, ec)) {
if (ec) {
LOG_ERROR(Common_Filesystem,
"Failed to completely enumerate the directory at path={}, ec_message={}",
@@ -337,6 +338,12 @@ bool RemoveDirContentsRecursively(const fs::path& path) {
PathToUTF8String(entry.path()), ec.message());
break;
}
+
+ // TODO (Morph): Remove this when MSVC fixes recursive_directory_iterator.
+ // recursive_directory_iterator throws an exception despite passing in a std::error_code.
+ if (entry.status().type() == fs::file_type::directory) {
+ return RemoveDirContentsRecursively(entry.path());
+ }
}
if (ec) {
@@ -475,7 +482,8 @@ void IterateDirEntriesRecursively(const std::filesystem::path& path,
std::error_code ec;
- for (const auto& entry : fs::recursive_directory_iterator(path, ec)) {
+ // TODO (Morph): Replace this with recursive_directory_iterator once it's fixed in MSVC.
+ for (const auto& entry : fs::directory_iterator(path, ec)) {
if (ec) {
break;
}
@@ -495,6 +503,12 @@ void IterateDirEntriesRecursively(const std::filesystem::path& path,
break;
}
}
+
+ // TODO (Morph): Remove this when MSVC fixes recursive_directory_iterator.
+ // recursive_directory_iterator throws an exception despite passing in a std::error_code.
+ if (entry.status().type() == fs::file_type::directory) {
+ IterateDirEntriesRecursively(entry.path(), callback, filter);
+ }
}
if (callback_error || ec) {