summaryrefslogtreecommitdiff
path: root/Source/Core/Common/FileUtil.cpp
diff options
context:
space:
mode:
authorScott Mansell <phiren@gmail.com>2016-04-25 18:03:39 +1200
committerScott Mansell <phiren@gmail.com>2016-04-25 18:28:38 +1200
commitb2f133d2ac74e073a76367e18abe051abad5bbc1 (patch)
tree3c4afa2bda9ca851e96895b8d5f550518a2b5c39 /Source/Core/Common/FileUtil.cpp
parent3033096223de1a212d475cd670705c00daeba88d (diff)
make DeleteDirRecursively clean up correctly after failure.
Fixes Metroid prime crashing the second boot after loading a save state (issue 9496)
Diffstat (limited to 'Source/Core/Common/FileUtil.cpp')
-rw-r--r--Source/Core/Common/FileUtil.cpp21
1 files changed, 9 insertions, 12 deletions
diff --git a/Source/Core/Common/FileUtil.cpp b/Source/Core/Common/FileUtil.cpp
index 5084bf545b..c4563c397f 100644
--- a/Source/Core/Common/FileUtil.cpp
+++ b/Source/Core/Common/FileUtil.cpp
@@ -530,6 +530,8 @@ FSTEntry ScanDirectoryTree(const std::string& directory, bool recursive)
bool DeleteDirRecursively(const std::string& directory)
{
INFO_LOG(COMMON, "DeleteDirRecursively: %s", directory.c_str());
+ bool success = true;
+
#ifdef _WIN32
// Find the first file in the directory.
WIN32_FIND_DATA ffd;
@@ -568,22 +570,16 @@ bool DeleteDirRecursively(const std::string& directory)
{
if (!DeleteDirRecursively(newPath))
{
- #ifndef _WIN32
- closedir(dirp);
- #endif
-
- return false;
+ success = false;
+ break;
}
}
else
{
if (!File::Delete(newPath))
{
- #ifndef _WIN32
- closedir(dirp);
- #endif
-
- return false;
+ success = false;
+ break;
}
}
@@ -594,9 +590,10 @@ bool DeleteDirRecursively(const std::string& directory)
}
closedir(dirp);
#endif
- File::DeleteDir(directory);
+ if (success)
+ File::DeleteDir(directory);
- return true;
+ return success;
}
// Create directory and copy contents (does not overwrite existing files)