diff options
| author | 2016-06-19 00:09:16 -0700 | |
|---|---|---|
| committer | 2016-06-19 00:12:15 -0700 | |
| commit | d6792632f0a426247167fc91c12c1f640748464f (patch) | |
| tree | acf52c2afb186071142991e852c9bda645f56c41 /src/common/file_util.cpp | |
| parent | Merge pull request #1877 from wwylele/wait-fix-timeout (diff) | |
| download | yuzu-d6792632f0a426247167fc91c12c1f640748464f.tar.gz yuzu-d6792632f0a426247167fc91c12c1f640748464f.tar.xz yuzu-d6792632f0a426247167fc91c12c1f640748464f.zip | |
Fix recursive scanning of directories
ForeachDirectoryEntry didn't actually do anything with the `recursive`
parameter, and the corresponding callback parameter was shadowing the
actual recursion counters in the user functions.
Diffstat (limited to 'src/common/file_util.cpp')
| -rw-r--r-- | src/common/file_util.cpp | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp index 17af7c385..84fe95c8c 100644 --- a/src/common/file_util.cpp +++ b/src/common/file_util.cpp | |||
| @@ -434,7 +434,7 @@ bool CreateEmptyFile(const std::string &filename) | |||
| 434 | } | 434 | } |
| 435 | 435 | ||
| 436 | 436 | ||
| 437 | bool ForeachDirectoryEntry(unsigned* num_entries_out, const std::string &directory, DirectoryEntryCallable callback, unsigned int recursion) | 437 | bool ForeachDirectoryEntry(unsigned* num_entries_out, const std::string &directory, DirectoryEntryCallable callback) |
| 438 | { | 438 | { |
| 439 | LOG_TRACE(Common_Filesystem, "directory %s", directory.c_str()); | 439 | LOG_TRACE(Common_Filesystem, "directory %s", directory.c_str()); |
| 440 | 440 | ||
| @@ -472,7 +472,7 @@ bool ForeachDirectoryEntry(unsigned* num_entries_out, const std::string &directo | |||
| 472 | continue; | 472 | continue; |
| 473 | 473 | ||
| 474 | unsigned ret_entries = 0; | 474 | unsigned ret_entries = 0; |
| 475 | if (!callback(&ret_entries, directory, virtual_name, recursion)) { | 475 | if (!callback(&ret_entries, directory, virtual_name)) { |
| 476 | callback_error = true; | 476 | callback_error = true; |
| 477 | break; | 477 | break; |
| 478 | } | 478 | } |
| @@ -497,10 +497,9 @@ bool ForeachDirectoryEntry(unsigned* num_entries_out, const std::string &directo | |||
| 497 | 497 | ||
| 498 | unsigned ScanDirectoryTree(const std::string &directory, FSTEntry& parent_entry, unsigned int recursion) | 498 | unsigned ScanDirectoryTree(const std::string &directory, FSTEntry& parent_entry, unsigned int recursion) |
| 499 | { | 499 | { |
| 500 | const auto callback = [&parent_entry](unsigned* num_entries_out, | 500 | const auto callback = [recursion, &parent_entry](unsigned* num_entries_out, |
| 501 | const std::string& directory, | 501 | const std::string& directory, |
| 502 | const std::string& virtual_name, | 502 | const std::string& virtual_name) -> bool { |
| 503 | unsigned int recursion) -> bool { | ||
| 504 | FSTEntry entry; | 503 | FSTEntry entry; |
| 505 | entry.virtualName = virtual_name; | 504 | entry.virtualName = virtual_name; |
| 506 | entry.physicalName = directory + DIR_SEP + virtual_name; | 505 | entry.physicalName = directory + DIR_SEP + virtual_name; |
| @@ -526,16 +525,15 @@ unsigned ScanDirectoryTree(const std::string &directory, FSTEntry& parent_entry, | |||
| 526 | }; | 525 | }; |
| 527 | 526 | ||
| 528 | unsigned num_entries; | 527 | unsigned num_entries; |
| 529 | return ForeachDirectoryEntry(&num_entries, directory, callback, recursion) ? num_entries : 0; | 528 | return ForeachDirectoryEntry(&num_entries, directory, callback) ? num_entries : 0; |
| 530 | } | 529 | } |
| 531 | 530 | ||
| 532 | 531 | ||
| 533 | bool DeleteDirRecursively(const std::string &directory, unsigned int recursion) | 532 | bool DeleteDirRecursively(const std::string &directory, unsigned int recursion) |
| 534 | { | 533 | { |
| 535 | const static auto callback = [](unsigned* num_entries_out, | 534 | const auto callback = [recursion](unsigned* num_entries_out, |
| 536 | const std::string& directory, | 535 | const std::string& directory, |
| 537 | const std::string& virtual_name, | 536 | const std::string& virtual_name) -> bool { |
| 538 | unsigned int recursion) -> bool { | ||
| 539 | std::string new_path = directory + DIR_SEP_CHR + virtual_name; | 537 | std::string new_path = directory + DIR_SEP_CHR + virtual_name; |
| 540 | 538 | ||
| 541 | if (IsDirectory(new_path)) { | 539 | if (IsDirectory(new_path)) { |
| @@ -546,7 +544,7 @@ bool DeleteDirRecursively(const std::string &directory, unsigned int recursion) | |||
| 546 | return Delete(new_path); | 544 | return Delete(new_path); |
| 547 | }; | 545 | }; |
| 548 | 546 | ||
| 549 | if (!ForeachDirectoryEntry(nullptr, directory, callback, recursion)) | 547 | if (!ForeachDirectoryEntry(nullptr, directory, callback)) |
| 550 | return false; | 548 | return false; |
| 551 | 549 | ||
| 552 | // Delete the outermost directory | 550 | // Delete the outermost directory |