Skip to content

Play your Steam library's Windows games on a jailbroken PS5.

C++

Cover unsupported walks and rollback sync retries

Leonardo Lobatoa0800e0383df
diff --git a/cmake/HomebrewUI.cmake b/cmake/HomebrewUI.cmake
index be0cc5b..5c29083 100644
--- a/cmake/HomebrewUI.cmake
+++ b/cmake/HomebrewUI.cmake
@@ -425,6 +425,14 @@ if(BUILD_TESTING)
target_compile_features(runtime_writable_folders_test PRIVATE cxx_std_20)
target_include_directories(runtime_writable_folders_test PRIVATE "${CMAKE_SOURCE_DIR}/src")
add_test(NAME runtime_writable_folders COMMAND runtime_writable_folders_test)
+ add_executable(runtime_writable_folders_native_policy_test
+ "${CMAKE_SOURCE_DIR}/tests/runtime_writable_folders_test.cpp"
+ "${CMAKE_SOURCE_DIR}/tests/directory_gateway_host.cpp"
+ "${CMAKE_SOURCE_DIR}/src/runtime/writable_folders.cpp")
+ target_compile_features(runtime_writable_folders_native_policy_test PRIVATE cxx_std_20)
+ target_include_directories(runtime_writable_folders_native_policy_test PRIVATE "${CMAKE_SOURCE_DIR}/src")
+ target_compile_definitions(runtime_writable_folders_native_policy_test PRIVATE PLAYDEN_PLATFORM_PS5=1)
+ add_test(NAME runtime_writable_folders_native_policy COMMAND runtime_writable_folders_native_policy_test)
add_executable(homebrew_title_icon_test "${CMAKE_SOURCE_DIR}/tests/homebrew_title_icon_test.cpp")
target_compile_features(homebrew_title_icon_test PRIVATE cxx_std_20)
target_include_directories(homebrew_title_icon_test PRIVATE "${PLAYDEN_STB_IMAGE_INCLUDE_DIR}")
diff --git a/src/homebrew/runtime_host.cpp b/src/homebrew/runtime_host.cpp
index 69874b2..293b8f7 100644
--- a/src/homebrew/runtime_host.cpp
+++ b/src/homebrew/runtime_host.cpp
@@ -1314,6 +1314,11 @@ bool RuntimeHost::MoveGames(Composition& c, std::string* error) {
if (rename_pending) move = std::make_pair(console_path(config_.layout_paths->app_root / "games"),
console_path(config_.layout_paths->games_root));
if (!move) return true;
+ for (auto* path : {&move->first, &move->second})
+ if (!config_.host_namespace_prefix.empty()) {
+ const auto relative = std::filesystem::path(*path).lexically_relative(config_.host_namespace_prefix);
+ if (!relative.empty() && *relative.begin() != "..") *path = (std::filesystem::path("/") / relative).string();
+ }
// All leases precede every activity check and survive the rename AND record rewrite.
std::vector<platform::ManagedFileLock> leases;
const auto postpone = [&](const std::string& why) {
diff --git a/src/runtime/layout_migration.cpp b/src/runtime/layout_migration.cpp
index 4ccfb68..b211906 100644
--- a/src/runtime/layout_migration.cpp
+++ b/src/runtime/layout_migration.cpp
@@ -581,6 +581,11 @@ RevertResult RevertLayout(const LayoutPaths& paths, const LayoutOps& ops) {
if (rename_error) problems += "rename " + (tree.from / name).string() + " failed " + Describe(rename_error) + "; ";
}
if (!problems.empty()) { result.error = problems; return result; }
+ // A previous attempt may have renamed the last entry but failed its parent sync.
+ if (!SyncDirectory(ops, tree.from) || !SyncDirectory(ops, tree.to)) {
+ result.error = "the rollback folders could not be synced";
+ return result;
+ }
Log(ops, "moved " + tree.from.string() + " back to " + tree.to.string());
}
if (!problems.empty()) {
diff --git a/tests/directory_gateway_host.cpp b/tests/directory_gateway_host.cpp
index ce40428..b3a0b5f 100644
--- a/tests/directory_gateway_host.cpp
+++ b/tests/directory_gateway_host.cpp
@@ -1,13 +1,17 @@
// Native-policy tests: direct *at imports fail; the separately named gateway works.
#include <dlfcn.h>
+#include <cerrno>
+int playden_test_gateway_error = 0;
#include <fcntl.h>
#include <sys/stat.h>
extern "C" int __wrap_openat(int parent, const char* name, int flags, ...) {
+ if (playden_test_gateway_error) { errno = playden_test_gateway_error; return -1; }
using OpenAt = int (*)(int, const char*, int, ...);
static const auto open_at = reinterpret_cast<OpenAt>(dlsym(RTLD_NEXT, "openat"));
return open_at(parent, name, flags);
}
extern "C" int __wrap_mkdirat(int parent, const char* name, mode_t mode) {
+ if (playden_test_gateway_error) { errno = playden_test_gateway_error; return -1; }
using MkdirAt = int (*)(int, const char*, mode_t);
static const auto mkdir_at = reinterpret_cast<MkdirAt>(dlsym(RTLD_NEXT, "mkdirat"));
return mkdir_at(parent, name, mode);
diff --git a/tests/layout_migration_test.cpp b/tests/layout_migration_test.cpp
index 948a58d..8189c34 100644
--- a/tests/layout_migration_test.cpp
+++ b/tests/layout_migration_test.cpp
@@ -497,6 +497,21 @@ void RenameParentsSyncBeforeJournalAdvances() {
CHECK(renames == 12 && syncs == 2 * renames && pending.empty());
}
+void RevertRetriesTheLastRenameSync() {
+ auto f = Make("revert-last-sync");
+ CHECK(MigrateLayout(f->paths, f->ops).games_moved);
+ bool failed = false;
+ f->ops.sync = [&](const fs::path& path) {
+ if (path == f->paths.log_root && fs::is_empty(path)) { failed = true; return false; }
+ return true;
+ };
+ CHECK(!RevertLayout(f->paths, f->ops).complete && failed);
+ CHECK(LoadLayoutJournal(f->paths.state_root)->step == "revert-logs");
+ bool retried = false;
+ f->ops.sync = [&](const fs::path& path) { if (path == f->paths.log_root) retried = true; return true; };
+ CHECK(RevertLayout(f->paths, f->ops).complete && retried);
+}
+
void FailedDirectorySyncKeepsUserStepBlocked() {
auto f = Make("user-sync");
const auto old = f->paths.app_root / "playden-data";
@@ -526,6 +541,7 @@ int main() {
PartialUserMoveBlocksServicesAndOnlyMovesForward();
FailedDirectorySyncKeepsUserStepBlocked();
RenameParentsSyncBeforeJournalAdvances();
+ RevertRetriesTheLastRenameSync();
MovesUserDataLogsAndGames();
KeepsStubFolders();
ResumesAfterEachStep();
diff --git a/tests/runtime_package_installer_test.cpp b/tests/runtime_package_installer_test.cpp
index b9261ba..665d056 100644
--- a/tests/runtime_package_installer_test.cpp
+++ b/tests/runtime_package_installer_test.cpp
@@ -29,6 +29,7 @@
#include <vector>
#ifdef PLAYDEN_TEST_AT_UNAVAILABLE
+extern int playden_test_gateway_error;
extern "C" int playden_ps5_file_lock(int fd, int operation) { return ::flock(fd, operation); }
#include <cerrno>
extern "C" int openat(int, const char*, int, ...) { errno = EINVAL; return -1; }
@@ -747,6 +748,14 @@ void SharedTreeWalksByPath() {
CHECK(::link((temporary.path / "private/secret").c_str(), (root / "Documents/secret").c_str()) == 0);
SharedTreeOptions options;
+#ifdef PLAYDEN_TEST_AT_UNAVAILABLE
+ for (const int error : {EINVAL, ENOSYS}) {
+ playden_test_gateway_error = error;
+ CHECK(!OpenTreeToEveryone(root, options).ok);
+ CHECK(ModeOf(root / "Documents/notes.txt") == 0600);
+ playden_test_gateway_error = 0;
+ }
+#endif
auto opened = OpenTreeToEveryone(root, options);
CHECK(opened.ok && !opened.changed_under && opened.linked == 1);
CHECK(ModeOf(root / "AppData/Roaming/Game") == 0777 && ModeOf(root / "AppData/Roaming/Game/save.dat") == 0666);
diff --git a/tests/runtime_writable_folders_test.cpp b/tests/runtime_writable_folders_test.cpp
index 4d6925b..32c3bd9 100644
--- a/tests/runtime_writable_folders_test.cpp
+++ b/tests/runtime_writable_folders_test.cpp
@@ -1,6 +1,10 @@
#include "runtime/writable_folders.h"
#include <cstdio>
+#include <cerrno>
+#if PLAYDEN_PLATFORM_PS5
+extern int playden_test_gateway_error;
+#endif
#include <cstdlib>
#include <filesystem>
#include <string>
@@ -126,6 +130,20 @@ int main() {
CHECK(EnsureWritableFolders({target}, runs, log, root).empty());
CHECK(Mode(target) == 0777 && calls == before_calls);
CHECK(chmod(target.c_str(), 0755) == 0);
+#if PLAYDEN_PLATFORM_PS5
+ for (const int error : {EINVAL, ENOSYS}) {
+ CHECK(chmod(locked.c_str(), 0555) == 0);
+ CHECK(chmod((root / "data/playden").c_str(), 0755) == 0);
+ playden_test_gateway_error = error;
+ CHECK(!EnsureWritableFolders({locked}, runs, log, root).empty());
+ CHECK(Mode(locked) == 0555);
+ CHECK(!PrepareRuntimeRoot(root / "data/playden", runs, log, root).empty());
+ CHECK(Mode(root / "data/playden") == 0755);
+ CHECK(lines.back().find("error=" + std::to_string(error)) != std::string::npos);
+ playden_test_gateway_error = 0;
+ CHECK(chmod(locked.c_str(), 0777) == 0);
+ }
+#endif
std::error_code ignored;
fs::remove_all(root, ignored);
std::puts("writable folders tests passed");