From cdd1de89f8b026dd4a8da210d7897df36920688d Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Tue, 11 May 2021 00:52:47 -0500 Subject: [PATCH] [ox/fs] Cleanup, Add error messages for unsupported methods in PassThroughFS --- .../ox/src/ox/fs/filesystem/passthroughfs.cpp | 34 +++++++++---------- .../ox/src/ox/fs/filesystem/passthroughfs.hpp | 4 +-- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/deps/ox/src/ox/fs/filesystem/passthroughfs.cpp b/deps/ox/src/ox/fs/filesystem/passthroughfs.cpp index f1f11631..81567b85 100644 --- a/deps/ox/src/ox/fs/filesystem/passthroughfs.cpp +++ b/deps/ox/src/ox/fs/filesystem/passthroughfs.cpp @@ -34,7 +34,7 @@ Error PassThroughFS::mkdir(const char *path, bool recursive) noexcept { oxTrace("ox::fs::PassThroughFS::mkdir") << u8p.c_str(); if (recursive) { std::error_code ec; - auto isDir = std::filesystem::is_directory(p, ec); + const auto isDir = std::filesystem::is_directory(p, ec); oxReturnError(OxError(ec.value(), "PassThroughFS: mkdir failed")); if (isDir) { success = true; @@ -82,12 +82,12 @@ Result PassThroughFS::directAccess(const char*) noexcept { Error PassThroughFS::read(uint64_t, void*, std::size_t) noexcept { // unsupported - return OxError(1); + return OxError(1, "read(uint64_t, void*, std::size_t) is not supported by PassThroughFS"); } Error PassThroughFS::read(uint64_t, std::size_t, std::size_t, void*, std::size_t*) noexcept { // unsupported - return OxError(1); + return OxError(1, "read(uint64_t, std::size_t, std::size_t, void*, std::size_t*) is not supported by PassThroughFS"); } Result PassThroughFS::directAccess(uint64_t) noexcept { @@ -99,8 +99,8 @@ Result> PassThroughFS::ls(const char *dir) noexcept { std::error_code ec; const auto di = std::filesystem::directory_iterator(m_path / stripSlash(dir), ec); oxReturnError(OxError(ec.value(), "PassThroughFS: ls failed")); - for (auto &p : di) { - auto u8p = p.path().filename().u8string(); + for (const auto &p : di) { + const auto u8p = p.path().filename().u8string(); out.emplace_back(bit_cast(u8p.c_str())); } return ox::move(out); @@ -116,11 +116,11 @@ Error PassThroughFS::remove(const char *path, bool recursive) noexcept { Error PassThroughFS::resize(uint64_t, void*) noexcept { // unsupported - return OxError(1); + return OxError(1, "resize is not supported by PassThroughFS"); } Error PassThroughFS::write(const char *path, void *buffer, uint64_t size, uint8_t) noexcept { - auto p = (m_path / stripSlash(path)); + const auto p = (m_path / stripSlash(path)); try { std::ofstream f(p, std::ios::binary); f.write(static_cast(buffer), size); @@ -133,21 +133,21 @@ Error PassThroughFS::write(const char *path, void *buffer, uint64_t size, uint8_ Error PassThroughFS::write(uint64_t, void*, uint64_t, uint8_t) noexcept { // unsupported - return OxError(1); + return OxError(1, "write(uint64_t, void*, uint64_t, uint8_t) is not supported by PassThroughFS"); } Result PassThroughFS::stat(uint64_t) noexcept { // unsupported - return OxError(1); + return OxError(1, "stat(uint64_t) is not supported by PassThroughFS"); } Result PassThroughFS::stat(const char *path) noexcept { std::error_code ec; const auto p = m_path / stripSlash(path); - uint8_t type = std::filesystem::is_directory(p, ec) ? + const uint8_t type = std::filesystem::is_directory(p, ec) ? FileType_Directory : FileType_NormalFile; oxTrace("ox::fs::PassThroughFS::stat") << ec.message().c_str() << path; - uint64_t size = type == FileType_Directory ? 0 : std::filesystem::file_size(p, ec); + const uint64_t size = type == FileType_Directory ? 0 : std::filesystem::file_size(p, ec); oxTrace("ox::fs::PassThroughFS::stat") << ec.message().c_str() << path; oxTrace("ox::fs::PassThroughFS::stat::size") << path << size; oxReturnError(OxError(ec.value())); @@ -160,14 +160,14 @@ uint64_t PassThroughFS::spaceNeeded(uint64_t size) noexcept { Result PassThroughFS::available() noexcept { std::error_code ec; - auto s = std::filesystem::space(m_path, ec); + const auto s = std::filesystem::space(m_path, ec); oxReturnError(OxError(ec.value(), "PassThroughFS: could not get FS size")); return s.available; } Result PassThroughFS::size() const noexcept { std::error_code ec; - auto s = std::filesystem::space(m_path, ec); + const auto s = std::filesystem::space(m_path, ec); oxReturnError(OxError(ec.value(), "PassThroughFS: could not get FS size")); return s.capacity; } @@ -177,12 +177,12 @@ char *PassThroughFS::buff() noexcept { } Error PassThroughFS::walk(Error(*)(uint8_t, uint64_t, uint64_t)) noexcept { - return OxError(1); + return OxError(1, "walk(Error(*)(uint8_t, uint64_t, uint64_t)) is not supported by PassThroughFS"); } bool PassThroughFS::valid() const noexcept { std::error_code ec; - auto out = std::filesystem::is_directory(m_path, ec); + const auto out = std::filesystem::is_directory(m_path, ec); if (!ec.value()) { return out; } @@ -190,8 +190,8 @@ bool PassThroughFS::valid() const noexcept { } const char *PassThroughFS::stripSlash(const char *path) noexcept { - auto pathLen = ox_strlen(path); - for (decltype(pathLen) i = 0; i < pathLen && path[0] == '/'; i++) { + const auto pathLen = ox_strlen(path); + for (auto i = 0u; i < pathLen && path[0] == '/'; i++) { path++; } return path; diff --git a/deps/ox/src/ox/fs/filesystem/passthroughfs.hpp b/deps/ox/src/ox/fs/filesystem/passthroughfs.hpp index a1f0ad02..558ef8c1 100644 --- a/deps/ox/src/ox/fs/filesystem/passthroughfs.hpp +++ b/deps/ox/src/ox/fs/filesystem/passthroughfs.hpp @@ -84,7 +84,7 @@ class PassThroughFS: public FileSystem { /** * Strips the leading slashes from a string. */ - const char *stripSlash(const char *path) noexcept; + static const char *stripSlash(const char *path) noexcept; }; @@ -94,7 +94,7 @@ Error PassThroughFS::ls(const char *dir, F cb) noexcept { const auto di = std::filesystem::directory_iterator(m_path / stripSlash(dir), ec); oxReturnError(OxError(ec.value(), "PassThroughFS: ls failed")); for (auto &p : di) { - auto u8p = p.path().filename().u8string(); + const auto u8p = p.path().filename().u8string(); oxReturnError(cb(bit_cast(u8p.c_str()), 0)); } return OxError(0);