-
-
Notifications
You must be signed in to change notification settings - Fork 29
/
index-debuginfo.cc
72 lines (50 loc) · 1.8 KB
/
index-debuginfo.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#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;
std::string key = "debuginfo/" + build_id;
// FIXME: or should we overwrite? The previous link may point
// to a GC'ed file, so overwriting might be useful...
if (binaryCache->fileExists(key)) return;
printError("redirecting ‘%s’ to ‘%s’", key, filename);
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);
});
}