mirror of
https://github.com/NixOS/nix.git
synced 2024-11-22 06:42:28 +00:00
Fix build errors on Windows
This commit is contained in:
parent
67a54d47c5
commit
84ea12ad7f
@ -86,7 +86,7 @@ fs::path ExecutablePath::findPath(const fs::path & exe, std::function<bool(const
|
||||
if (resOpt)
|
||||
return *resOpt;
|
||||
else
|
||||
throw ExecutableLookupError("Could not find executable '%s'", exe.native());
|
||||
throw ExecutableLookupError("Could not find executable '%s'", exe.string());
|
||||
} else {
|
||||
return exe;
|
||||
}
|
||||
|
@ -23,9 +23,9 @@ bool dryRun = false;
|
||||
|
||||
void removeOldGenerations(std::filesystem::path dir)
|
||||
{
|
||||
if (access(dir.c_str(), R_OK) != 0) return;
|
||||
if (access(dir.string().c_str(), R_OK) != 0) return;
|
||||
|
||||
bool canWrite = access(dir.c_str(), W_OK) == 0;
|
||||
bool canWrite = access(dir.string().c_str(), W_OK) == 0;
|
||||
|
||||
for (auto & i : std::filesystem::directory_iterator{dir}) {
|
||||
checkInterrupt();
|
||||
|
@ -87,12 +87,8 @@ struct CmdEval : MixJSON, InstallableValueCommand, MixReadOnlyOption
|
||||
// FIXME: disallow strings with contexts?
|
||||
writeFile(path.string(), v.string_view());
|
||||
else if (v.type() == nAttrs) {
|
||||
if (mkdir(path.c_str()
|
||||
#ifndef _WIN32 // TODO abstract mkdir perms for Windows
|
||||
, 0777
|
||||
#endif
|
||||
) == -1)
|
||||
throw SysError("creating directory '%s'", path);
|
||||
// TODO abstract mkdir perms for Windows
|
||||
createDir(path.string(), 0777);
|
||||
for (auto & attr : *v.attrs()) {
|
||||
std::string_view name = state->symbols[attr.name];
|
||||
try {
|
||||
|
@ -25,6 +25,8 @@
|
||||
|
||||
#include "strings-inline.hh"
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
using namespace nix;
|
||||
using namespace nix::flake;
|
||||
using json = nlohmann::json;
|
||||
@ -897,25 +899,26 @@ struct CmdFlakeInitCommon : virtual Args, EvalCommand
|
||||
"If you've set '%s' to a string, try using a path instead.",
|
||||
templateDir, templateDirAttr->getAttrPathStr()).debugThrow();
|
||||
|
||||
std::vector<std::filesystem::path> changedFiles;
|
||||
std::vector<std::filesystem::path> conflictedFiles;
|
||||
std::vector<fs::path> changedFiles;
|
||||
std::vector<fs::path> conflictedFiles;
|
||||
|
||||
std::function<void(const std::filesystem::path & from, const std::filesystem::path & to)> copyDir;
|
||||
copyDir = [&](const std::filesystem::path & from, const std::filesystem::path & to)
|
||||
std::function<void(const fs::path & from, const fs::path & to)> copyDir;
|
||||
copyDir = [&](const fs::path & from, const fs::path & to)
|
||||
{
|
||||
createDirs(to);
|
||||
fs::create_directories(to);
|
||||
|
||||
for (auto & entry : std::filesystem::directory_iterator{from}) {
|
||||
for (auto & entry : fs::directory_iterator{from}) {
|
||||
checkInterrupt();
|
||||
auto from2 = entry.path();
|
||||
auto to2 = to / entry.path().filename();
|
||||
auto st = entry.symlink_status();
|
||||
if (std::filesystem::is_directory(st))
|
||||
auto to_st = fs::symlink_status(to2);
|
||||
if (fs::is_directory(st))
|
||||
copyDir(from2, to2);
|
||||
else if (std::filesystem::is_regular_file(st)) {
|
||||
auto contents = readFile(from2);
|
||||
if (pathExists(to2)) {
|
||||
auto contents2 = readFile(to2);
|
||||
else if (fs::is_regular_file(st)) {
|
||||
auto contents = readFile(from2.string());
|
||||
if (fs::exists(to_st)) {
|
||||
auto contents2 = readFile(to2.string());
|
||||
if (contents != contents2) {
|
||||
printError("refusing to overwrite existing file '%s'\n please merge it manually with '%s'", to2.string(), from2.string());
|
||||
conflictedFiles.push_back(to2);
|
||||
@ -924,12 +927,12 @@ struct CmdFlakeInitCommon : virtual Args, EvalCommand
|
||||
}
|
||||
continue;
|
||||
} else
|
||||
writeFile(to2, contents);
|
||||
writeFile(to2.string(), contents);
|
||||
}
|
||||
else if (std::filesystem::is_symlink(st)) {
|
||||
auto target = readLink(from2);
|
||||
if (pathExists(to2)) {
|
||||
if (readLink(to2) != target) {
|
||||
else if (fs::is_symlink(st)) {
|
||||
auto target = fs::read_symlink(from2);
|
||||
if (fs::exists(to_st)) {
|
||||
if (fs::read_symlink(to2) != target) {
|
||||
printError("refusing to overwrite existing file '%s'\n please merge it manually with '%s'", to2.string(), from2.string());
|
||||
conflictedFiles.push_back(to2);
|
||||
} else {
|
||||
@ -937,7 +940,7 @@ struct CmdFlakeInitCommon : virtual Args, EvalCommand
|
||||
}
|
||||
continue;
|
||||
} else
|
||||
createSymlink(target, to2);
|
||||
fs::create_symlink(target, to2);
|
||||
}
|
||||
else
|
||||
throw Error("file '%s' has unsupported type", from2);
|
||||
@ -948,9 +951,9 @@ struct CmdFlakeInitCommon : virtual Args, EvalCommand
|
||||
|
||||
copyDir(templateDir, flakeDir);
|
||||
|
||||
if (!changedFiles.empty() && pathExists(flakeDir + "/.git")) {
|
||||
if (!changedFiles.empty() && fs::exists(std::filesystem::path{flakeDir} / ".git")) {
|
||||
Strings args = { "-C", flakeDir, "add", "--intent-to-add", "--force", "--" };
|
||||
for (auto & s : changedFiles) args.push_back(s);
|
||||
for (auto & s : changedFiles) args.emplace_back(s.string());
|
||||
runProgram("git", true, args);
|
||||
}
|
||||
auto welcomeText = cursor->maybeGetAttr("welcomeText");
|
||||
@ -1275,7 +1278,7 @@ struct CmdFlakeShow : FlakeCommand, MixJSON
|
||||
if (auto aDescription = aMeta->maybeGetAttr(state->sDescription))
|
||||
description = aDescription->getString();
|
||||
}
|
||||
|
||||
|
||||
if (json) {
|
||||
j.emplace("type", "derivation");
|
||||
j.emplace("name", name);
|
||||
|
@ -126,8 +126,8 @@ struct ProfileManifest
|
||||
{
|
||||
auto manifestPath = profile / "manifest.json";
|
||||
|
||||
if (pathExists(manifestPath)) {
|
||||
auto json = nlohmann::json::parse(readFile(manifestPath));
|
||||
if (std::filesystem::exists(manifestPath)) {
|
||||
auto json = nlohmann::json::parse(readFile(manifestPath.string()));
|
||||
|
||||
auto version = json.value("version", 0);
|
||||
std::string sUrl;
|
||||
@ -176,7 +176,7 @@ struct ProfileManifest
|
||||
}
|
||||
}
|
||||
|
||||
else if (pathExists(profile / "manifest.nix")) {
|
||||
else if (std::filesystem::exists(profile / "manifest.nix")) {
|
||||
// FIXME: needed because of pure mode; ugly.
|
||||
state.allowPath(state.store->followLinksToStore(profile.string()));
|
||||
state.allowPath(state.store->followLinksToStore((profile / "manifest.nix").string()));
|
||||
|
Loading…
Reference in New Issue
Block a user