From ceb0172b1e95c821e4b7dfb2124d5689a4143f1e Mon Sep 17 00:00:00 2001 From: DH Date: Sat, 31 Aug 2024 23:23:11 +0300 Subject: [PATCH] vfs: add exists test function --- rpcsx-os/vfs.cpp | 15 ++++++++++++++- rpcsx-os/vfs.hpp | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/rpcsx-os/vfs.cpp b/rpcsx-os/vfs.cpp index eba498aa3..083a12d51 100644 --- a/rpcsx-os/vfs.cpp +++ b/rpcsx-os/vfs.cpp @@ -6,7 +6,6 @@ #include "orbis/error/SysResult.hpp" #include #include -#include #include @@ -183,6 +182,20 @@ orbis::SysResult rx::vfs::open(std::string_view path, int flags, int mode, return device->open(file, devPath.c_str(), flags, mode, thread); } +bool rx::vfs::exists(std::string_view path, orbis::Thread *thread) { + auto [device, devPath] = get(path); + if (device == nullptr) { + return false; + } + + orbis::Ref file; + if (device->open(&file, devPath.c_str(), 0, 0, thread) != + orbis::ErrorCode{}) { + return false; + } + return true; +} + orbis::SysResult rx::vfs::mkdir(std::string_view path, int mode, orbis::Thread *thread) { auto [device, devPath] = get(path); diff --git a/rpcsx-os/vfs.hpp b/rpcsx-os/vfs.hpp index 2edb29e2d..8884d9399 100644 --- a/rpcsx-os/vfs.hpp +++ b/rpcsx-os/vfs.hpp @@ -17,6 +17,7 @@ get(const std::filesystem::path &guestPath); orbis::SysResult mount(const std::filesystem::path &guestPath, IoDevice *dev); orbis::SysResult open(std::string_view path, int flags, int mode, orbis::Ref *file, orbis::Thread *thread); +bool exists(std::string_view path, orbis::Thread *thread); orbis::SysResult mkdir(std::string_view path, int mode, orbis::Thread *thread); orbis::SysResult rmdir(std::string_view path, orbis::Thread *thread); orbis::SysResult rename(std::string_view from, std::string_view to,