[nostalgia/tools/pack] Remove all std references from Pack lib

This commit is contained in:
Gary Talent 2021-04-17 16:35:35 -05:00
parent 8f7504c1c8
commit fef0ff58c3
2 changed files with 10 additions and 21 deletions

View File

@ -6,8 +6,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/ */
#include <string_view>
#include <ox/claw/read.hpp> #include <ox/claw/read.hpp>
#include "pack.hpp" #include "pack.hpp"
@ -16,27 +14,18 @@ namespace nostalgia {
namespace { namespace {
[[nodiscard]]
static constexpr bool endsWith(std::string_view str, std::string_view ending) noexcept {
return str.size() >= ending.size() && str.substr(str.size() - ending.size()) == ending;
}
static_assert(endsWith("asdf", "df"));
static_assert(!endsWith("asdf", "awefawe"));
static_assert(!endsWith("asdf", "eu"));
/** /**
* Convert path references to inodes to save space * Convert path references to inodes to save space
* @param buff buffer holding file * @param buff buffer holding file
* @return error * @return error
* stub for now * stub for now
*/ */
ox::Error pathToInode(ox::Vector<uint8_t>*) { static ox::Error pathToInode(ox::Vector<uint8_t>*) noexcept {
return OxError(0); return OxError(0);
} }
// just strip header for now... // just strip header for now...
ox::Error toMetalClaw(ox::Vector<uint8_t> *buff) { static ox::Error toMetalClaw(ox::Vector<uint8_t> *buff) noexcept {
auto [mc, err] = ox::stripClawHeader(ox::bit_cast<char*>(buff->data()), buff->size()); auto [mc, err] = ox::stripClawHeader(ox::bit_cast<char*>(buff->data()), buff->size());
oxReturnError(err); oxReturnError(err);
buff->resize(mc.size()); buff->resize(mc.size());
@ -46,10 +35,10 @@ ox::Error toMetalClaw(ox::Vector<uint8_t> *buff) {
// 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, ox::String path) { static ox::Error transformClaw(ox::FileSystem32 *dest, ox::String path) noexcept {
// copy // copy
oxTrace("pack::transformClaw") << "path:" << path.c_str(); oxTrace("pack::transformClaw") << "path:" << path.c_str();
return dest->ls(path.c_str(), [dest, path](const char *name, ox::InodeId_t) { return dest->ls(path.c_str(), [dest, path](const ox::String &name, ox::InodeId_t) {
auto filePath = path + name; auto filePath = path + name;
auto [stat, err] = dest->stat(filePath.c_str()); auto [stat, err] = dest->stat(filePath.c_str());
oxReturnError(err); oxReturnError(err);
@ -58,7 +47,7 @@ ox::Error transformClaw(ox::FileSystem32 *dest, ox::String path) {
oxReturnError(transformClaw(dest, dir)); oxReturnError(transformClaw(dest, dir));
} else { } else {
// do transforms // do transforms
if (endsWith(name, ".ng") || endsWith(name, ".npal")) { if (name.endsWith(".ng") || name.endsWith(".npal")) {
// load file // load file
ox::Vector<uint8_t> buff(stat.size); ox::Vector<uint8_t> buff(stat.size);
oxReturnError(dest->read(filePath.c_str(), buff.data(), buff.size())); oxReturnError(dest->read(filePath.c_str(), buff.data(), buff.size()));
@ -73,7 +62,7 @@ ox::Error transformClaw(ox::FileSystem32 *dest, ox::String path) {
}); });
} }
ox::Error verifyFile(ox::FileSystem32 *fs, const ox::String &path, const ox::Vector<uint8_t> &expected) noexcept { static ox::Error verifyFile(ox::FileSystem32 *fs, const ox::String &path, const ox::Vector<uint8_t> &expected) noexcept {
ox::Vector<uint8_t> buff(expected.size()); ox::Vector<uint8_t> buff(expected.size());
oxReturnError(fs->read(path.c_str(), buff.data(), buff.size())); oxReturnError(fs->read(path.c_str(), buff.data(), buff.size()));
return OxError(buff == expected ? 0 : 1); return OxError(buff == expected ? 0 : 1);
@ -84,11 +73,11 @@ struct VerificationPair {
ox::Vector<uint8_t> buff; ox::Vector<uint8_t> buff;
}; };
ox::Error copy(ox::PassThroughFS *src, ox::FileSystem32 *dest, ox::String path) { static ox::Error copy(ox::PassThroughFS *src, ox::FileSystem32 *dest, ox::String path) noexcept {
oxOutf("copying directory: {}\n", path); oxOutf("copying directory: {}\n", path);
ox::Vector<VerificationPair> verificationPairs; ox::Vector<VerificationPair> verificationPairs;
// copy // copy
oxReturnError(src->ls(path.c_str(), [&verificationPairs, src, dest, path](const char *name, ox::InodeId_t) { oxReturnError(src->ls(path.c_str(), [&verificationPairs, src, dest, path](const char *name, ox::InodeId_t) noexcept {
auto currentFile = path + name; auto currentFile = path + name;
if (currentFile == "/.nostalgia") { if (currentFile == "/.nostalgia") {
return OxError(0); return OxError(0);
@ -122,7 +111,7 @@ ox::Error copy(ox::PassThroughFS *src, ox::FileSystem32 *dest, ox::String path)
} }
ox::Error pack(ox::PassThroughFS *src, ox::FileSystem32 *dest) { ox::Error pack(ox::PassThroughFS *src, ox::FileSystem32 *dest) noexcept {
oxReturnError(copy(src, dest, "/")); oxReturnError(copy(src, dest, "/"));
oxReturnError(transformClaw(dest, "/")); oxReturnError(transformClaw(dest, "/"));
return OxError(0); return OxError(0);

View File

@ -10,6 +10,6 @@
namespace nostalgia { namespace nostalgia {
ox::Error pack(ox::PassThroughFS *src, ox::FileSystem32 *dest); ox::Error pack(ox::PassThroughFS *src, ox::FileSystem32 *dest) noexcept;
} }