[keel] Add missing error checking to pack

This commit is contained in:
Gary Talent 2024-11-26 23:32:15 -06:00
parent c78d3cf638
commit dc6605fd48

View File

@ -15,16 +15,22 @@ static ox::Error pathToInode(
ox::FileSystem &dest, ox::FileSystem &dest,
ox::ModelObject &obj) noexcept { ox::ModelObject &obj) noexcept {
auto &o = obj; auto &o = obj;
auto type = static_cast<ox::FileAddressType>(o.at("type").unwrap()->get<int8_t>()); oxRequire(typeVal, o.at("type"));
auto &data = o.at("data").unwrap()->get<ox::ModelUnion>(); auto const type = static_cast<ox::FileAddressType>(typeVal->get<int8_t>());
oxRequire(dataVal, o.at("data"));
auto &data = dataVal->get<ox::ModelUnion>();
ox::String path; ox::String path;
switch (type) { switch (type) {
case ox::FileAddressType::Path: case ox::FileAddressType::Path: {
path = data.at("path").unwrap()->get<ox::String>(); oxRequire(pathVal, data.at("path"));
path = pathVal->get<ox::String>();
break; break;
case ox::FileAddressType::ConstPath: }
path = data.at("constPath").unwrap()->get<ox::String>(); case ox::FileAddressType::ConstPath: {
oxRequire(pathVal, data.at("constPath"));
path = pathVal->get<ox::String>();
break; break;
}
case ox::FileAddressType::Inode: case ox::FileAddressType::Inode:
case ox::FileAddressType::None: case ox::FileAddressType::None:
return {}; return {};
@ -34,7 +40,7 @@ static ox::Error pathToInode(
oxReturnError(keel::uuidToPath(ctx, uuid).to<ox::String>().moveTo(path)); oxReturnError(keel::uuidToPath(ctx, uuid).to<ox::String>().moveTo(path));
} }
oxRequire(s, dest.stat(path)); oxRequire(s, dest.stat(path));
oxReturnError(o.at("type").unwrap()->set(static_cast<int8_t>(ox::FileAddressType::Inode))); oxReturnError(typeVal->set(static_cast<int8_t>(ox::FileAddressType::Inode)));
oxOutf("\tpath to inode: {} => {}\n", path, s.inode); oxOutf("\tpath to inode: {} => {}\n", path, s.inode);
return data.set(2, s.inode); return data.set(2, s.inode);
} }
@ -162,12 +168,12 @@ static ox::Error copy(
// copy // copy
oxRequire(fileList, src.ls(path)); oxRequire(fileList, src.ls(path));
for (auto const&name : fileList) { for (auto const&name : fileList) {
auto currentFile = ox::sfmt("{}{}", path, name); auto const currentFile = ox::sfmt("{}{}", path, name);
if (beginsWith(name, ".")) { if (beginsWith(name, ".")) {
continue; continue;
} }
oxRequire(stat, src.stat(currentFile)); oxRequire(srcStat, src.stat(currentFile));
if (stat.fileType == ox::FileType::Directory) { if (srcStat.fileType == ox::FileType::Directory) {
oxReturnError(dest.mkdir(currentFile, true)); oxReturnError(dest.mkdir(currentFile, true));
oxReturnError(copy(manifest, src, dest, currentFile + '/', childLogPrefix)); oxReturnError(copy(manifest, src, dest, currentFile + '/', childLogPrefix));
} else { } else {
@ -181,9 +187,9 @@ static ox::Error copy(
// write file to dest // write file to dest
oxReturnError(dest.write(currentFile, buff)); oxReturnError(dest.write(currentFile, buff));
status = "OK"; status = "OK";
oxRequire(stat, dest.stat(currentFile)); oxRequire(dstStat, dest.stat(currentFile));
manifest.files[currentFile] = { manifest.files[currentFile] = {
.inode = stat.inode, .inode = dstStat.inode,
.type = ox::String{keel::readAssetTypeId(buff).or_value({})}, .type = ox::String{keel::readAssetTypeId(buff).or_value({})},
}; };
} }