[ox] Cleanup some old style error handling
This commit is contained in:
@@ -445,7 +445,7 @@ Result<StatInfo> FileStoreTemplate<size_t>::stat(InodeId_t id) {
|
||||
inode->fileType,
|
||||
});
|
||||
}
|
||||
return Result<StatInfo>({}, OxError(0));
|
||||
return {};
|
||||
}
|
||||
|
||||
template<typename size_t>
|
||||
@@ -486,9 +486,9 @@ Result<typename FileStoreTemplate<size_t>::InodeId_t> FileStoreTemplate<size_t>:
|
||||
return inode;
|
||||
}
|
||||
}
|
||||
return {0, OxError(2)};
|
||||
return OxError(2);
|
||||
}
|
||||
return {0, OxError(1)};
|
||||
return OxError(1);
|
||||
}
|
||||
|
||||
template<typename size_t>
|
||||
|
4
deps/ox/src/ox/fs/filesystem/directory.hpp
vendored
4
deps/ox/src/ox/fs/filesystem/directory.hpp
vendored
@@ -319,7 +319,7 @@ Result<typename FileStore::InodeId_t> Directory<FileStore, InodeId_t>::findEntry
|
||||
auto buff = m_fs.read(m_inodeId).template to<Buffer>();
|
||||
if (!buff.valid()) {
|
||||
oxTrace("ox::fs::Directory::findEntry::fail") << "Could not findEntry directory buffer";
|
||||
return {0, OxError(2)};
|
||||
return OxError(2);
|
||||
}
|
||||
oxTrace("ox::fs::Directory::findEntry") << "Found directory buffer, size:" << buff.size();
|
||||
for (auto i = buff->iterator(); i.valid(); i.next()) {
|
||||
@@ -335,7 +335,7 @@ Result<typename FileStore::InodeId_t> Directory<FileStore, InodeId_t>::findEntry
|
||||
}
|
||||
}
|
||||
oxTrace("ox::fs::Directory::findEntry::fail") << "Entry not present";
|
||||
return {0, OxError(1)};
|
||||
return OxError(1);
|
||||
}
|
||||
|
||||
template<typename FileStore, typename InodeId_t>
|
||||
|
52
deps/ox/src/ox/fs/filesystem/filesystem.hpp
vendored
52
deps/ox/src/ox/fs/filesystem/filesystem.hpp
vendored
@@ -316,9 +316,8 @@ template<typename FileStore, typename Directory>
|
||||
Error FileSystemTemplate<FileStore, Directory>::write(const char *path, void *buffer, uint64_t size, uint8_t fileType) noexcept {
|
||||
auto [inode, err] = find(path);
|
||||
if (err) {
|
||||
auto generated = m_fs.generateInodeId();
|
||||
oxReturnError(generated.error);
|
||||
inode = generated.value;
|
||||
oxRequire(generatedId, m_fs.generateInodeId());
|
||||
inode = generatedId;
|
||||
}
|
||||
auto rootDir = this->rootDir();
|
||||
oxReturnError(rootDir.error);
|
||||
@@ -334,22 +333,19 @@ Error FileSystemTemplate<FileStore, Directory>::write(uint64_t inode, void *buff
|
||||
|
||||
template<typename FileStore, typename Directory>
|
||||
Result<FileStat> FileSystemTemplate<FileStore, Directory>::stat(uint64_t inode) noexcept {
|
||||
auto s = m_fs.stat(inode);
|
||||
oxRequire(s, m_fs.stat(inode));
|
||||
FileStat out;
|
||||
out.inode = s.value.inode;
|
||||
out.links = s.value.links;
|
||||
out.size = s.value.size;
|
||||
out.fileType = s.value.fileType;
|
||||
return {out, s.error};
|
||||
out.inode = s.inode;
|
||||
out.links = s.links;
|
||||
out.size = s.size;
|
||||
out.fileType = s.fileType;
|
||||
return out;
|
||||
}
|
||||
|
||||
template<typename FileStore, typename Directory>
|
||||
Result<FileStat> FileSystemTemplate<FileStore, Directory>::stat(const char *path) noexcept {
|
||||
auto inode = find(path);
|
||||
if (inode.error) {
|
||||
return {{}, inode.error};
|
||||
}
|
||||
return stat(inode.value);
|
||||
oxRequire(inode, find(path));
|
||||
return stat(inode);
|
||||
}
|
||||
|
||||
template<typename FileStore, typename Directory>
|
||||
@@ -385,38 +381,26 @@ bool FileSystemTemplate<FileStore, Directory>::valid() const noexcept {
|
||||
template<typename FileStore, typename Directory>
|
||||
Result<typename FileSystemTemplate<FileStore, Directory>::FileSystemData> FileSystemTemplate<FileStore, Directory>::fileSystemData() const noexcept {
|
||||
FileSystemData fd;
|
||||
auto err = m_fs.read(InodeFsData, &fd, sizeof(fd));
|
||||
if (err != 0) {
|
||||
return {fd, err};
|
||||
}
|
||||
oxReturnError(m_fs.read(InodeFsData, &fd, sizeof(fd)));
|
||||
return fd;
|
||||
}
|
||||
|
||||
template<typename FileStore, typename Directory>
|
||||
Result<uint64_t> FileSystemTemplate<FileStore, Directory>::find(const char *path) const noexcept {
|
||||
auto fd = fileSystemData();
|
||||
if (fd.error) {
|
||||
return {0, fd.error};
|
||||
}
|
||||
oxRequire(fd, fileSystemData());
|
||||
// return root as a special case
|
||||
if (ox_strcmp(path, "/") == 0) {
|
||||
return static_cast<uint64_t>(fd.value.rootDirInode);
|
||||
return static_cast<uint64_t>(fd.rootDirInode);
|
||||
}
|
||||
Directory rootDir(m_fs, fd.value.rootDirInode);
|
||||
auto inode = rootDir.find(path);
|
||||
if (inode.error) {
|
||||
return {0, inode.error};
|
||||
}
|
||||
return inode.value;
|
||||
Directory rootDir(m_fs, fd.rootDirInode);
|
||||
oxRequire(out, rootDir.find(path));
|
||||
return static_cast<uint64_t>(out);
|
||||
}
|
||||
|
||||
template<typename FileStore, typename Directory>
|
||||
Result<Directory> FileSystemTemplate<FileStore, Directory>::rootDir() const noexcept {
|
||||
auto fd = fileSystemData();
|
||||
if (fd.error) {
|
||||
return {{}, fd.error};
|
||||
}
|
||||
return Directory(m_fs, fd.value.rootDirInode);
|
||||
oxRequire(fd, fileSystemData());
|
||||
return Directory(m_fs, fd.rootDirInode);
|
||||
}
|
||||
|
||||
extern template class FileSystemTemplate<FileStore16, Directory16>;
|
||||
|
@@ -136,7 +136,8 @@ Result<FileStat> PassThroughFS::stat(const char *path) noexcept {
|
||||
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;
|
||||
return {{0, 0, size, type}, OxError(ec.value())};
|
||||
oxReturnError(OxError(ec.value()));
|
||||
return FileStat{0, 0, size, type};
|
||||
}
|
||||
|
||||
uint64_t PassThroughFS::spaceNeeded(uint64_t size) noexcept {
|
||||
|
Reference in New Issue
Block a user