From db04367579c992bbd568d3eca85d2ce3297291b1 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Thu, 20 Jun 2019 23:24:36 -0500 Subject: [PATCH] [ox/fs] Cleanup hard-to-read code --- deps/ox/src/ox/fs/filesystem/directory.hpp | 8 ++++---- deps/ox/src/ox/fs/filesystem/passthroughfs.cpp | 1 + deps/ox/src/ox/fs/filesystem/pathiterator.cpp | 4 ++-- deps/ox/src/ox/fs/filesystem/pathiterator.hpp | 2 +- deps/ox/src/ox/fs/test/tests.cpp | 4 +++- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/deps/ox/src/ox/fs/filesystem/directory.hpp b/deps/ox/src/ox/fs/filesystem/directory.hpp index b6c8a8f5..9f72f5f3 100644 --- a/deps/ox/src/ox/fs/filesystem/directory.hpp +++ b/deps/ox/src/ox/fs/filesystem/directory.hpp @@ -183,7 +183,7 @@ Error Directory::mkdir(PathIterator path, bool parents, Fi Directory child(m_fs, childInode); if (path.hasNext()) { - oxReturnError(child.mkdir(path + 1, parents, nameBuff)); + oxReturnError(child.mkdir(path.next(), parents, nameBuff)); } } return OxError(0); @@ -199,7 +199,7 @@ Error Directory::write(PathIterator path, InodeId_t inode, } auto name = nameBuff; - if ((path + 1).hasNext()) { + if (path.next().hasNext()) { // not yet at target directory, recurse to next one oxReturnError(path.get(name)); oxTrace("ox::fs::Directory::write") << "Attempting to write to next sub-Directory: " @@ -212,7 +212,7 @@ Error Directory::write(PathIterator path, InodeId_t inode, // reuse name because it is a rather large variable and will not be used again // be attentive that this remains true name = nullptr; - return Directory(m_fs, nextChild).write(path + 1, inode, nameBuff); + return Directory(m_fs, nextChild).write(path.next(), inode, nameBuff); } else { oxTrace("ox::fs::Directory::write") << name->c_str() << "not found and not allowed to create it."; @@ -356,7 +356,7 @@ ValErr Directory::find(Path return v; } name = nullptr; - v = find(path + 1, nameBuff); + v = find(path.next(), nameBuff); if (!v.error) { return v; } diff --git a/deps/ox/src/ox/fs/filesystem/passthroughfs.cpp b/deps/ox/src/ox/fs/filesystem/passthroughfs.cpp index e34bd0cc..86508aec 100644 --- a/deps/ox/src/ox/fs/filesystem/passthroughfs.cpp +++ b/deps/ox/src/ox/fs/filesystem/passthroughfs.cpp @@ -54,6 +54,7 @@ Error PassThroughFS::read(const char *path, void *buffer, std::size_t buffSize) return OxError(itemsRead == 1 ? 0 : 1); } } + oxTrace("ox::fs::PassThroughFS::read::error") << "Read failed: " << path; return OxError(1); } diff --git a/deps/ox/src/ox/fs/filesystem/pathiterator.cpp b/deps/ox/src/ox/fs/filesystem/pathiterator.cpp index e3694d02..88e48af0 100644 --- a/deps/ox/src/ox/fs/filesystem/pathiterator.cpp +++ b/deps/ox/src/ox/fs/filesystem/pathiterator.cpp @@ -181,7 +181,7 @@ bool PathIterator::valid() const { return m_iterator < m_maxSize && m_path[m_iterator] != 0; } -PathIterator PathIterator::operator+(int i) const { +PathIterator PathIterator::next() const { std::size_t size = 0; auto iterator = m_iterator; if (iterator < m_maxSize && ox_strlen(&m_path[iterator])) { @@ -199,7 +199,7 @@ PathIterator PathIterator::operator+(int i) const { size = end - start; } iterator += size; - return PathIterator(m_path, m_maxSize, iterator + i); + return PathIterator(m_path, m_maxSize, iterator + 1); } const char *PathIterator::fullPath() const { diff --git a/deps/ox/src/ox/fs/filesystem/pathiterator.hpp b/deps/ox/src/ox/fs/filesystem/pathiterator.hpp index 1be28ba7..3d4172c5 100644 --- a/deps/ox/src/ox/fs/filesystem/pathiterator.hpp +++ b/deps/ox/src/ox/fs/filesystem/pathiterator.hpp @@ -65,7 +65,7 @@ class PathIterator { bool valid() const; - PathIterator operator+(int i) const; + [[nodiscard]] PathIterator next() const; const char *fullPath() const; diff --git a/deps/ox/src/ox/fs/test/tests.cpp b/deps/ox/src/ox/fs/test/tests.cpp index cb46d4d9..3d317aee 100644 --- a/deps/ox/src/ox/fs/test/tests.cpp +++ b/deps/ox/src/ox/fs/test/tests.cpp @@ -115,7 +115,7 @@ map tests = { const auto path = "/file1"; PathIterator it(path, ox_strlen(path)); oxAssert(it.hasNext(), "PathIterator shows incorrect hasNext"); - oxAssert(!(it + 1).hasNext(), "PathIterator shows incorrect hasNext"); + oxAssert(!it.next().hasNext(), "PathIterator shows incorrect hasNext"); return retval; } }, @@ -202,6 +202,8 @@ map tests = { ox::FileSystem32 fs(ox::FileStore32(fsBuff.data(), fsBuff.size())); oxTrace("ox::fs::test::FileSystem") << "mkdir"; + oxAssert(fs.mkdir("/dir", true), "mkdir failed"); + oxAssert(fs.stat("/dir").error, "mkdir failed"); oxAssert(fs.mkdir("/l1d1/l2d1/l3d1", true), "mkdir failed"); oxAssert(fs.stat("/l1d1/l2d1/l3d1").error, "mkdir failed"); oxAssert(fs.mkdir("/l1d1/l2d2", true), "mkdir failed");