Play your Steam library's Windows games on a jailbroken PS5.
C++
Keep the app's folders movable for self-updates
Leonardo Lobato212cfb96285d
diff --git a/src/platform/ps5/native_startup.cpp b/src/platform/ps5/native_startup.cppindex 1e5f306..ac2bb67 100644--- a/src/platform/ps5/native_startup.cpp+++ b/src/platform/ps5/native_startup.cpp@@ -186,6 +186,9 @@ NativeAccessResult PrepareNativeStartup(const std::string& title_id) {// logged: the move takes a missing one.runtime::PrepareAppFolderStubs(result.paths.title_root, WithRoot,[&layout_lines](const std::string& line) { layout_lines.push_back(line); });+ // Before an update's swap, which can't move a folder of the app user's at 0755.+ runtime::OpenAppFolders(result.paths.title_root, WithRoot,+ [&layout_lines](const std::string& line) { layout_lines.push_back(line); });runtime::LayoutPaths layout;layout.app_root = result.paths.title_root;layout.user_root = data_root / "user";diff --git a/src/runtime/writable_folders.cpp b/src/runtime/writable_folders.cppindex bfac006..d1e355a 100644--- a/src/runtime/writable_folders.cpp+++ b/src/runtime/writable_folders.cpp@@ -182,6 +182,51 @@ std::string PrepareDropFolder(const std::filesystem::path& folder, const Writablreturn "Playden can't make " + folder.string() + " (" + detail + "). Games can still be imported from a drive.";}+std::string OpenAppFolders(const std::filesystem::path& app_root, const WritableFoldersAsRoot& as_root,+ const std::function<void(const std::string&)>& log,+ const std::filesystem::path& namespace_root) {+ const auto name = app_root.filename().string();+ if (app_root.parent_path() != namespace_root / "data/homebrew" || name.empty() || name == "." || name == "..") {+ if (log) log("app folders refused path=" + app_root.string());+ return "Playden can't repair this app folder.";+ }+ // Opens one folder and makes it 0777 if it isn't. True when it needs nothing more: done, missing or not a folder.+ const auto open_up = [&](const char* child, int* error) {+ // The app folder is opened again for each one: see PrepareAppFolderStubs.+ const int parent = platform::OpenDirectoryWalk(app_root);+ if (parent < 0) {+ *error = errno;+ return false;+ }+ const int fd = platform::OpenWalkChild(parent, child, O_RDONLY | O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC);+ const int open_error = errno;+ ::close(parent);+ if (fd < 0) {+ *error = open_error;+ return open_error == ENOENT || open_error == ENOTDIR || open_error == ELOOP;+ }+ struct stat info{};+ bool done = ::fstat(fd, &info) == 0 && (info.st_mode & 07777) == 0777;+ if (!done) {+ done = ::fchmod(fd, 0777) == 0;+ if (done && log) log("app folder opened path=" + (app_root / child).string());+ }+ *error = errno;+ ::close(fd);+ return done;+ };+ std::string failed;+ for (const char* child : {"assets", "runtime", "sce_module", "sce_sys", "trust"}) {+ int error = 0;+ if (open_up(child, &error)) continue;+ const bool repaired_as_root = as_root && as_root([&] { return open_up(child, &error); });+ if (repaired_as_root) continue;+ if (log) log("app folder failed path=" + (app_root / child).string() + " error=" + Error(error));+ if (failed.empty()) failed = "Playden can't open " + (app_root / child).string() + ".";+ }+ return failed;+}+std::string PrepareAppFolderStubs(const std::filesystem::path& app_root, const WritableFoldersAsRoot& as_root,const std::function<void(const std::string&)>& log,const std::filesystem::path& namespace_root) {diff --git a/src/runtime/writable_folders.h b/src/runtime/writable_folders.hindex cee44a8..4e2d92d 100644--- a/src/runtime/writable_folders.h+++ b/src/runtime/writable_folders.h@@ -45,4 +45,13 @@ std::string PrepareAppFolderStubs(const std::filesystem::path& app_root, const Wconst std::function<void(const std::string&)>& log,const std::filesystem::path& namespace_root = "/");+// The app's own folders (assets, runtime, sce_module, sce_sys, trust) to 0777: a self-update moves them aside as+// root, and root can't move a folder it doesn't own unless everyone can write to it. A deploy tool or a chmod can+// leave them 0755. Tried as the app user, who owns them after a self-update, then as root, who owns them after an+// FTP copy. Missing folders are skipped, and a link or a file in the place of one is left alone. Only a folder+// directly in /data/homebrew is accepted. Failing doesn't stop Playden: the message is for the log.+std::string OpenAppFolders(const std::filesystem::path& app_root, const WritableFoldersAsRoot& as_root,+ const std::function<void(const std::string&)>& log,+ const std::filesystem::path& namespace_root = "/");+} // namespace playden::runtimediff --git a/tests/runtime_writable_folders_test.cpp b/tests/runtime_writable_folders_test.cppindex fa090f7..adf17a9 100644--- a/tests/runtime_writable_folders_test.cpp+++ b/tests/runtime_writable_folders_test.cpp@@ -181,6 +181,26 @@ int main() {CHECK(!PrepareAppFolderStubs(root / "data/homebrew/PPSA97031", runs, log, root).empty());CHECK(!fs::exists(root / "data/homebrew/PPSA97031"));}+ // The app's own folders go to 0777; missing ones, links and refused paths are left.+ {+ const auto app = root / "data/homebrew/FAKE77031";+ fs::create_directories(app / "assets");+ fs::create_directories(app / "sce_sys");+ CHECK(chmod((app / "assets").c_str(), 0755) == 0 && chmod((app / "sce_sys").c_str(), 0777) == 0);+ const auto link_target = root / "app-folder-link-target";+ fs::create_directories(link_target);+ CHECK(chmod(link_target.c_str(), 0755) == 0 && symlink(link_target.c_str(), (app / "trust").c_str()) == 0);+ const auto before = calls;+ lines.clear();+ CHECK(OpenAppFolders(app, runs, log, root).empty());+ CHECK(Mode(app / "assets") == 0777 && Mode(app / "sce_sys") == 0777 && Mode(link_target) == 0755);+ CHECK(!fs::exists(app / "runtime") && calls == before);+ CHECK(lines.size() == 1 && lines[0].find("/assets") != std::string::npos);+ CHECK(OpenAppFolders(app, nullptr, log, root).empty());+ CHECK(!OpenAppFolders(root / "data/FAKE77031", runs, log, root).empty());+ CHECK(!OpenAppFolders(root / "data/homebrew", runs, log, root).empty());+ CHECK(unlink((app / "trust").c_str()) == 0);+ }// /data swapped for a link to an outside folder: neither repair follows it as root.{const auto outside = root / "outside-data";diff --git a/tools/console_title_deploy.py b/tools/console_title_deploy.pyindex b069a0d..49ebf68 100644--- a/tools/console_title_deploy.py+++ b/tools/console_title_deploy.py@@ -8,8 +8,9 @@ same way. Game downloads, logs and user data under the title are never touched.deploy --install also creates the package's folders, for a first install on aconsole that has none (after a system reinstall, for example). Folders are-0755, except the ones Playden writes to as the app's user, which must be 0777-whoever created them; every deploy checks those.+0777: Playden writes to some as the app's user, and its self-update moves the+others aside, which root can't do to a folder it doesn't own unless everyone can+write to it. Every deploy checks the ones Playden writes to."""import argparseimport ftplib@@ -132,7 +133,7 @@ def main():ensure_directory(ftp, TITLE, "777")for local in sorted(path for path in args.package.rglob("*") if path.is_dir()):relative = local.relative_to(args.package).as_posix()- ensure_directory(ftp, f"{TITLE}/{relative}", "777" if relative in WRITABLE_DIRS else "755")+ ensure_directory(ftp, f"{TITLE}/{relative}", "777")elif listing(ftp, TITLE) is None:print(f"refusing: {TITLE} is missing; use --install for a first install", file=sys.stderr)return 1