Skip to content

Commit

Permalink
Revert "fs: Reimplement path resolving using std::filesystem::weakly_…
Browse files Browse the repository at this point in the history
…canonical"

This reverts commit 0c4b2ff.
  • Loading branch information
MSuih committed Jan 13, 2022
1 parent 1623e59 commit 615cec2
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 45 deletions.
15 changes: 0 additions & 15 deletions Utilities/File.cpp
Expand Up @@ -4,7 +4,6 @@
#include "Crypto/sha1.h"

#include <unordered_map>
#include <filesystem>
#include <algorithm>
#include <cstring>
#include <map>
Expand Down Expand Up @@ -1823,20 +1822,6 @@ bool fs::remove_all(const std::string& path, bool remove_root)
return true;
}

std::string fs::resolve_path(std::string_view path)
{
std::error_code ec{};
const auto result = std::filesystem::weakly_canonical(std::filesystem::path(path), ec);

if (ec)
{
g_tls_error = error::inval;
return {};
}

return result.string();
}

u64 fs::get_dir_size(const std::string& path, u64 rounding_alignment)
{
u64 result = 0;
Expand Down
3 changes: 0 additions & 3 deletions Utilities/File.h
Expand Up @@ -645,9 +645,6 @@ namespace fs
std::string m_dest{}; // Destination file path
};

// Get real path for comparisons
std::string resolve_path(std::string_view path);

// Delete directory and all its contents recursively
bool remove_all(const std::string& path, bool remove_root = true);

Expand Down
12 changes: 6 additions & 6 deletions rpcs3/Emu/System.cpp
Expand Up @@ -554,7 +554,7 @@ void Emulator::SetForceBoot(bool force_boot)

