From 304a43a4b44886871430299990c2c5adf570239c Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sat, 17 Apr 2021 17:24:37 -0500 Subject: [PATCH] [nostalgia/tools/pack] Make Pack lib operate on generic ox::FileSystems --- src/nostalgia/tools/pack.cpp | 4 ++-- src/nostalgia/tools/pack/pack.cpp | 25 ++++++++++++++----------- src/nostalgia/tools/pack/pack.hpp | 2 +- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/nostalgia/tools/pack.cpp b/src/nostalgia/tools/pack.cpp index 815cb241..eb7c9205 100644 --- a/src/nostalgia/tools/pack.cpp +++ b/src/nostalgia/tools/pack.cpp @@ -13,7 +13,7 @@ #include "pack/pack.hpp" -static ox::Error writeFileBuff(const ox::String &path, ox::Vector &buff) { +static ox::Error writeFileBuff(const ox::String &path, ox::Vector &buff) noexcept { try { std::ofstream f(path.c_str(), std::ios::binary); f.write(buff.data(), static_cast(buff.size())); @@ -23,7 +23,7 @@ static ox::Error writeFileBuff(const ox::String &path, ox::Vector &buff) { return OxError(0); } -static ox::Error run(const ox::ClArgs &args) { +static ox::Error run(const ox::ClArgs &args) noexcept { auto argSrc = args.getString("src", ""); auto argDst = args.getString("dst", ""); if (argSrc == "") { diff --git a/src/nostalgia/tools/pack/pack.cpp b/src/nostalgia/tools/pack/pack.cpp index ca50147b..2e9f8f4f 100644 --- a/src/nostalgia/tools/pack/pack.cpp +++ b/src/nostalgia/tools/pack/pack.cpp @@ -35,10 +35,12 @@ static ox::Error toMetalClaw(ox::Vector *buff) noexcept { // claw file transformations are broken out because path to inode // transformations need to be done after the copy to the new FS is complete -static ox::Error transformClaw(ox::FileSystem32 *dest, ox::String path) noexcept { +static ox::Error transformClaw(ox::FileSystem *dest, ox::String path) noexcept { // copy oxTrace("pack::transformClaw") << "path:" << path.c_str(); - return dest->ls(path.c_str(), [dest, path](const ox::String &name, ox::InodeId_t) { + oxRequire(fileList, dest->ls(path.c_str())); + for (auto i = 0u; i < fileList.size(); ++i) { + auto &name = fileList[i]; auto filePath = path + name; auto [stat, err] = dest->stat(filePath.c_str()); oxReturnError(err); @@ -58,11 +60,11 @@ static ox::Error transformClaw(ox::FileSystem32 *dest, ox::String path) noexcept oxReturnError(dest->write(filePath.c_str(), buff.data(), buff.size())); } } - return OxError(0); - }); + } + return OxError(0); } -static ox::Error verifyFile(ox::FileSystem32 *fs, const ox::String &path, const ox::Vector &expected) noexcept { +static ox::Error verifyFile(ox::FileSystem *fs, const ox::String &path, const ox::Vector &expected) noexcept { ox::Vector buff(expected.size()); oxReturnError(fs->read(path.c_str(), buff.data(), buff.size())); return OxError(buff == expected ? 0 : 1); @@ -73,14 +75,16 @@ struct VerificationPair { ox::Vector buff; }; -static ox::Error copy(ox::PassThroughFS *src, ox::FileSystem32 *dest, ox::String path) noexcept { +static ox::Error copy(ox::FileSystem *src, ox::FileSystem *dest, ox::String path) noexcept { oxOutf("copying directory: {}\n", path); ox::Vector verificationPairs; // copy - oxReturnError(src->ls(path.c_str(), [&verificationPairs, src, dest, path](const char *name, ox::InodeId_t) noexcept { + oxRequire(fileList, src->ls(path.c_str())); + for (auto i = 0u; i < fileList.size(); ++i) { + auto &name = fileList[i]; auto currentFile = path + name; if (currentFile == "/.nostalgia") { - return OxError(0); + continue; } oxOutf("reading {}\n", name); auto [stat, err] = src->stat((currentFile).c_str()); @@ -99,8 +103,7 @@ static ox::Error copy(ox::PassThroughFS *src, ox::FileSystem32 *dest, ox::String oxReturnError(verifyFile(dest, currentFile, buff)); verificationPairs.push_back({currentFile, buff}); } - return OxError(0); - })); + } // verify all at once in addition to right after the files are written for (auto i = 0u; i < verificationPairs.size(); ++i) { const auto &v = verificationPairs[i]; @@ -111,7 +114,7 @@ static ox::Error copy(ox::PassThroughFS *src, ox::FileSystem32 *dest, ox::String } -ox::Error pack(ox::PassThroughFS *src, ox::FileSystem32 *dest) noexcept { +ox::Error pack(ox::FileSystem *src, ox::FileSystem *dest) noexcept { oxReturnError(copy(src, dest, "/")); oxReturnError(transformClaw(dest, "/")); return OxError(0); diff --git a/src/nostalgia/tools/pack/pack.hpp b/src/nostalgia/tools/pack/pack.hpp index cbc9ee95..1845fe25 100644 --- a/src/nostalgia/tools/pack/pack.hpp +++ b/src/nostalgia/tools/pack/pack.hpp @@ -10,6 +10,6 @@ namespace nostalgia { -ox::Error pack(ox::PassThroughFS *src, ox::FileSystem32 *dest) noexcept; +ox::Error pack(ox::FileSystem *src, ox::FileSystem *dest) noexcept; }