Implemented writeRegistry

This commit is contained in:
Nick Van den Broeck 2019-02-25 13:46:37 +01:00
parent 9ff1a9ea65
commit 6542de98c2
2 changed files with 14 additions and 0 deletions

View file

@ -31,6 +31,18 @@ static std::unique_ptr<FlakeRegistry> readRegistry(const Path & path)
return registry; return registry;
} }
/* Write the registry or lock file to a file. */
static void writeRegistry(FlakeRegistry registry, Path path = "./flake.lock")
{
nlohmann::json json = {};
json["value"] = 0; // Not sure whether this should be 0.
json["flakes"] = {};
for (auto elem : registry.entries) {
json["flakes"][elem.first] = elem.second.ref.to_string();
}
writeFile(path, json.dump(4)); // The '4' is the number of spaces used in the indentation in the json file.
}
const FlakeRegistry & EvalState::getFlakeRegistry() const FlakeRegistry & EvalState::getFlakeRegistry()
{ {
std::call_once(_flakeRegistryInit, [&]() std::call_once(_flakeRegistryInit, [&]()

View file

@ -35,4 +35,6 @@ struct Flake
}; };
Flake getFlake(EvalState & state, const FlakeRef & flakeRef); Flake getFlake(EvalState & state, const FlakeRef & flakeRef);
void writeRegistry(FlakeRegistry);
} }