game_boot_result Emulator::Load(const std::string& title_id, bool add_only, bool is_disc_patch)
{
const std::string resolved_path = fs::resolve_path(m_path);
const std::string resolved_path = GetCallbacks().resolve_path(m_path);

if (!IsStopped())
{
Expand Down Expand Up @@ -1213,7 +1213,7 @@ game_boot_result Emulator::Load(const std::string& title_id, bool add_only, bool
// Check game updates
const std::string hdd0_boot = hdd0_game + m_title_id + "/USRDIR/EBOOT.BIN";

if (disc.empty() && !bdvd_dir.empty() && fs::resolve_path(m_path) != fs::resolve_path(hdd0_boot) && fs::is_file(hdd0_boot))
if (disc.empty() && !bdvd_dir.empty() && GetCallbacks().resolve_path(m_path) != GetCallbacks().resolve_path(hdd0_boot) && fs::is_file(hdd0_boot))
{
// Booting game update
sys_log.success("Updates found at /dev_hdd0/game/%s/", m_title_id);
Expand Down Expand Up @@ -1333,7 +1333,7 @@ game_boot_result Emulator::Load(const std::string& title_id, bool add_only, bool
return fmt::merge(result, "/");
};

const std::string resolved_hdd0 = fs::resolve_path(hdd0_game) + '/';
const std::string resolved_hdd0 = GetCallbacks().resolve_path(hdd0_game) + '/';

if (from_hdd0_game && m_cat == "DG")
{
Expand All @@ -1357,7 +1357,7 @@ game_boot_result Emulator::Load(const std::string& title_id, bool add_only, bool
else if (from_dev_flash)
{
// Firmware executables
argv[0] = "/dev_flash" + resolved_path.substr(fs::resolve_path(g_cfg_vfs.get_dev_flash()).size());
argv[0] = "/dev_flash" + resolved_path.substr(GetCallbacks().resolve_path(g_cfg_vfs.get_dev_flash()).size());
m_dir = fs::get_parent_dir(argv[0]) + '/';
}
else if (g_cfg.vfs.host_root)
Expand Down Expand Up @@ -1975,9 +1975,9 @@ std::set<std::string> Emulator::GetGameDirs() const

bool Emulator::IsPathInsideDir(std::string_view path, std::string_view dir) const
{
const std::string dir_path = fs::resolve_path(dir);
const std::string dir_path = GetCallbacks().resolve_path(dir);

return !dir_path.empty() && (fs::resolve_path(path) + '/').starts_with(dir_path + '/');
return !dir_path.empty() && (GetCallbacks().resolve_path(path) + '/').starts_with(dir_path + '/');
};

const std::string& Emulator::GetFakeCat() const
Expand Down
1 change: 1 addition & 0 deletions rpcs3/Emu/System.h
Expand Up @@ -81,6 +81,7 @@ struct EmuCallbacks
std::function<std::string(localized_string_id, const char*)> get_localized_string;
std::function<std::u32string(localized_string_id, const char*)> get_localized_u32string;
std::function<void(const std::string&)> play_sound;
std::string(*resolve_path)(std::string_view) = nullptr; // Resolve path using Qt
};

class Emulator final
Expand Down
28 changes: 7 additions & 21 deletions rpcs3/Emu/VFS.cpp
Expand Up @@ -42,31 +42,17 @@ bool vfs::mount(std::string_view vpath, std::string_view path)

// TODO: scan roots of mounted devices for undeleted vfs::host::unlink remnants, and try to delete them (_WIN32 only)

std::lock_guard lock(table.mutex);

if (vpath.empty())
{
// Empty relative path, should set relative path base; unsupported
vfs_log.error("Cannot mount empty path to \"%s\"", path);
return false;
}

const bool delim_suffixed = path.ends_with(fs::delim);
std::string final_path = fs::resolve_path(path);

if (final_path.empty())
{
vfs_log.error("Cannot mount path \"%s\" due to invalid host path \"%s\" (%s)", vpath, path, fs::g_tls_error);
return false;
}

if (!final_path.ends_with(fs::delim) && delim_suffixed)
{
final_path += '/';
}

const std::string_view vpath_backup = vpath;

std::lock_guard lock(table.mutex);

for (std::vector<vfs_directory*> list{&table.root};;)
{
// Skip one or more '/'
Expand All @@ -82,8 +68,8 @@ bool vfs::mount(std::string_view vpath, std::string_view path)
if (pos == umax)
{
// Mounting completed
list.back()->path = std::move(final_path);
vfs_log.notice("Mounted path \"%s\" to \"%s\"", vpath_backup, final_path);
list.back()->path = path;
vfs_log.notice("Mounted path \"%s\" to \"%s\"", vpath_backup, path);
return true;
}

Expand Down Expand Up @@ -757,7 +743,7 @@ bool vfs::host::rename(const std::string& from, const std::string& to, const lv2
{
// Lock mount point, close file descriptors, retry
const auto from0 = std::string_view(from).substr(0, from.find_last_not_of(fs::delim) + 1);
const auto escaped_from = fs::resolve_path(from);
const auto escaped_from = Emu.GetCallbacks().resolve_path(from);

std::lock_guard lock(mp->mutex);

Expand All @@ -768,7 +754,7 @@ bool vfs::host::rename(const std::string& from, const std::string& to, const lv2

idm::select<lv2_fs_object, lv2_file>([&](u32 /*id*/, lv2_file& file)
{
if (check_path(fs::resolve_path(file.real_path)))
if (check_path(Emu.GetCallbacks().resolve_path(file.real_path)))
{
ensure(file.mp == mp);

Expand Down Expand Up @@ -810,7 +796,7 @@ bool vfs::host::rename(const std::string& from, const std::string& to, const lv2

idm::select<lv2_fs_object, lv2_file>([&](u32 /*id*/, lv2_file& file)
{
const auto escaped_real = fs::resolve_path(file.real_path);
const auto escaped_real = Emu.GetCallbacks().resolve_path(file.real_path);

if (check_path(escaped_real))
{
Expand Down
7 changes: 7 additions & 0 deletions rpcs3/main_application.cpp
Expand Up @@ -26,6 +26,8 @@
#include "Emu/Audio/FAudio/FAudioBackend.h"
#endif

#include <QFileInfo> // This shouldn't be outside rpcs3qt...

LOG_CHANNEL(sys_log, "SYS");

/** Emu.Init() wrapper for user management */
Expand Down Expand Up @@ -121,5 +123,10 @@ EmuCallbacks main_application::CreateCallbacks()
return result;
};

callbacks.resolve_path = [](std::string_view sv)
{
return QFileInfo(QString::fromUtf8(sv.data(), static_cast<int>(sv.size()))).canonicalFilePath().toStdString();
};

return callbacks;
}

0 comments on commit 615cec2

Please sign in to comment.