channel-scripts/index-debuginfo.cc

73 lines
1.8 KiB
C++
Raw Normal View History

#include <nix/config.h>
#include <regex>
#include "shared.hh"
#include "sqlite.hh"
#include "s3-binary-cache-store.hh"
#include "thread-pool.hh"
#include "nar-info.hh"
// https://github.com/NixOS/nix/commit/ac89bb064aeea85a62b82a6daf0ecca7190a28b7
#ifdef HAS_SIGNALS_HH
#include "signals.hh"
#endif
#include <nlohmann/json.hpp>
// cache.nixos.org/debuginfo/<build-id>
// => redirect to NAR
using namespace nix;
void mainWrapped(int argc, char * * argv)
{
initNix();
if (argc != 3) throw Error("usage: index-debuginfo DEBUG-DB BINARY-CACHE-URI");
Path debugDbPath = argv[1];
std::string binaryCacheUri = argv[2];
if (hasSuffix(binaryCacheUri, "/")) binaryCacheUri.pop_back();
auto binaryCache = openStore(binaryCacheUri).cast<S3BinaryCacheStore>();
ThreadPool threadPool(25);
auto doFile = [&](std::string build_id, std::string url, std::string filename) {
checkInterrupt();
nlohmann::json json;
json["archive"] = url;
json["member"] = filename;
2023-01-26 13:33:36 +00:00
std::string key = "debuginfo/" + build_id;
2023-01-26 07:11:34 +00:00
// FIXME: or should we overwrite? The previous link may point
// to a GC'ed file, so overwriting might be useful...
2023-01-26 07:11:34 +00:00
if (binaryCache->fileExists(key)) return;
2023-01-26 07:11:34 +00:00
printError("redirecting %s to %s", key, filename);
2023-01-26 07:11:34 +00:00
binaryCache->upsertFile(key, json.dump(), "application/json");
};
auto db = SQLite(debugDbPath);
auto stmt = SQLiteStmt(db, "select build_id, url, filename from DebugInfo;");
auto query = stmt.use();
while (query.next()) {
threadPool.enqueue(std::bind(doFile, query.getStr(0), query.getStr(1), query.getStr(2)));
}
threadPool.process();
}
int main(int argc, char * * argv)
{
return handleExceptions(argv[0], [&]() {
mainWrapped(argc, argv);
});
}