1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-12-09 10:31:02 +01:00

Fix mingw build

This commit is contained in:
Eelco Dolstra 2025-12-03 19:46:56 +01:00
parent 96d8b54e42
commit c338f9cc5d
16 changed files with 31 additions and 29 deletions

View file

@ -142,7 +142,7 @@ NixRepl::NixRepl(
, getValues(getValues) , getValues(getValues)
, staticEnv(new StaticEnv(nullptr, state->staticBaseEnv)) , staticEnv(new StaticEnv(nullptr, state->staticBaseEnv))
, runNixPtr{runNix} , runNixPtr{runNix}
, interacter(make_unique<ReadlineLikeInteracter>(getDataDir() + "/repl-history")) , interacter(make_unique<ReadlineLikeInteracter>((getDataDir() / "repl-history").string()))
{ {
} }

View file

@ -38,7 +38,7 @@ struct CacheImpl : Cache
{ {
auto state(_state.lock()); auto state(_state.lock());
auto dbPath = getCacheDir() + "/fetcher-cache-v4.sqlite"; auto dbPath = (getCacheDir() / "fetcher-cache-v4.sqlite").string();
createDirs(dirOf(dbPath)); createDirs(dirOf(dbPath));
state->db = SQLite(dbPath); state->db = SQLite(dbPath);

View file

@ -212,7 +212,7 @@ static void initRepoAtomically(std::filesystem::path & path, bool bare)
AutoDelete delTmpDir(tmpDir, true); AutoDelete delTmpDir(tmpDir, true);
Repository tmpRepo; Repository tmpRepo;
if (git_repository_init(Setter(tmpRepo), tmpDir.c_str(), bare)) if (git_repository_init(Setter(tmpRepo), tmpDir.string().c_str(), bare))
throw Error("creating Git repository %s: %s", path, git_error_last()->message); throw Error("creating Git repository %s: %s", path, git_error_last()->message);
try { try {
std::filesystem::rename(tmpDir, path); std::filesystem::rename(tmpDir, path);

View file

@ -61,7 +61,7 @@ std::optional<std::string> readHead(const std::filesystem::path & path)
RunOptions{ RunOptions{
.program = "git", .program = "git",
// FIXME: use 'HEAD' to avoid returning all refs // FIXME: use 'HEAD' to avoid returning all refs
.args = {"ls-remote", "--symref", path}, .args = {"ls-remote", "--symref", path.string()},
.isInteractive = true, .isInteractive = true,
}); });
if (status != 0) if (status != 0)
@ -88,7 +88,7 @@ bool storeCachedHead(const std::string & actualUrl, bool shallow, const std::str
{ {
std::filesystem::path cacheDir = getCachePath(actualUrl, shallow); std::filesystem::path cacheDir = getCachePath(actualUrl, shallow);
try { try {
runProgram("git", true, {"-C", cacheDir, "--git-dir", ".", "symbolic-ref", "--", "HEAD", headRef}); runProgram("git", true, {"-C", cacheDir.string(), "--git-dir", ".", "symbolic-ref", "--", "HEAD", headRef});
} catch (ExecError & e) { } catch (ExecError & e) {
if ( if (
#ifndef WIN32 // TODO abstract over exit status handling on Windows #ifndef WIN32 // TODO abstract over exit status handling on Windows
@ -115,7 +115,7 @@ std::optional<std::string> readHeadCached(const std::string & actualUrl, bool sh
time_t now = time(0); time_t now = time(0);
struct stat st; struct stat st;
std::optional<std::string> cachedRef; std::optional<std::string> cachedRef;
if (stat(headRefFile.c_str(), &st) == 0) { if (stat(headRefFile.string().c_str(), &st) == 0) {
cachedRef = readHead(cacheDir); cachedRef = readHead(cacheDir);
if (cachedRef != std::nullopt && *cachedRef != gitInitialBranch && isCacheFileWithinTtl(now, st)) { if (cachedRef != std::nullopt && *cachedRef != gitInitialBranch && isCacheFileWithinTtl(now, st)) {
debug("using cached HEAD ref '%s' for repo '%s'", *cachedRef, actualUrl); debug("using cached HEAD ref '%s' for repo '%s'", *cachedRef, actualUrl);
@ -450,7 +450,7 @@ struct GitInputScheme : InputScheme
if (input.getRev()) if (input.getRev())
throw UnimplementedError("cloning a specific revision is not implemented"); throw UnimplementedError("cloning a specific revision is not implemented");
args.push_back(destDir); args.push_back(destDir.string());
runProgram("git", true, args, {}, true); runProgram("git", true, args, {}, true);
} }

View file

@ -281,27 +281,28 @@ struct MercurialInputScheme : InputScheme
/* If this is a commit hash that we already have, we don't /* If this is a commit hash that we already have, we don't
have to pull again. */ have to pull again. */
if (!(input.getRev() && pathExists(cacheDir) if (!(input.getRev() && pathExists(cacheDir)
&& runProgram(hgOptions({"log", "-R", cacheDir, "-r", input.getRev()->gitRev(), "--template", "1"})) && runProgram(
hgOptions({"log", "-R", cacheDir.string(), "-r", input.getRev()->gitRev(), "--template", "1"}))
.second .second
== "1")) { == "1")) {
Activity act(*logger, lvlTalkative, actUnknown, fmt("fetching Mercurial repository '%s'", actualUrl)); Activity act(*logger, lvlTalkative, actUnknown, fmt("fetching Mercurial repository '%s'", actualUrl));
if (pathExists(cacheDir)) { if (pathExists(cacheDir)) {
try { try {
runHg({"pull", "-R", cacheDir, "--", actualUrl}); runHg({"pull", "-R", cacheDir.string(), "--", actualUrl});
} catch (ExecError & e) { } catch (ExecError & e) {
auto transJournal = cacheDir / ".hg" / "store" / "journal"; auto transJournal = cacheDir / ".hg" / "store" / "journal";
/* hg throws "abandoned transaction" error only if this file exists */ /* hg throws "abandoned transaction" error only if this file exists */
if (pathExists(transJournal)) { if (pathExists(transJournal)) {
runHg({"recover", "-R", cacheDir}); runHg({"recover", "-R", cacheDir.string()});
runHg({"pull", "-R", cacheDir, "--", actualUrl}); runHg({"pull", "-R", cacheDir.string(), "--", actualUrl});
} else { } else {
throw ExecError(e.status, "'hg pull' %s", statusToString(e.status)); throw ExecError(e.status, "'hg pull' %s", statusToString(e.status));
} }
} }
} else { } else {
createDirs(dirOf(cacheDir.string())); createDirs(dirOf(cacheDir.string()));
runHg({"clone", "--noupdate", "--", actualUrl, cacheDir}); runHg({"clone", "--noupdate", "--", actualUrl, cacheDir.string()});
} }
} }
@ -309,7 +310,7 @@ struct MercurialInputScheme : InputScheme
auto tokens = tokenizeString<std::vector<std::string>>(runHg( auto tokens = tokenizeString<std::vector<std::string>>(runHg(
{"log", {"log",
"-R", "-R",
cacheDir, cacheDir.string(),
"-r", "-r",
input.getRev() ? input.getRev()->gitRev() : *input.getRef(), input.getRev() ? input.getRev()->gitRev() : *input.getRef(),
"--template", "--template",
@ -329,7 +330,7 @@ struct MercurialInputScheme : InputScheme
std::filesystem::path tmpDir = createTempDir(); std::filesystem::path tmpDir = createTempDir();
AutoDelete delTmpDir(tmpDir, true); AutoDelete delTmpDir(tmpDir, true);
runHg({"archive", "-R", cacheDir, "-r", rev.gitRev(), tmpDir}); runHg({"archive", "-R", cacheDir.string(), "-r", rev.gitRev(), tmpDir.string()});
deletePath(tmpDir / ".hg_archival.txt"); deletePath(tmpDir / ".hg_archival.txt");

View file

@ -150,7 +150,7 @@ static std::shared_ptr<Registry> getGlobalRegistry(const Settings & settings, St
if (!isAbsolute(path)) { if (!isAbsolute(path)) {
auto storePath = downloadFile(store, settings, path, "flake-registry.json").storePath; auto storePath = downloadFile(store, settings, path, "flake-registry.json").storePath;
if (auto store2 = dynamic_cast<LocalFSStore *>(&store)) if (auto store2 = dynamic_cast<LocalFSStore *>(&store))
store2->addPermRoot(storePath, getCacheDir() + "/flake-registry.json"); store2->addPermRoot(storePath, (getCacheDir() / "flake-registry.json").string());
return {store.requireStoreObjectAccessor(storePath)}; return {store.requireStoreObjectAccessor(storePath)};
} else { } else {
return SourcePath{getFSSourceAccessor(), CanonPath{path}}.resolveSymlinks(); return SourcePath{getFSSourceAccessor(), CanonPath{path}}.resolveSymlinks();

View file

@ -304,7 +304,7 @@ void printVersion(const std::string & programName)
std::cout << "System type: " << settings.thisSystem << "\n"; std::cout << "System type: " << settings.thisSystem << "\n";
std::cout << "Additional system types: " << concatStringsSep(", ", settings.extraPlatforms.get()) << "\n"; std::cout << "Additional system types: " << concatStringsSep(", ", settings.extraPlatforms.get()) << "\n";
std::cout << "Features: " << concatStringsSep(", ", cfg) << "\n"; std::cout << "Features: " << concatStringsSep(", ", cfg) << "\n";
std::cout << "System configuration file: " << settings.nixConfDir + "/nix.conf" << "\n"; std::cout << "System configuration file: " << (settings.nixConfDir / "nix.conf") << "\n";
std::cout << "User configuration files: " << concatStringsSep(":", settings.nixUserConfFiles) << "\n"; std::cout << "User configuration files: " << concatStringsSep(":", settings.nixUserConfFiles) << "\n";
std::cout << "Store directory: " << settings.nixStore << "\n"; std::cout << "Store directory: " << settings.nixStore << "\n";
std::cout << "State directory: " << settings.nixStateDir << "\n"; std::cout << "State directory: " << settings.nixStateDir << "\n";

View file

@ -116,7 +116,7 @@ void loadConfFile(AbstractConfig & config)
} }
}; };
applyConfigFile(settings.nixConfDir + "/nix.conf"); applyConfigFile((settings.nixConfDir / "nix.conf").string());
/* We only want to send overrides to the daemon, i.e. stuff from /* We only want to send overrides to the daemon, i.e. stuff from
~/.nix/nix.conf or the command line. */ ~/.nix/nix.conf or the command line. */
@ -145,7 +145,7 @@ std::vector<Path> getUserConfigFiles()
std::vector<Path> files; std::vector<Path> files;
auto dirs = getConfigDirs(); auto dirs = getConfigDirs();
for (auto & dir : dirs) { for (auto & dir : dirs) {
files.insert(files.end(), dir + "/nix.conf"); files.insert(files.end(), (dir / "nix.conf").string());
} }
return files; return files;
} }

View file

@ -86,7 +86,7 @@ public:
Sync<State> _state; Sync<State> _state;
NarInfoDiskCacheImpl(Path dbPath = getCacheDir() + "/binary-cache-v7.sqlite") NarInfoDiskCacheImpl(Path dbPath = (getCacheDir() / "binary-cache-v7.sqlite").string())
{ {
auto state(_state.lock()); auto state(_state.lock());

View file

@ -687,7 +687,7 @@ std::filesystem::path createTempDir(const std::filesystem::path & tmpRoot, const
checkInterrupt(); checkInterrupt();
std::filesystem::path tmpDir = makeTempPath(tmpRoot, prefix); std::filesystem::path tmpDir = makeTempPath(tmpRoot, prefix);
if (mkdir( if (mkdir(
tmpDir.c_str() tmpDir.string().c_str()
#ifndef _WIN32 // TODO abstract mkdir perms for Windows #ifndef _WIN32 // TODO abstract mkdir perms for Windows
, ,
mode mode
@ -734,7 +734,7 @@ AutoCloseFD createAnonymousTempFile()
std::pair<AutoCloseFD, Path> createTempFile(const Path & prefix) std::pair<AutoCloseFD, Path> createTempFile(const Path & prefix)
{ {
Path tmpl(defaultTempDir() + "/" + prefix + ".XXXXXX"); Path tmpl(defaultTempDir().string() + "/" + prefix + ".XXXXXX");
// Strictly speaking, this is UB, but who cares... // Strictly speaking, this is UB, but who cares...
// FIXME: use O_TMPFILE. // FIXME: use O_TMPFILE.
// FIXME: Windows should use FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE // FIXME: Windows should use FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE

View file

@ -207,7 +207,8 @@ void FdSource::restart()
throw Error("can't seek to the start of a file"); throw Error("can't seek to the start of a file");
buffer.reset(); buffer.reset();
read = bufPosOut = bufPosOut = 0; read = bufPosOut = bufPosOut = 0;
if (lseek(fd, 0, SEEK_SET) == -1) int fd_ = fromDescriptorReadOnly(fd);
if (lseek(fd_, 0, SEEK_SET) == -1)
throw SysError("seeking to the start of a file"); throw SysError("seeking to the start of a file");
} }

View file

@ -90,7 +90,7 @@ std::string expandTilde(std::string_view path)
// TODO: expand ~user ? // TODO: expand ~user ?
auto tilde = path.substr(0, 2); auto tilde = path.substr(0, 2);
if (tilde == "~/" || tilde == "~") if (tilde == "~/" || tilde == "~")
return getHome() + std::string(path.substr(1)); return getHome().string() + std::string(path.substr(1));
else else
return std::string(path); return std::string(path);
} }

View file

@ -40,7 +40,7 @@ std::filesystem::path getHome()
static std::filesystem::path homeDir = []() { static std::filesystem::path homeDir = []() {
std::filesystem::path homeDir = getEnv("USERPROFILE").value_or("C:\\Users\\Default"); std::filesystem::path homeDir = getEnv("USERPROFILE").value_or("C:\\Users\\Default");
assert(!homeDir.empty()); assert(!homeDir.empty());
return canonPath(homeDir); return canonPath(homeDir.string());
}(); }();
return homeDir; return homeDir;
} }

View file

@ -1292,7 +1292,7 @@ static void opSwitchProfile(Globals & globals, Strings opFlags, Strings opArgs)
throw UsageError("exactly one argument expected"); throw UsageError("exactly one argument expected");
Path profile = absPath(opArgs.front()); Path profile = absPath(opArgs.front());
Path profileLink = settings.useXDGBaseDirectories ? createNixStateDir() + "/profile" : getHome() + "/.nix-profile"; auto profileLink = settings.useXDGBaseDirectories ? createNixStateDir() / "profile" : getHome() / ".nix-profile";
switchLink(profileLink, profile); switchLink(profileLink, profile);
} }

View file

@ -247,13 +247,13 @@ struct ProfileManifest
} }
} }
buildProfile(tempDir, std::move(pkgs)); buildProfile(tempDir.string(), std::move(pkgs));
writeFile(tempDir + "/manifest.json", toJSON(*store).dump()); writeFile(tempDir / "manifest.json", toJSON(*store).dump());
/* Add the symlink tree to the store. */ /* Add the symlink tree to the store. */
StringSink sink; StringSink sink;
dumpPath(tempDir, sink); dumpPath(tempDir.string(), sink);
auto narHash = hashString(HashAlgorithm::SHA256, sink.s); auto narHash = hashString(HashAlgorithm::SHA256, sink.s);

View file

@ -43,7 +43,7 @@ public:
Path getRegistryPath() Path getRegistryPath()
{ {
if (registry_path.empty()) { if (registry_path.empty()) {
return fetchers::getUserRegistryPath(); return fetchers::getUserRegistryPath().string();
} else { } else {
return registry_path; return registry_path;
} }