Nix 2.26.3
Nix, the purely functional package manager; unstable internal interfaces
 
Loading...
Searching...
No Matches
nix_api_store.hh
Go to the documentation of this file.
1#pragma once
4
5#include "file-system.hh"
6#include <filesystem>
7
8#include "nix_api_store.h"
9#include "nix_api_store_internal.h"
10
11#include <filesystem>
12#include <gtest/gtest.h>
13
14namespace fs { using namespace std::filesystem; }
15
16namespace nixC {
17class nix_api_store_test : public nix_api_util_context
18{
19public:
20 nix_api_store_test()
21 {
22 nix_libstore_init(ctx);
23 init_local_store();
24 };
25
26 ~nix_api_store_test() override
27 {
28 nix_store_free(store);
29
30 for (auto & path : fs::recursive_directory_iterator(nixDir)) {
31 fs::permissions(path, fs::perms::owner_all);
32 }
33 fs::remove_all(nixDir);
34 }
35
36 Store * store;
37 std::string nixDir;
38 std::string nixStoreDir;
39
40protected:
41 void init_local_store()
42 {
43#ifdef _WIN32
44 // no `mkdtemp` with MinGW
45 auto tmpl = nix::defaultTempDir() + "/tests_nix-store.";
46 for (size_t i = 0; true; ++i) {
47 nixDir = tmpl + std::string { i };
48 if (fs::create_directory(nixDir)) break;
49 }
50#else
51 // resolve any symlinks in i.e. on macOS /tmp -> /private/tmp
52 // because this is not allowed for a nix store.
53 auto tmpl = nix::absPath(std::filesystem::path(nix::defaultTempDir()) / "tests_nix-store.XXXXXX", true);
54 nixDir = mkdtemp((char *) tmpl.c_str());
55#endif
56
57 nixStoreDir = nixDir + "/my_nix_store";
58
59 // Options documented in `nix help-stores`
60 const char * p1[] = {"store", nixStoreDir.c_str()};
61 const char * p2[] = {"state", (new std::string(nixDir + "/my_state"))->c_str()};
62 const char * p3[] = {"log", (new std::string(nixDir + "/my_log"))->c_str()};
63
64 const char ** params[] = {p1, p2, p3, nullptr};
65
66 store = nix_store_open(ctx, "local", params);
67 if (!store) {
68 std::string errMsg = nix_err_msg(nullptr, ctx, nullptr);
69 ASSERT_NE(store, nullptr) << "Could not open store: " << errMsg;
70 };
71 }
72};
73}
auto i
Definition lexer.l:2745
std::string path
Definition lexer.l:1399