Skip to content

Commit b5c8865

Browse files
committed
Slightly more std::filesystem for nix eval
Progress on #9205
1 parent 26c3fc1 commit b5c8865

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

src/nix/eval.cc

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111

1212
using namespace nix;
1313

14+
namespace nix::fs { using namespace std::filesystem; }
15+
1416
struct CmdEval : MixJSON, InstallableValueCommand, MixReadOnlyOption
1517
{
1618
bool raw = false;
1719
std::optional<std::string> apply;
18-
std::optional<Path> writeTo;
20+
std::optional<fs::path> writeTo;
1921

2022
CmdEval() : InstallableValueCommand()
2123
{
@@ -75,20 +77,20 @@ struct CmdEval : MixJSON, InstallableValueCommand, MixReadOnlyOption
7577
if (writeTo) {
7678
stopProgressBar();
7779

78-
if (pathExists(*writeTo))
79-
throw Error("path '%s' already exists", *writeTo);
80+
if (fs::symlink_exists(*writeTo))
81+
throw Error("path '%s' already exists", writeTo->string());
8082

81-
std::function<void(Value & v, const PosIdx pos, const std::filesystem::path & path)> recurse;
83+
std::function<void(Value & v, const PosIdx pos, const fs::path & path)> recurse;
8284

83-
recurse = [&](Value & v, const PosIdx pos, const std::filesystem::path & path)
85+
recurse = [&](Value & v, const PosIdx pos, const fs::path & path)
8486
{
8587
state->forceValue(v, pos);
8688
if (v.type() == nString)
8789
// FIXME: disallow strings with contexts?
8890
writeFile(path.string(), v.string_view());
8991
else if (v.type() == nAttrs) {
90-
// TODO abstract mkdir perms for Windows
91-
createDir(path.string(), 0777);
92+
// Directory should not already exist
93+
assert(fs::create_directory(path.string()));
9294
for (auto & attr : *v.attrs()) {
9395
std::string_view name = state->symbols[attr.name];
9496
try {

0 commit comments

Comments
 (0)