[nostalgia/tools/pack] Add missing error checking

This commit is contained in:
Gary Talent 2019-06-22 02:08:28 -05:00
parent 74fe0c55cc
commit 74d1bb08fe
2 changed files with 9 additions and 10 deletions

View File

@ -21,7 +21,7 @@ using namespace ox;
using namespace nostalgia::core; using namespace nostalgia::core;
using namespace nostalgia::common; using namespace nostalgia::common;
ox::ValErr<std::vector<uint8_t>> loadFileBuff(std::string path, ::size_t *sizeOut = nullptr) { [[nodiscard]] ox::ValErr<std::vector<uint8_t>> loadFileBuff(std::string path, ::size_t *sizeOut = nullptr) {
auto file = fopen(path.c_str(), "rb"); auto file = fopen(path.c_str(), "rb");
if (file) { if (file) {
fseek(file, 0, SEEK_END); fseek(file, 0, SEEK_END);
@ -39,7 +39,7 @@ ox::ValErr<std::vector<uint8_t>> loadFileBuff(std::string path, ::size_t *sizeOu
} }
} }
ox::Error run(ClArgs args) { [[nodiscard]] ox::Error run(ClArgs args) {
std::string argSrc = args.getString("src").c_str(); std::string argSrc = args.getString("src").c_str();
std::string argDst = args.getString("dst").c_str(); std::string argDst = args.getString("dst").c_str();
if (argSrc == "") { if (argSrc == "") {
@ -51,7 +51,7 @@ ox::Error run(ClArgs args) {
return OxError(1); return OxError(1);
} }
std::vector<uint8_t> buff(32 * ox::units::MB); std::vector<uint8_t> buff(32 * ox::units::MB);
ox::FileSystem32::format(buff.data(), buff.size()); oxReturnError(ox::FileSystem32::format(buff.data(), buff.size()));
ox::PassThroughFS src(argSrc.c_str()); ox::PassThroughFS src(argSrc.c_str());
ox::FileSystem32 dst(ox::FileStore32(buff.data(), buff.size())); ox::FileSystem32 dst(ox::FileStore32(buff.data(), buff.size()));
auto err = nostalgia::pack(&src, &dst); auto err = nostalgia::pack(&src, &dst);

View File

@ -27,20 +27,20 @@ namespace {
* @return error * @return error
* stub for now * stub for now
*/ */
ox::Error pathToInode(std::vector<char>*) { [[nodiscard]] ox::Error pathToInode(std::vector<char>*) {
return OxError(0); return OxError(0);
} }
// stub for now // stub for now
ox::Error toMetalClaw(std::vector<char>*) { [[nodiscard]] ox::Error toMetalClaw(std::vector<char>*) {
return OxError(0); return OxError(0);
} }
// claw file transformations are broken out because path to inode // claw file transformations are broken out because path to inode
// transformations need to be done after the copy to the new FS is complete // transformations need to be done after the copy to the new FS is complete
ox::Error transformClaw(ox::FileSystem32 *dest, std::string path) { [[nodiscard]] ox::Error transformClaw(ox::FileSystem32 *dest, std::string path) {
// copy // copy
dest->ls(path.c_str(), [dest, path](const char *name, ox::InodeId_t) { return dest->ls(path.c_str(), [dest, path](const char *name, ox::InodeId_t) {
auto [stat, err] = dest->stat(path.c_str()); auto [stat, err] = dest->stat(path.c_str());
oxReturnError(err); oxReturnError(err);
if (stat.fileType == ox::FileType_Directory) { if (stat.fileType == ox::FileType_Directory) {
@ -61,7 +61,6 @@ ox::Error transformClaw(ox::FileSystem32 *dest, std::string path) {
} }
return OxError(0); return OxError(0);
}); });
return OxError(0);
} }
[[nodiscard]] ox::Error verifyFile(ox::FileSystem32 *fs, const std::string &path, const std::vector<char> &expected) noexcept { [[nodiscard]] ox::Error verifyFile(ox::FileSystem32 *fs, const std::string &path, const std::vector<char> &expected) noexcept {
@ -70,7 +69,7 @@ ox::Error transformClaw(ox::FileSystem32 *dest, std::string path) {
return buff == expected ? 0 : OxError(1); return buff == expected ? 0 : OxError(1);
} }
ox::Error copy(ox::PassThroughFS *src, ox::FileSystem32 *dest, std::string path) { [[nodiscard]] ox::Error copy(ox::PassThroughFS *src, ox::FileSystem32 *dest, std::string path) {
std::cout << "copying directory: " << path << '\n'; std::cout << "copying directory: " << path << '\n';
// copy // copy
return src->ls(path.c_str(), [src, dest, path](const char *name, ox::InodeId_t) { return src->ls(path.c_str(), [src, dest, path](const char *name, ox::InodeId_t) {
@ -107,7 +106,7 @@ ox::Error copy(ox::PassThroughFS *src, ox::FileSystem32 *dest, std::string path)
} }
ox::Error pack(ox::PassThroughFS *src, ox::FileSystem32 *dest, std::string path) { [[nodiscard]] ox::Error pack(ox::PassThroughFS *src, ox::FileSystem32 *dest, std::string path) {
oxReturnError(copy(src, dest, path)); oxReturnError(copy(src, dest, path));
oxReturnError(transformClaw(dest, path)); oxReturnError(transformClaw(dest, path));
return OxError(0); return OxError(0);