osb/source/utility/btree_repacker.cpp
Kai Blaschke 431a9c00a5
Fixed a huge amount of Clang warnings
On Linux and macOS, using Clang to compile OpenStarbound produces about 400 MB worth of warnings during the build, making the compiler output unreadable and slowing the build down considerably.

99% of the warnings were unqualified uses of std::move and std::forward, which are now all properly qualified.

Fixed a few other minor warnings about non-virtual destructors and some uses of std::move preventing copy elision on temporary objects.

Most remaining warnings are now unused parameters.
2024-02-19 16:55:19 +01:00

59 lines
1.8 KiB
C++

#include "StarBTreeDatabase.hpp"
#include "StarTime.hpp"
#include "StarFile.hpp"
#include "StarVersionOptionParser.hpp"
using namespace Star;
int main(int argc, char** argv) {
try {
double startTime = Time::monotonicTime();
VersionOptionParser optParse;
optParse.setSummary("Repacks a Starbound BTree file to shrink its file size");
optParse.addArgument("input file path", OptionParser::Required, "Path to the BTree to be repacked");
optParse.addArgument("output filename", OptionParser::Optional, "Output BTree file");
auto opts = optParse.commandParseOrDie(argc, argv);
String bTreePath = opts.arguments.at(0);
String outputFilename = opts.arguments.get(1, bTreePath + ".repack");
outputFilename = File::relativeTo(File::fullPath(File::dirName(outputFilename)), File::baseName(outputFilename));
//open the old db
BTreeDatabase db;
db.setIODevice(File::open(bTreePath, IOMode::Read));
db.open();
//make a new db
BTreeDatabase newDb;
newDb.setBlockSize(db.blockSize());
newDb.setContentIdentifier(db.contentIdentifier());
newDb.setKeySize(db.keySize());
newDb.setAutoCommit(false);
newDb.setIODevice(File::open(outputFilename, IOMode::ReadWrite | IOMode::Truncate));
newDb.open();
coutf("Repacking {}...\n", bTreePath);
//copy the data over
unsigned count = 0;
db.forAll([&count, &newDb](ByteArray key, ByteArray data) {
newDb.insert(key, data);
++count;
});
//close the old db
db.close();
//commit and close the new db
newDb.commit();
newDb.close();
coutf("Repacked BTree to {} in {}s\n", outputFilename, Time::monotonicTime() - startTime);
return 0;
} catch (std::exception const& e) {
cerrf("Exception caught: {}\n", outputException(e, true));
return 1;
}
}