[ox/fs] Cleanup hard-to-read code
This commit is contained in:
parent
c87eed730e
commit
db04367579
8
deps/ox/src/ox/fs/filesystem/directory.hpp
vendored
8
deps/ox/src/ox/fs/filesystem/directory.hpp
vendored
@ -183,7 +183,7 @@ Error Directory<FileStore, InodeId_t>::mkdir(PathIterator path, bool parents, Fi
|
||||
|
||||
Directory<FileStore, InodeId_t> 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<FileStore, InodeId_t>::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<FileStore, InodeId_t>::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<typename FileStore::InodeId_t> Directory<FileStore, InodeId_t>::find(Path
|
||||
return v;
|
||||
}
|
||||
name = nullptr;
|
||||
v = find(path + 1, nameBuff);
|
||||
v = find(path.next(), nameBuff);
|
||||
if (!v.error) {
|
||||
return v;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -65,7 +65,7 @@ class PathIterator {
|
||||
|
||||
bool valid() const;
|
||||
|
||||
PathIterator operator+(int i) const;
|
||||
[[nodiscard]] PathIterator next() const;
|
||||
|
||||
const char *fullPath() const;
|
||||
|
||||
|
4
deps/ox/src/ox/fs/test/tests.cpp
vendored
4
deps/ox/src/ox/fs/test/tests.cpp
vendored
@ -115,7 +115,7 @@ map<string, int(*)(string)> 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<string, int(*)(string)> 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");
|
||||
|
Loading…
x
Reference in New Issue
Block a user