Implement vfs::host::rename

With spurious access error workaround
This commit is contained in:
Nekotekina 2019-04-07 12:58:08 +03:00
parent 3354f068fc
commit 9736773c04
5 changed files with 28 additions and 9 deletions

View File

@ -453,7 +453,7 @@ error_code cellGameContentPermit(vm::ptr<char[CELL_GAME_PATH_MAX]> contentInfoPa
// Make temporary directory persistent
const auto vdir = vfs::get(dir);
if (fs::rename(prm->temp, vdir, false))
if (vfs::host::rename(prm->temp, vdir, false))
{
cellGame.success("cellGameContentPermit(): directory '%s' has been created", dir);
}

View File

@ -934,19 +934,16 @@ static NEVER_INLINE error_code savedata_op(ppu_thread& ppu, u32 operation, u32 v
fs::remove_all(old_path, false);
// Backup old savedata
while (!fs::rename(dir_path, old_path, true))
if (!vfs::host::rename(dir_path, old_path, true))
{
// Try to ignore access error in order to prevent spurious failure
if (Emu.IsStopped() || fs::g_tls_error != fs::error::acces)
fmt::throw_exception("Failed to move directory %s (%s)", dir_path, fs::g_tls_error);
fmt::throw_exception("Failed to move directory %s (%s)", dir_path, fs::g_tls_error);
}
// Commit new savedata
while (!fs::rename(new_path, dir_path, false))
if (!vfs::host::rename(new_path, dir_path, false))
{
// TODO: handle the case when only commit failed at the next save load
if (Emu.IsStopped() || fs::g_tls_error != fs::error::acces)
fmt::throw_exception("Failed to move directory %s (%s)", new_path, fs::g_tls_error);
fmt::throw_exception("Failed to move directory %s (%s)", new_path, fs::g_tls_error);
}
// Remove backup again (TODO: may be changed to persistent backup implementation)

View File

@ -774,7 +774,7 @@ error_code sys_fs_rename(vm::cptr<char> from, vm::cptr<char> to)
return CELL_ENOTMOUNTED;
}
if (!fs::rename(local_from, local_to, false))
if (!vfs::host::rename(local_from, local_to, false))
{
switch (auto error = fs::g_tls_error)
{

View File

@ -1,5 +1,6 @@
#include "stdafx.h"
#include "IdManager.h"
#include "System.h"
#include "VFS.h"
#include "Utilities/mutex.h"
@ -447,3 +448,17 @@ std::string vfs::unescape(std::string_view path)
return result;
}
bool vfs::host::rename(const std::string& from, const std::string& to, bool overwrite)
{
while (!fs::rename(from, to, overwrite))
{
// Try to ignore access error in order to prevent spurious failure
if (Emu.IsStopped() || fs::g_tls_error != fs::error::acces)
{
return false;
}
}
return true;
}

View File

@ -17,4 +17,11 @@ namespace vfs
// Invert escape operation
std::string unescape(std::string_view path);
// Functions in this namespace operate on host filepaths, similar to fs::
namespace host
{
// Call fs::rename with retry on access error
bool rename(const std::string& from, const std::string& to, bool overwrite);
}
}