make DeleteDirRecursively clean up correctly after failure.
Fixes Metroid prime crashing the second boot after loading a save state (issue 9496)
This commit is contained in:
parent
3033096223
commit
b2f133d2ac
|
@ -530,6 +530,8 @@ FSTEntry ScanDirectoryTree(const std::string& directory, bool recursive)
|
||||||
bool DeleteDirRecursively(const std::string& directory)
|
bool DeleteDirRecursively(const std::string& directory)
|
||||||
{
|
{
|
||||||
INFO_LOG(COMMON, "DeleteDirRecursively: %s", directory.c_str());
|
INFO_LOG(COMMON, "DeleteDirRecursively: %s", directory.c_str());
|
||||||
|
bool success = true;
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
// Find the first file in the directory.
|
// Find the first file in the directory.
|
||||||
WIN32_FIND_DATA ffd;
|
WIN32_FIND_DATA ffd;
|
||||||
|
@ -568,22 +570,16 @@ bool DeleteDirRecursively(const std::string& directory)
|
||||||
{
|
{
|
||||||
if (!DeleteDirRecursively(newPath))
|
if (!DeleteDirRecursively(newPath))
|
||||||
{
|
{
|
||||||
#ifndef _WIN32
|
success = false;
|
||||||
closedir(dirp);
|
break;
|
||||||
#endif
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!File::Delete(newPath))
|
if (!File::Delete(newPath))
|
||||||
{
|
{
|
||||||
#ifndef _WIN32
|
success = false;
|
||||||
closedir(dirp);
|
break;
|
||||||
#endif
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -594,9 +590,10 @@ bool DeleteDirRecursively(const std::string& directory)
|
||||||
}
|
}
|
||||||
closedir(dirp);
|
closedir(dirp);
|
||||||
#endif
|
#endif
|
||||||
File::DeleteDir(directory);
|
if (success)
|
||||||
|
File::DeleteDir(directory);
|
||||||
|
|
||||||
return true;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create directory and copy contents (does not overwrite existing files)
|
// Create directory and copy contents (does not overwrite existing files)
|
||||||
|
|
Loading…
Reference in New Issue