[ox] Make ValErr::operator T() explicit

This commit is contained in:
2019-07-30 19:00:01 -05:00
parent 2b536ff053
commit c27cc56e31
6 changed files with 44 additions and 34 deletions

View File

@@ -167,19 +167,19 @@ ox::Error Directory<FileStore, InodeId_t>::mkdir(PathIterator path, bool parents
oxReturnError(childInode.error);
// initialize the directory
Directory<FileStore, InodeId_t> child(m_fs, childInode);
Directory<FileStore, InodeId_t> child(m_fs, childInode.value);
oxReturnError(child.init());
auto err = write(name->c_str(), childInode);
auto err = write(name->c_str(), childInode.value);
if (err) {
oxLogError(err);
// could not index the directory, delete it
oxLogError(m_fs.remove(childInode));
oxLogError(m_fs.remove(childInode.value));
return err;
}
}
Directory<FileStore, InodeId_t> child(m_fs, childInode);
Directory<FileStore, InodeId_t> child(m_fs, childInode.value);
if (path.hasNext()) {
oxReturnError(child.mkdir(path.next(), parents, nameBuff));
}
@@ -189,8 +189,6 @@ ox::Error Directory<FileStore, InodeId_t>::mkdir(PathIterator path, bool parents
template<typename FileStore, typename InodeId_t>
ox::Error Directory<FileStore, InodeId_t>::write(PathIterator path, InodeId_t inode, FileName *nameBuff) noexcept {
InodeId_t nextChild = 0;
// reuse nameBuff if it has already been allocated, as it is a rather large variable
if (nameBuff == nullptr) {
nameBuff = reinterpret_cast<FileName*>(ox_alloca(sizeof(FileName)));
@@ -203,7 +201,9 @@ ox::Error Directory<FileStore, InodeId_t>::write(PathIterator path, InodeId_t in
oxTrace("ox::fs::Directory::write") << "Attempting to write to next sub-Directory: "
<< name->c_str() << " of " << path.fullPath();
nextChild = findEntry(*name);
auto [nextChild, err] = findEntry(*name);
oxReturnError(err);
oxTrace("ox::fs::Directory::write") << name->c_str() << ": " << nextChild;
if (nextChild) {

View File

@@ -184,8 +184,8 @@ ox::Error FileSystemTemplate<FileStore, Directory>::move(const char *src, const
auto fd = fileSystemData();
oxReturnError(fd.error);
Directory rootDir(m_fs, fd.value.rootDirInode);
auto inode = rootDir.find(src);
oxReturnError(inode.error);
auto [inode, err] = rootDir.find(src);
oxReturnError(err);
oxReturnError(rootDir.write(dest, inode));
oxReturnError(rootDir.remove(src));
return OxError(0);
@@ -196,8 +196,8 @@ ox::Error FileSystemTemplate<FileStore, Directory>::read(const char *path, void
auto fd = fileSystemData();
oxReturnError(fd.error);
Directory rootDir(m_fs, fd.value.rootDirInode);
auto inode = rootDir.find(path);
oxReturnError(inode.error);
auto [inode, err] = rootDir.find(path);
oxReturnError(err);
return read(inode, buffer, buffSize);
}
@@ -227,12 +227,12 @@ ox::Error FileSystemTemplate<FileStore, Directory>::remove(const char *path, boo
Directory rootDir(m_fs, fd.value.rootDirInode);
auto inode = rootDir.find(path);
oxReturnError(inode.error);
auto st = stat(inode);
auto st = stat(inode.value);
oxReturnError(st.error);
if (st.value.fileType == FileType_NormalFile || recursive) {
if (auto err = rootDir.remove(path)) {
// removal failed, try putting the index back
oxLogError(rootDir.write(path, inode));
oxLogError(rootDir.write(path, inode.value));
return err;
}
} else {
@@ -255,9 +255,11 @@ ox::Error FileSystemTemplate<FileStore, Directory>::resize(uint64_t size, void *
template<typename FileStore, typename Directory>
ox::Error FileSystemTemplate<FileStore, Directory>::write(const char *path, void *buffer, uint64_t size, uint8_t fileType) {
auto inode = find(path);
if (inode.error) {
inode.value = m_fs.generateInodeId();
auto [inode, err] = find(path);
if (err) {
auto generated = m_fs.generateInodeId();
oxReturnError(generated.error);
inode = generated.value;
}
auto rootDir = this->rootDir();
oxReturnError(rootDir.error);

View File

@@ -182,7 +182,7 @@ map<string, int(*)(string)> tests = {
oxTrace("ox::fs::test::Directory") << "find";
oxAssert(dir.find("file1").error, "Could not find file1");
oxAssert(dir.find("file1") == 1, "Could not find file1");
oxAssert(dir.find("file1").value == 1, "Could not find file1");
oxTrace("ox::fs::test::Directory") << "write 2";
oxAssert(dir.write("/file3", 3) == 0, "Directory write of file3 failed");