mirror of
https://github.com/yuzu-emu/yuzu.git
synced 2024-07-04 23:31:19 +01:00
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.
This commit is contained in:
parent
0974533c96
commit
755506d404
1 changed files with 17 additions and 10 deletions
|
@ -112,19 +112,26 @@ VirtualFile RealVfsFilesystem::MoveFile(std::string_view old_path_, std::string_
|
||||||
const auto new_path =
|
const auto new_path =
|
||||||
FileUtil::SanitizePath(new_path_, FileUtil::DirectorySeparator::PlatformDefault);
|
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()) {
|
if (cache.find(old_path) != cache.end()) {
|
||||||
auto cached = cache[old_path];
|
auto file = cache[old_path].lock();
|
||||||
if (!cached.expired()) {
|
|
||||||
auto file = cached.lock();
|
if (!cache[old_path].expired()) {
|
||||||
file->Open(new_path, "r+b");
|
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);
|
cache.erase(old_path);
|
||||||
|
file->Open(new_path, "r+b");
|
||||||
cache[new_path] = file;
|
cache[new_path] = file;
|
||||||
|
} else {
|
||||||
|
UNREACHABLE();
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return OpenFile(new_path, Mode::ReadWrite);
|
return OpenFile(new_path, Mode::ReadWrite);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue