1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-06 21:41:48 +02:00

C API: update libstore tests

This commit is contained in:
José Luis Lafuente 2024-02-29 18:33:07 +01:00 committed by José Luis Lafuente
parent 31fbb24329
commit 940ff6535c
No known key found for this signature in database
GPG key ID: 8A3455EBE455489A
3 changed files with 29 additions and 24 deletions

View file

@ -24,24 +24,30 @@ public:
{
nix_store_free(store);
for (auto & path : fs::recursive_directory_iterator(nixStoreDir)) {
for (auto & path : fs::recursive_directory_iterator(nixDir)) {
fs::permissions(path, fs::perms::owner_all);
}
fs::remove_all(nixStoreDir);
fs::remove_all(nixDir);
}
Store * store;
std::string nixDir;
std::string nixStoreDir;
protected:
void init_local_store()
{
auto tmpl = nix::getEnv("TMPDIR").value_or("/tmp") + "/tests_nix-store.XXXXXX";
nixStoreDir = mkdtemp((char *) tmpl.c_str());
nixDir = mkdtemp((char *) tmpl.c_str());
nixStoreDir = nixDir + "/my_nix_store";
// Options documented in `nix help-stores`
const char * p1[] = {"root", nixStoreDir.c_str()};
const char ** params[] = {p1, nullptr};
const char * p1[] = {"store", nixStoreDir.c_str()};
const char * p2[] = {"state", (new std::string(nixDir + "/my_state"))->c_str()};
const char * p3[] = {"log", (new std::string(nixDir + "/my_log"))->c_str()};
const char ** params[] = {p1, p2, p3, nullptr};
store = nix_store_open(ctx, "local", params);
}
};