summaryrefslogtreecommitdiff
path: root/Source/Core
diff options
context:
space:
mode:
authorLéo Lam <leo@leolam.fr>2020-05-09 16:34:25 +0200
committerLéo Lam <leo@leolam.fr>2020-05-09 16:47:45 +0200
commit47ee5ac284c2feb5671384f250bbf0036ca2e423 (patch)
treec0f3143d413d96efbc3b49ae136f5c5408dc4dc1 /Source/Core
parent236ffd5e0ee98e9eba310ef07b41ffc191770915 (diff)
WiiRoot: Fix empty files being created when source is missing
CopyNandFile must not create empty files on the destination filesystem if the source file doesn't exist. Otherwise, this can lead to an empty Mii database being created in the session Wii root if there's no database in the configured Wii root and netplay or Movie is used -- that database would then be copied back to the configured root, which causes games like MKW to complain about corrupted Mii data even when the player has stopped using netplay. This commit also simplifies CreateFullPath usage. There's no need to manually extract the directory from the path, FS::CreateFullPath does it automatically just like File::CreateFullPath
Diffstat (limited to 'Source/Core')
-rw-r--r--Source/Core/Core/WiiRoot.cpp18
1 files changed, 9 insertions, 9 deletions
diff --git a/Source/Core/Core/WiiRoot.cpp b/Source/Core/Core/WiiRoot.cpp
index 4096504867..aba484c0de 100644
--- a/Source/Core/Core/WiiRoot.cpp
+++ b/Source/Core/Core/WiiRoot.cpp
@@ -80,21 +80,21 @@ static void CopySave(FS::FileSystem* source, FS::FileSystem* dest, const u64 tit
static bool CopyNandFile(FS::FileSystem* source_fs, const std::string& source_file,
FS::FileSystem* dest_fs, const std::string& dest_file)
{
- const auto last_slash = dest_file.find_last_of('/');
- if (last_slash != std::string::npos && last_slash > 0)
- {
- const std::string dir = dest_file.substr(0, last_slash);
- dest_fs->CreateFullPath(IOS::PID_KERNEL, IOS::PID_KERNEL, dir + '/', 0,
- {FS::Mode::ReadWrite, FS::Mode::ReadWrite, FS::Mode::ReadWrite});
- }
-
auto source_handle =
source_fs->OpenFile(IOS::PID_KERNEL, IOS::PID_KERNEL, source_file, IOS::HLE::FS::Mode::Read);
+ // If the source file doesn't exist, there is nothing more to do.
+ // This function must not create an empty file on the destination filesystem.
+ if (!source_handle)
+ return true;
+
+ dest_fs->CreateFullPath(IOS::PID_KERNEL, IOS::PID_KERNEL, dest_file, 0,
+ {FS::Mode::ReadWrite, FS::Mode::ReadWrite, FS::Mode::ReadWrite});
+
auto dest_handle =
dest_fs->CreateAndOpenFile(IOS::PID_KERNEL, IOS::PID_KERNEL, source_file,
{IOS::HLE::FS::Mode::ReadWrite, IOS::HLE::FS::Mode::ReadWrite,
IOS::HLE::FS::Mode::ReadWrite});
- if (!source_handle || !dest_handle)
+ if (!dest_handle)
return false;
std::vector<u8> buffer(source_handle->GetStatus()->size);