2017-07-07 13:23:29 +00:00
|
|
|
|
#include <nix/config.h>
|
|
|
|
|
|
|
|
|
|
#include <regex>
|
|
|
|
|
|
|
|
|
|
#include "shared.hh"
|
2022-11-12 14:15:50 +00:00
|
|
|
|
#include "sqlite.hh"
|
2017-07-07 13:23:29 +00:00
|
|
|
|
#include "s3-binary-cache-store.hh"
|
|
|
|
|
#include "thread-pool.hh"
|
|
|
|
|
#include "nar-info.hh"
|
|
|
|
|
|
2022-11-12 14:15:50 +00:00
|
|
|
|
#include <nlohmann/json.hpp>
|
2017-07-07 13:23:29 +00:00
|
|
|
|
|
|
|
|
|
// cache.nixos.org/debuginfo/<build-id>
|
|
|
|
|
// => redirect to NAR
|
|
|
|
|
|
|
|
|
|
using namespace nix;
|
|
|
|
|
|
|
|
|
|
void mainWrapped(int argc, char * * argv)
|
|
|
|
|
{
|
|
|
|
|
initNix();
|
|
|
|
|
|
2022-11-12 14:15:50 +00:00
|
|
|
|
if (argc != 3) throw Error("usage: index-debuginfo DEBUG-DB BINARY-CACHE-URI");
|
2017-07-07 13:23:29 +00:00
|
|
|
|
|
2022-11-12 14:15:50 +00:00
|
|
|
|
Path debugDbPath = argv[1];
|
2017-07-07 13:23:29 +00:00
|
|
|
|
std::string binaryCacheUri = argv[2];
|
|
|
|
|
|
|
|
|
|
if (hasSuffix(binaryCacheUri, "/")) binaryCacheUri.pop_back();
|
|
|
|
|
auto binaryCache = openStore(binaryCacheUri).cast<S3BinaryCacheStore>();
|
|
|
|
|
|
|
|
|
|
ThreadPool threadPool(25);
|
|
|
|
|
|
2022-11-12 14:15:50 +00:00
|
|
|
|
auto doFile = [&](std::string build_id, std::string url, std::string filename) {
|
2017-07-07 13:23:29 +00:00
|
|
|
|
checkInterrupt();
|
|
|
|
|
|
|
|
|
|
nlohmann::json json;
|
2022-11-12 14:15:50 +00:00
|
|
|
|
json["archive"] = url;
|
|
|
|
|
json["member"] = filename;
|
2017-07-07 13:23:29 +00:00
|
|
|
|
|
2023-01-26 13:33:36 +00:00
|
|
|
|
std::string key = "debuginfo/" + build_id;
|
2023-01-26 07:11:34 +00:00
|
|
|
|
|
2017-07-07 13:23:29 +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;
|
2017-07-07 13:23:29 +00:00
|
|
|
|
|
2023-01-26 07:11:34 +00:00
|
|
|
|
printError("redirecting ‘%s’ to ‘%s’", key, filename);
|
2017-07-07 13:23:29 +00:00
|
|
|
|
|
2023-01-26 07:11:34 +00:00
|
|
|
|
binaryCache->upsertFile(key, json.dump(), "application/json");
|
2017-07-07 13:23:29 +00:00
|
|
|
|
};
|
|
|
|
|
|
2022-11-12 14:15:50 +00:00
|
|
|
|
auto db = SQLite(debugDbPath);
|
2017-07-07 13:23:29 +00:00
|
|
|
|
|
2022-11-12 14:15:50 +00:00
|
|
|
|
auto stmt = SQLiteStmt(db, "select build_id, url, filename from DebugInfo;");
|
|
|
|
|
auto query = stmt.use();
|
2017-07-07 13:23:29 +00:00
|
|
|
|
|
2022-11-12 14:15:50 +00:00
|
|
|
|
while (query.next()) {
|
|
|
|
|
threadPool.enqueue(std::bind(doFile, query.getStr(0), query.getStr(1), query.getStr(2)));
|
|
|
|
|
}
|
2017-07-07 13:23:29 +00:00
|
|
|
|
|
|
|
|
|
threadPool.process();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main(int argc, char * * argv)
|
|
|
|
|
{
|
|
|
|
|
return handleExceptions(argv[0], [&]() {
|
|
|
|
|
mainWrapped(argc, argv);
|
|
|
|
|
});
|
|
|
|
|
}
|