summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Morph2020-07-07 06:57:20 -0400
committerGravatar Morph2020-07-10 00:39:23 -0400
commit755506d4047af89aaa4cb90720ef721582431784 (patch)
treeb527500fee78230fde8a72860e53fcc6e44ddb11
parentMerge pull request #4285 from ogniK5377/fmt-fix (diff)
downloadyuzu-755506d4047af89aaa4cb90720ef721582431784.tar.gz
yuzu-755506d4047af89aaa4cb90720ef721582431784.tar.xz
yuzu-755506d4047af89aaa4cb90720ef721582431784.zip
vfs_real: Fix MoveFile
The file wasn't closed prior to being renamed / moved, throwing an error that states "The process cannot access the file because it is being used by another process." Fix this by closing the file prior to a rename / move operation. Fixes saving in Luigi's Mansion 3 and KATANA KAMI: A Way of the Samurai Story.
Diffstat (limited to '')
-rw-r--r--src/core/file_sys/vfs_real.cpp27
1 files changed, 17 insertions, 10 deletions
diff --git a/src/core/file_sys/vfs_real.cpp b/src/core/file_sys/vfs_real.cpp
index e21300a7c..96ce5957c 100644
--- a/src/core/file_sys/vfs_real.cpp
+++ b/src/core/file_sys/vfs_real.cpp
@@ -112,19 +112,26 @@ VirtualFile RealVfsFilesystem::MoveFile(std::string_view old_path_, std::string_
112 const auto new_path = 112 const auto new_path =
113 FileUtil::SanitizePath(new_path_, FileUtil::DirectorySeparator::PlatformDefault); 113 FileUtil::SanitizePath(new_path_, FileUtil::DirectorySeparator::PlatformDefault);
114 114
115 if (!FileUtil::Exists(old_path) || FileUtil::Exists(new_path) ||
116 FileUtil::IsDirectory(old_path) || !FileUtil::Rename(old_path, new_path))
117 return nullptr;
118
119 if (cache.find(old_path) != cache.end()) { 115 if (cache.find(old_path) != cache.end()) {
120 auto cached = cache[old_path]; 116 auto file = cache[old_path].lock();
121 if (!cached.expired()) { 117
122 auto file = cached.lock(); 118 if (!cache[old_path].expired()) {
123 file->Open(new_path, "r+b"); 119 file->Close();
124 cache.erase(old_path); 120 }
125 cache[new_path] = file; 121
122 if (!FileUtil::Exists(old_path) || FileUtil::Exists(new_path) ||
123 FileUtil::IsDirectory(old_path) || !FileUtil::Rename(old_path, new_path)) {
124 return nullptr;
126 } 125 }
126
127 cache.erase(old_path);
128 file->Open(new_path, "r+b");
129 cache[new_path] = file;
130 } else {
131 UNREACHABLE();
132 return nullptr;
127 } 133 }
134
128 return OpenFile(new_path, Mode::ReadWrite); 135 return OpenFile(new_path, Mode::ReadWrite);
129} 136}
130 137