Skip to content

Commit

Permalink
Merge pull request #11650 from obsidiansystems/nix-eval-slight-fs-cle…
Browse files Browse the repository at this point in the history
…anup

Slightly more `std::filesystem` for `nix eval`
  • Loading branch information
roberth authored Oct 9, 2024
2 parents d4b9977 + b5c8865 commit 4db9487
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/nix/eval.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

using namespace nix;

namespace nix::fs { using namespace std::filesystem; }

struct CmdEval : MixJSON, InstallableValueCommand, MixReadOnlyOption
{
bool raw = false;
std::optional<std::string> apply;
std::optional<Path> writeTo;
std::optional<fs::path> writeTo;

CmdEval() : InstallableValueCommand()
{
Expand Down Expand Up @@ -75,20 +77,20 @@ struct CmdEval : MixJSON, InstallableValueCommand, MixReadOnlyOption
if (writeTo) {
stopProgressBar();

if (pathExists(*writeTo))
throw Error("path '%s' already exists", *writeTo);
if (fs::symlink_exists(*writeTo))
throw Error("path '%s' already exists", writeTo->string());

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

recurse = [&](Value & v, const PosIdx pos, const std::filesystem::path & path)
recurse = [&](Value & v, const PosIdx pos, const fs::path & path)
{
state->forceValue(v, pos);
if (v.type() == nString)
// FIXME: disallow strings with contexts?
writeFile(path.string(), v.string_view());
else if (v.type() == nAttrs) {
// TODO abstract mkdir perms for Windows
createDir(path.string(), 0777);
// Directory should not already exist
assert(fs::create_directory(path.string()));
for (auto & attr : *v.attrs()) {
std::string_view name = state->symbols[attr.name];
try {
Expand Down

0 comments on commit 4db9487

Please sign in to comment.