From dc6605fd4848e56c4f86af4c7faa39f2ba87cc4a Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Tue, 26 Nov 2024 23:32:15 -0600 Subject: [PATCH] [keel] Add missing error checking to pack --- src/olympic/keel/src/pack.cpp | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/olympic/keel/src/pack.cpp b/src/olympic/keel/src/pack.cpp index 1f18eb60..3810f166 100644 --- a/src/olympic/keel/src/pack.cpp +++ b/src/olympic/keel/src/pack.cpp @@ -15,16 +15,22 @@ static ox::Error pathToInode( ox::FileSystem &dest, ox::ModelObject &obj) noexcept { auto &o = obj; - auto type = static_cast(o.at("type").unwrap()->get()); - auto &data = o.at("data").unwrap()->get(); + oxRequire(typeVal, o.at("type")); + auto const type = static_cast(typeVal->get()); + oxRequire(dataVal, o.at("data")); + auto &data = dataVal->get(); ox::String path; switch (type) { - case ox::FileAddressType::Path: - path = data.at("path").unwrap()->get(); + case ox::FileAddressType::Path: { + oxRequire(pathVal, data.at("path")); + path = pathVal->get(); break; - case ox::FileAddressType::ConstPath: - path = data.at("constPath").unwrap()->get(); + } + case ox::FileAddressType::ConstPath: { + oxRequire(pathVal, data.at("constPath")); + path = pathVal->get(); break; + } case ox::FileAddressType::Inode: case ox::FileAddressType::None: return {}; @@ -34,7 +40,7 @@ static ox::Error pathToInode( oxReturnError(keel::uuidToPath(ctx, uuid).to().moveTo(path)); } oxRequire(s, dest.stat(path)); - oxReturnError(o.at("type").unwrap()->set(static_cast(ox::FileAddressType::Inode))); + oxReturnError(typeVal->set(static_cast(ox::FileAddressType::Inode))); oxOutf("\tpath to inode: {} => {}\n", path, s.inode); return data.set(2, s.inode); } @@ -162,12 +168,12 @@ static ox::Error copy( // copy oxRequire(fileList, src.ls(path)); for (auto const&name : fileList) { - auto currentFile = ox::sfmt("{}{}", path, name); + auto const currentFile = ox::sfmt("{}{}", path, name); if (beginsWith(name, ".")) { continue; } - oxRequire(stat, src.stat(currentFile)); - if (stat.fileType == ox::FileType::Directory) { + oxRequire(srcStat, src.stat(currentFile)); + if (srcStat.fileType == ox::FileType::Directory) { oxReturnError(dest.mkdir(currentFile, true)); oxReturnError(copy(manifest, src, dest, currentFile + '/', childLogPrefix)); } else { @@ -181,9 +187,9 @@ static ox::Error copy( // write file to dest oxReturnError(dest.write(currentFile, buff)); status = "OK"; - oxRequire(stat, dest.stat(currentFile)); + oxRequire(dstStat, dest.stat(currentFile)); manifest.files[currentFile] = { - .inode = stat.inode, + .inode = dstStat.inode, .type = ox::String{keel::readAssetTypeId(buff).or_value({})}, }; }