summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFernando Sahmkow <fsahmkow27@gmail.com>2020-07-12 19:00:09 +0200
committerGitHub <noreply@github.com>2020-07-12 19:00:09 +0200
commit739d90ee66cac6986c3ae9dcb2ff78a0836b2017 (patch)
treef3e333d29fcb8fed69374c9eb967c854932aee8e /src
parentMerge pull request #4290 from lioncash/latest (diff)
parentvfs_real: Fix MoveFile (diff)
downloadyuzu-739d90ee66cac6986c3ae9dcb2ff78a0836b2017.tar
yuzu-739d90ee66cac6986c3ae9dcb2ff78a0836b2017.tar.gz
yuzu-739d90ee66cac6986c3ae9dcb2ff78a0836b2017.tar.bz2
yuzu-739d90ee66cac6986c3ae9dcb2ff78a0836b2017.tar.lz
yuzu-739d90ee66cac6986c3ae9dcb2ff78a0836b2017.tar.xz
yuzu-739d90ee66cac6986c3ae9dcb2ff78a0836b2017.tar.zst
yuzu-739d90ee66cac6986c3ae9dcb2ff78a0836b2017.zip
Diffstat (limited to 'src')
-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_
const auto new_path =
FileUtil::SanitizePath(new_path_, FileUtil::DirectorySeparator::PlatformDefault);
- if (!FileUtil::Exists(old_path) || FileUtil::Exists(new_path) ||
- FileUtil::IsDirectory(old_path) || !FileUtil::Rename(old_path, new_path))
- return nullptr;
-
if (cache.find(old_path) != cache.end()) {
- auto cached = cache[old_path];
- if (!cached.expired()) {
- auto file = cached.lock();
- file->Open(new_path, "r+b");
- cache.erase(old_path);
- cache[new_path] = file;
+ auto file = cache[old_path].lock();
+
+ if (!cache[old_path].expired()) {
+ file->Close();
+ }
+
+ if (!FileUtil::Exists(old_path) || FileUtil::Exists(new_path) ||
+ FileUtil::IsDirectory(old_path) || !FileUtil::Rename(old_path, new_path)) {
+ return nullptr;
}
+
+ cache.erase(old_path);
+ file->Open(new_path, "r+b");
+ cache[new_path] = file;
+ } else {
+ UNREACHABLE();
+ return nullptr;
}
+
return OpenFile(new_path, Mode::ReadWrite);
}