[ox/fs] Cleanup error handling
This commit is contained in:
parent
b3fb724ae7
commit
6845ff38de
54
deps/ox/src/ox/fs/filesystem/filesystem.hpp
vendored
54
deps/ox/src/ox/fs/filesystem/filesystem.hpp
vendored
@ -221,18 +221,15 @@ Error FileSystemTemplate<FileStore, Directory>::format(void *buff, uint64_t buff
|
|||||||
template<typename FileStore, typename Directory>
|
template<typename FileStore, typename Directory>
|
||||||
Error FileSystemTemplate<FileStore, Directory>::mkdir(const char *path, bool recursive) noexcept {
|
Error FileSystemTemplate<FileStore, Directory>::mkdir(const char *path, bool recursive) noexcept {
|
||||||
oxTrace("ox::fs::FileSystemTemplate::mkdir") << "path:" << path << "recursive:" << recursive;
|
oxTrace("ox::fs::FileSystemTemplate::mkdir") << "path:" << path << "recursive:" << recursive;
|
||||||
auto rootDir = this->rootDir();
|
oxRequireM(rootDir, this->rootDir());
|
||||||
oxReturnError(rootDir.error);
|
return rootDir.mkdir(path, recursive);
|
||||||
return rootDir.value.mkdir(path, recursive);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename FileStore, typename Directory>
|
template<typename FileStore, typename Directory>
|
||||||
Error FileSystemTemplate<FileStore, Directory>::move(const char *src, const char *dest) noexcept {
|
Error FileSystemTemplate<FileStore, Directory>::move(const char *src, const char *dest) noexcept {
|
||||||
auto fd = fileSystemData();
|
oxRequire(fd, fileSystemData());
|
||||||
oxReturnError(fd.error);
|
Directory rootDir(m_fs, fd.rootDirInode);
|
||||||
Directory rootDir(m_fs, fd.value.rootDirInode);
|
oxRequireM(inode, rootDir.find(src));
|
||||||
auto [inode, err] = rootDir.find(src);
|
|
||||||
oxReturnError(err);
|
|
||||||
oxReturnError(rootDir.write(dest, inode));
|
oxReturnError(rootDir.write(dest, inode));
|
||||||
oxReturnError(rootDir.remove(src));
|
oxReturnError(rootDir.remove(src));
|
||||||
return OxError(0);
|
return OxError(0);
|
||||||
@ -240,21 +237,17 @@ Error FileSystemTemplate<FileStore, Directory>::move(const char *src, const char
|
|||||||
|
|
||||||
template<typename FileStore, typename Directory>
|
template<typename FileStore, typename Directory>
|
||||||
Error FileSystemTemplate<FileStore, Directory>::read(const char *path, void *buffer, std::size_t buffSize) noexcept {
|
Error FileSystemTemplate<FileStore, Directory>::read(const char *path, void *buffer, std::size_t buffSize) noexcept {
|
||||||
auto fd = fileSystemData();
|
oxRequire(fd, fileSystemData());
|
||||||
oxReturnError(fd.error);
|
Directory rootDir(m_fs, fd.rootDirInode);
|
||||||
Directory rootDir(m_fs, fd.value.rootDirInode);
|
oxRequire(inode, rootDir.find(path));
|
||||||
auto [inode, err] = rootDir.find(path);
|
|
||||||
oxReturnError(err);
|
|
||||||
return read(inode, buffer, buffSize);
|
return read(inode, buffer, buffSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename FileStore, typename Directory>
|
template<typename FileStore, typename Directory>
|
||||||
Result<const char*> FileSystemTemplate<FileStore, Directory>::directAccess(const char *path) noexcept {
|
Result<const char*> FileSystemTemplate<FileStore, Directory>::directAccess(const char *path) noexcept {
|
||||||
auto fd = fileSystemData();
|
oxRequire(fd, fileSystemData());
|
||||||
oxReturnError(fd.error);
|
Directory rootDir(m_fs, fd.rootDirInode);
|
||||||
Directory rootDir(m_fs, fd.value.rootDirInode);
|
oxRequire(inode, rootDir.find(path));
|
||||||
auto [inode, err] = rootDir.find(path);
|
|
||||||
oxReturnError(err);
|
|
||||||
return directAccess(inode);
|
return directAccess(inode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -290,26 +283,22 @@ Result<Vector<String>> FileSystemTemplate<FileStore, Directory>::ls(const char *
|
|||||||
template<typename FileStore, typename Directory>
|
template<typename FileStore, typename Directory>
|
||||||
template<typename F>
|
template<typename F>
|
||||||
Error FileSystemTemplate<FileStore, Directory>::ls(const char *path, F cb) {
|
Error FileSystemTemplate<FileStore, Directory>::ls(const char *path, F cb) {
|
||||||
oxTrace("ox::FileSystemTemplate::ls") << "path:" << path;
|
oxTrace("ox::fs::FileSystemTemplate::ls") << "path:" << path;
|
||||||
auto [s, err] = stat(path);
|
oxRequire(s, stat(path));
|
||||||
oxReturnError(err);
|
|
||||||
Directory dir(m_fs, s.inode);
|
Directory dir(m_fs, s.inode);
|
||||||
return dir.ls(cb);
|
return dir.ls(cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename FileStore, typename Directory>
|
template<typename FileStore, typename Directory>
|
||||||
Error FileSystemTemplate<FileStore, Directory>::remove(const char *path, bool recursive) noexcept {
|
Error FileSystemTemplate<FileStore, Directory>::remove(const char *path, bool recursive) noexcept {
|
||||||
auto fd = fileSystemData();
|
oxRequire(fd, fileSystemData());
|
||||||
oxReturnError(fd.error);
|
Directory rootDir(m_fs, fd.rootDirInode);
|
||||||
Directory rootDir(m_fs, fd.value.rootDirInode);
|
oxRequire(inode, rootDir.find(path));
|
||||||
auto inode = rootDir.find(path);
|
oxRequire(st, stat(inode));
|
||||||
oxReturnError(inode.error);
|
if (st.fileType == FileType_NormalFile || recursive) {
|
||||||
auto st = stat(inode.value);
|
|
||||||
oxReturnError(st.error);
|
|
||||||
if (st.value.fileType == FileType_NormalFile || recursive) {
|
|
||||||
if (auto err = rootDir.remove(path)) {
|
if (auto err = rootDir.remove(path)) {
|
||||||
// removal failed, try putting the index back
|
// removal failed, try putting the index back
|
||||||
oxLogError(rootDir.write(path, inode.value));
|
oxLogError(rootDir.write(path, inode));
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -337,9 +326,8 @@ Error FileSystemTemplate<FileStore, Directory>::write(const char *path, void *bu
|
|||||||
oxRequire(generatedId, m_fs.generateInodeId());
|
oxRequire(generatedId, m_fs.generateInodeId());
|
||||||
inode = generatedId;
|
inode = generatedId;
|
||||||
}
|
}
|
||||||
auto rootDir = this->rootDir();
|
oxRequireM(rootDir, this->rootDir());
|
||||||
oxReturnError(rootDir.error);
|
oxReturnError(rootDir.write(path, inode));
|
||||||
oxReturnError(rootDir.value.write(path, inode));
|
|
||||||
oxReturnError(write(inode, buffer, size, fileType));
|
oxReturnError(write(inode, buffer, size, fileType));
|
||||||
return OxError(0);
|
return OxError(0);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user