Skip to content

Commit 7bff820

Browse files
C API: wait on async path writer when parsing store path
1 parent 7319060 commit 7bff820

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

src/libstore-c/nix_api_store.cc

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,26 @@ Store * nix_store_open(nix_c_context * context, const char * uri, const char ***
4444
try {
4545
std::string uri_str = uri ? uri : "";
4646

47-
if (uri_str.empty())
48-
return new Store{nix::openStore()};
47+
if (uri_str.empty()) {
48+
auto store = nix::openStore();
49+
auto asyncPathWriter = nix::AsyncPathWriter::make(store);
50+
return new Store{asyncPathWriter, store};
51+
}
4952

50-
if (!params)
51-
return new Store{nix::openStore(uri_str)};
53+
if (!params) {
54+
auto store = nix::openStore(uri_str);
55+
auto asyncPathWriter = nix::AsyncPathWriter::make(store);
56+
return new Store{asyncPathWriter, store};
57+
}
5258

5359
nix::Store::Config::Params params_map;
5460
for (size_t i = 0; params[i] != nullptr; i++) {
5561
params_map[params[i][0]] = params[i][1];
5662
}
57-
return new Store{nix::openStore(uri_str, params_map)};
63+
64+
auto store = nix::openStore(uri_str, params_map);
65+
auto asyncPathWriter = nix::AsyncPathWriter::make(store);
66+
return new Store{asyncPathWriter, store};
5867
}
5968
NIXC_CATCH_ERRS_NULL
6069
}
@@ -127,6 +136,7 @@ StorePath * nix_store_parse_path(nix_c_context * context, Store * store, const c
127136
context->last_err_code = NIX_OK;
128137
try {
129138
nix::StorePath s = store->ptr->parseStorePath(path);
139+
store->asyncPathWriter->waitForPath(s);
130140
return new StorePath{std::move(s)};
131141
}
132142
NIXC_CATCH_ERRS_NULL

src/libstore-c/nix_api_store_internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
#ifndef NIX_API_STORE_INTERNAL_H
22
#define NIX_API_STORE_INTERNAL_H
3+
#include "nix/store/async-path-writer.hh"
34
#include "nix/store/store-api.hh"
45
#include "nix/store/derivations.hh"
56

67
extern "C" {
78

89
struct Store
910
{
11+
nix::ref<nix::AsyncPathWriter> asyncPathWriter;
1012
nix::ref<nix::Store> ptr;
1113
};
1214

0 commit comments

Comments
 (0)