vfs: add exists test function

This commit is contained in:
DH 2024-08-31 23:23:11 +03:00
parent e6022c1c4c
commit ceb0172b1e
2 changed files with 15 additions and 1 deletions

View file

@ -6,7 +6,6 @@
#include "orbis/error/SysResult.hpp"
#include <filesystem>
#include <map>
#include <optional>
#include <string_view>
@ -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<orbis::File> 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);

View file

@ -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<orbis::File> *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,