|
5 | 5 |
|
6 | 6 | namespace nix { |
7 | 7 |
|
8 | | -Path getCacheDir() |
| 8 | +std::filesystem::path getCacheDir() |
9 | 9 | { |
10 | 10 | auto dir = getEnv("NIX_CACHE_HOME"); |
11 | 11 | if (dir) { |
12 | 12 | return *dir; |
13 | 13 | } else { |
14 | 14 | auto xdgDir = getEnv("XDG_CACHE_HOME"); |
15 | 15 | if (xdgDir) { |
16 | | - return *xdgDir + "/nix"; |
| 16 | + return std::filesystem::path{*xdgDir} / "nix"; |
17 | 17 | } else { |
18 | | - return getHome() + "/.cache/nix"; |
| 18 | + return getHome() / ".cache" / "nix"; |
19 | 19 | } |
20 | 20 | } |
21 | 21 | } |
22 | 22 |
|
23 | | -Path getConfigDir() |
| 23 | +std::filesystem::path getConfigDir() |
24 | 24 | { |
25 | 25 | auto dir = getEnv("NIX_CONFIG_HOME"); |
26 | 26 | if (dir) { |
27 | 27 | return *dir; |
28 | 28 | } else { |
29 | 29 | auto xdgDir = getEnv("XDG_CONFIG_HOME"); |
30 | 30 | if (xdgDir) { |
31 | | - return *xdgDir + "/nix"; |
| 31 | + return std::filesystem::path{*xdgDir} / "nix"; |
32 | 32 | } else { |
33 | | - return getHome() + "/.config/nix"; |
| 33 | + return getHome() / ".config" / "nix"; |
34 | 34 | } |
35 | 35 | } |
36 | 36 | } |
37 | 37 |
|
38 | | -std::vector<Path> getConfigDirs() |
| 38 | +std::vector<std::filesystem::path> getConfigDirs() |
39 | 39 | { |
40 | | - Path configHome = getConfigDir(); |
| 40 | + std::filesystem::path configHome = getConfigDir(); |
41 | 41 | auto configDirs = getEnv("XDG_CONFIG_DIRS").value_or("/etc/xdg"); |
42 | | - std::vector<Path> result = tokenizeString<std::vector<std::string>>(configDirs, ":"); |
43 | | - for (auto & p : result) { |
44 | | - p += "/nix"; |
| 42 | + auto tokens = tokenizeString<std::vector<std::string>>(configDirs, ":"); |
| 43 | + std::vector<std::filesystem::path> result; |
| 44 | + result.push_back(configHome); |
| 45 | + for (auto & token : tokens) { |
| 46 | + result.push_back(std::filesystem::path{token} / "nix"); |
45 | 47 | } |
46 | | - result.insert(result.begin(), configHome); |
47 | 48 | return result; |
48 | 49 | } |
49 | 50 |
|
50 | | -Path getDataDir() |
| 51 | +std::filesystem::path getDataDir() |
51 | 52 | { |
52 | 53 | auto dir = getEnv("NIX_DATA_HOME"); |
53 | 54 | if (dir) { |
54 | 55 | return *dir; |
55 | 56 | } else { |
56 | 57 | auto xdgDir = getEnv("XDG_DATA_HOME"); |
57 | 58 | if (xdgDir) { |
58 | | - return *xdgDir + "/nix"; |
| 59 | + return std::filesystem::path{*xdgDir} / "nix"; |
59 | 60 | } else { |
60 | | - return getHome() + "/.local/share/nix"; |
| 61 | + return getHome() / ".local" / "share" / "nix"; |
61 | 62 | } |
62 | 63 | } |
63 | 64 | } |
64 | 65 |
|
65 | | -Path getStateDir() |
| 66 | +std::filesystem::path getStateDir() |
66 | 67 | { |
67 | 68 | auto dir = getEnv("NIX_STATE_HOME"); |
68 | 69 | if (dir) { |
69 | 70 | return *dir; |
70 | 71 | } else { |
71 | 72 | auto xdgDir = getEnv("XDG_STATE_HOME"); |
72 | 73 | if (xdgDir) { |
73 | | - return *xdgDir + "/nix"; |
| 74 | + return std::filesystem::path{*xdgDir} / "nix"; |
74 | 75 | } else { |
75 | | - return getHome() + "/.local/state/nix"; |
| 76 | + return getHome() / ".local" / "state" / "nix"; |
76 | 77 | } |
77 | 78 | } |
78 | 79 | } |
79 | 80 |
|
80 | | -Path createNixStateDir() |
| 81 | +std::filesystem::path createNixStateDir() |
81 | 82 | { |
82 | | - Path dir = getStateDir(); |
| 83 | + std::filesystem::path dir = getStateDir(); |
83 | 84 | createDirs(dir); |
84 | 85 | return dir; |
85 | 86 | } |
|
0 commit comments