diff options
| author | 2021-06-11 02:20:36 -0400 | |
|---|---|---|
| committer | 2021-06-12 01:39:07 -0400 | |
| commit | c978f3144cae1a59a612088aa99752bc74cf9e03 (patch) | |
| tree | a3d41920a0f2a99dcf6506f4a7e503a2ce306a3c | |
| parent | Merge pull request #6453 from lat9nq/libusb-fix-msvc (diff) | |
| download | yuzu-c978f3144cae1a59a612088aa99752bc74cf9e03.tar.gz yuzu-c978f3144cae1a59a612088aa99752bc74cf9e03.tar.xz yuzu-c978f3144cae1a59a612088aa99752bc74cf9e03.zip | |
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 '')
| -rw-r--r-- | src/common/fs/fs.cpp | 18 |
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) { | |||
| 321 | 321 | ||
| 322 | std::error_code ec; | 322 | std::error_code ec; |
| 323 | 323 | ||
| 324 | for (const auto& entry : fs::recursive_directory_iterator(path, ec)) { | 324 | // TODO (Morph): Replace this with recursive_directory_iterator once it's fixed in MSVC. |
| 325 | for (const auto& entry : fs::directory_iterator(path, ec)) { | ||
| 325 | if (ec) { | 326 | if (ec) { |
| 326 | LOG_ERROR(Common_Filesystem, | 327 | LOG_ERROR(Common_Filesystem, |
| 327 | "Failed to completely enumerate the directory at path={}, ec_message={}", | 328 | "Failed to completely enumerate the directory at path={}, ec_message={}", |
| @@ -337,6 +338,12 @@ bool RemoveDirContentsRecursively(const fs::path& path) { | |||
| 337 | PathToUTF8String(entry.path()), ec.message()); | 338 | PathToUTF8String(entry.path()), ec.message()); |
| 338 | break; | 339 | break; |
| 339 | } | 340 | } |
| 341 | |||
| 342 | // TODO (Morph): Remove this when MSVC fixes recursive_directory_iterator. | ||
| 343 | // recursive_directory_iterator throws an exception despite passing in a std::error_code. | ||
| 344 | if (entry.status().type() == fs::file_type::directory) { | ||
| 345 | return RemoveDirContentsRecursively(entry.path()); | ||
| 346 | } | ||
| 340 | } | 347 | } |
| 341 | 348 | ||
| 342 | if (ec) { | 349 | if (ec) { |
| @@ -475,7 +482,8 @@ void IterateDirEntriesRecursively(const std::filesystem::path& path, | |||
| 475 | 482 | ||
| 476 | std::error_code ec; | 483 | std::error_code ec; |
| 477 | 484 | ||
| 478 | for (const auto& entry : fs::recursive_directory_iterator(path, ec)) { | 485 | // TODO (Morph): Replace this with recursive_directory_iterator once it's fixed in MSVC. |
| 486 | for (const auto& entry : fs::directory_iterator(path, ec)) { | ||
| 479 | if (ec) { | 487 | if (ec) { |
| 480 | break; | 488 | break; |
| 481 | } | 489 | } |
| @@ -495,6 +503,12 @@ void IterateDirEntriesRecursively(const std::filesystem::path& path, | |||
| 495 | break; | 503 | break; |
| 496 | } | 504 | } |
| 497 | } | 505 | } |
| 506 | |||
| 507 | // TODO (Morph): Remove this when MSVC fixes recursive_directory_iterator. | ||
| 508 | // recursive_directory_iterator throws an exception despite passing in a std::error_code. | ||
| 509 | if (entry.status().type() == fs::file_type::directory) { | ||
| 510 | IterateDirEntriesRecursively(entry.path(), callback, filter); | ||
| 511 | } | ||
| 498 | } | 512 | } |
| 499 | 513 | ||
| 500 | if (callback_error || ec) { | 514 | if (callback_error || ec) { |