[ox] Replace C strings in FS with StringView

This commit is contained in:
2022-12-31 14:18:38 -06:00
parent 5cae7cbd24
commit ca07dc6152
16 changed files with 148 additions and 128 deletions

View File

@ -30,20 +30,20 @@ class PassThroughFS: public FileSystem {
std::filesystem::path m_path;
public:
explicit PassThroughFS(const char *dirPath);
explicit PassThroughFS(CRStringView dirPath);
~PassThroughFS() noexcept override;
[[nodiscard]]
String basePath() const noexcept;
Error mkdir(const char *path, bool recursive = false) noexcept override;
Error mkdir(CRStringView path, bool recursive = false) noexcept override;
Error move(const char *src, const char *dest) noexcept override;
Error move(CRStringView src, CRStringView dest) noexcept override;
Error read(const char *path, void *buffer, std::size_t buffSize) noexcept override;
Error read(CRStringView path, void *buffer, std::size_t buffSize) noexcept override;
Result<const char*> directAccess(const char*) noexcept override;
Result<const char*> directAccess(CRStringView) noexcept override;
Error read(uint64_t inode, void *buffer, std::size_t size) noexcept override;
@ -51,29 +51,31 @@ class PassThroughFS: public FileSystem {
Result<const char*> directAccess(uint64_t) noexcept override;
Result<Vector<String>> ls(const char *dir) const noexcept override;
Result<Vector<String>> ls(CRStringView dir) const noexcept override;
template<typename F>
Error ls(const char *dir, F cb) const noexcept;
Error ls(CRStringView dir, F cb) const noexcept;
Error remove(const char *path, bool recursive = false) noexcept override;
Error remove(CRStringView path, bool recursive = false) noexcept override;
Error resize(uint64_t size, void *buffer = nullptr) noexcept override;
Error write(const char *path, const void *buffer, uint64_t size, FileType fileType = FileType::NormalFile) noexcept override;
Error write(CRStringView path, const void *buffer, uint64_t size, FileType fileType = FileType::NormalFile) noexcept override;
Error write(uint64_t inode, const void *buffer, uint64_t size, FileType fileType = FileType::NormalFile) noexcept override;
Result<FileStat> stat(uint64_t inode) const noexcept override;
Result<FileStat> stat(const char *path) const noexcept override;
Result<FileStat> stat(CRStringView path) const noexcept override;
[[nodiscard]]
uint64_t spaceNeeded(uint64_t size) const noexcept override;
Result<uint64_t> available() const noexcept override;
Result<uint64_t> size() const noexcept override;
[[nodiscard]]
char *buff() noexcept override;
Error walk(Error(*cb)(uint8_t, uint64_t, uint64_t)) noexcept override;
@ -85,12 +87,13 @@ class PassThroughFS: public FileSystem {
/**
* Strips the leading slashes from a string.
*/
static const char *stripSlash(const char *path) noexcept;
[[nodiscard]]
static std::string_view stripSlash(StringView path) noexcept;
};
template<typename F>
Error PassThroughFS::ls(const char *dir, F cb) const noexcept {
Error PassThroughFS::ls(CRStringView dir, F cb) const noexcept {
std::error_code ec;
const auto di = std::filesystem::directory_iterator(m_path / stripSlash(dir), ec);
oxReturnError(OxError(ec.value(), "PassThroughFS: ls failed"));