diff --git a/src/libcmd/repl.cc b/src/libcmd/repl.cc index 38a0da0f8..8fbb54dd3 100644 --- a/src/libcmd/repl.cc +++ b/src/libcmd/repl.cc @@ -142,7 +142,7 @@ NixRepl::NixRepl( , getValues(getValues) , staticEnv(new StaticEnv(nullptr, state->staticBaseEnv)) , runNixPtr{runNix} - , interacter(make_unique(getDataDir() + "/repl-history")) + , interacter(make_unique((getDataDir() / "repl-history").string())) { } diff --git a/src/libfetchers/cache.cc b/src/libfetchers/cache.cc index 67361c765..183f106a5 100644 --- a/src/libfetchers/cache.cc +++ b/src/libfetchers/cache.cc @@ -38,7 +38,7 @@ struct CacheImpl : Cache { auto state(_state.lock()); - auto dbPath = getCacheDir() + "/fetcher-cache-v4.sqlite"; + auto dbPath = (getCacheDir() / "fetcher-cache-v4.sqlite").string(); createDirs(dirOf(dbPath)); state->db = SQLite(dbPath); diff --git a/src/libfetchers/git-utils.cc b/src/libfetchers/git-utils.cc index f62c3b9b4..fecceefff 100644 --- a/src/libfetchers/git-utils.cc +++ b/src/libfetchers/git-utils.cc @@ -212,7 +212,7 @@ static void initRepoAtomically(std::filesystem::path & path, bool bare) AutoDelete delTmpDir(tmpDir, true); 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); try { std::filesystem::rename(tmpDir, path); diff --git a/src/libfetchers/git.cc b/src/libfetchers/git.cc index 08cd5d1ca..4f5247861 100644 --- a/src/libfetchers/git.cc +++ b/src/libfetchers/git.cc @@ -61,7 +61,7 @@ std::optional readHead(const std::filesystem::path & path) RunOptions{ .program = "git", // FIXME: use 'HEAD' to avoid returning all refs - .args = {"ls-remote", "--symref", path}, + .args = {"ls-remote", "--symref", path.string()}, .isInteractive = true, }); 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); 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) { if ( #ifndef WIN32 // TODO abstract over exit status handling on Windows @@ -115,7 +115,7 @@ std::optional readHeadCached(const std::string & actualUrl, bool sh time_t now = time(0); struct stat st; std::optional cachedRef; - if (stat(headRefFile.c_str(), &st) == 0) { + if (stat(headRefFile.string().c_str(), &st) == 0) { cachedRef = readHead(cacheDir); if (cachedRef != std::nullopt && *cachedRef != gitInitialBranch && isCacheFileWithinTtl(now, st)) { debug("using cached HEAD ref '%s' for repo '%s'", *cachedRef, actualUrl); @@ -450,7 +450,7 @@ struct GitInputScheme : InputScheme if (input.getRev()) throw UnimplementedError("cloning a specific revision is not implemented"); - args.push_back(destDir); + args.push_back(destDir.string()); runProgram("git", true, args, {}, true); } diff --git a/src/libfetchers/mercurial.cc b/src/libfetchers/mercurial.cc index 65999497c..dd31e224f 100644 --- a/src/libfetchers/mercurial.cc +++ b/src/libfetchers/mercurial.cc @@ -281,27 +281,28 @@ struct MercurialInputScheme : InputScheme /* If this is a commit hash that we already have, we don't have to pull again. */ 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 == "1")) { Activity act(*logger, lvlTalkative, actUnknown, fmt("fetching Mercurial repository '%s'", actualUrl)); if (pathExists(cacheDir)) { try { - runHg({"pull", "-R", cacheDir, "--", actualUrl}); + runHg({"pull", "-R", cacheDir.string(), "--", actualUrl}); } catch (ExecError & e) { auto transJournal = cacheDir / ".hg" / "store" / "journal"; /* hg throws "abandoned transaction" error only if this file exists */ if (pathExists(transJournal)) { - runHg({"recover", "-R", cacheDir}); - runHg({"pull", "-R", cacheDir, "--", actualUrl}); + runHg({"recover", "-R", cacheDir.string()}); + runHg({"pull", "-R", cacheDir.string(), "--", actualUrl}); } else { throw ExecError(e.status, "'hg pull' %s", statusToString(e.status)); } } } else { 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>(runHg( {"log", "-R", - cacheDir, + cacheDir.string(), "-r", input.getRev() ? input.getRev()->gitRev() : *input.getRef(), "--template", @@ -329,7 +330,7 @@ struct MercurialInputScheme : InputScheme std::filesystem::path tmpDir = createTempDir(); 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"); diff --git a/src/libfetchers/registry.cc b/src/libfetchers/registry.cc index c81eb6b53..f96ef89b3 100644 --- a/src/libfetchers/registry.cc +++ b/src/libfetchers/registry.cc @@ -150,7 +150,7 @@ static std::shared_ptr getGlobalRegistry(const Settings & settings, St if (!isAbsolute(path)) { auto storePath = downloadFile(store, settings, path, "flake-registry.json").storePath; if (auto store2 = dynamic_cast(&store)) - store2->addPermRoot(storePath, getCacheDir() + "/flake-registry.json"); + store2->addPermRoot(storePath, (getCacheDir() / "flake-registry.json").string()); return {store.requireStoreObjectAccessor(storePath)}; } else { return SourcePath{getFSSourceAccessor(), CanonPath{path}}.resolveSymlinks(); diff --git a/src/libmain/shared.cc b/src/libmain/shared.cc index 8a59e3dac..ad1caae2b 100644 --- a/src/libmain/shared.cc +++ b/src/libmain/shared.cc @@ -304,7 +304,7 @@ void printVersion(const std::string & programName) std::cout << "System type: " << settings.thisSystem << "\n"; std::cout << "Additional system types: " << concatStringsSep(", ", settings.extraPlatforms.get()) << "\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 << "Store directory: " << settings.nixStore << "\n"; std::cout << "State directory: " << settings.nixStateDir << "\n"; diff --git a/src/libstore/globals.cc b/src/libstore/globals.cc index 9e72f8577..27d17e1a9 100644 --- a/src/libstore/globals.cc +++ b/src/libstore/globals.cc @@ -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 ~/.nix/nix.conf or the command line. */ @@ -145,7 +145,7 @@ std::vector getUserConfigFiles() std::vector files; auto dirs = getConfigDirs(); for (auto & dir : dirs) { - files.insert(files.end(), dir + "/nix.conf"); + files.insert(files.end(), (dir / "nix.conf").string()); } return files; } diff --git a/src/libstore/nar-info-disk-cache.cc b/src/libstore/nar-info-disk-cache.cc index 11608a667..b0e56fa74 100644 --- a/src/libstore/nar-info-disk-cache.cc +++ b/src/libstore/nar-info-disk-cache.cc @@ -86,7 +86,7 @@ public: Sync _state; - NarInfoDiskCacheImpl(Path dbPath = getCacheDir() + "/binary-cache-v7.sqlite") + NarInfoDiskCacheImpl(Path dbPath = (getCacheDir() / "binary-cache-v7.sqlite").string()) { auto state(_state.lock()); diff --git a/src/libutil/file-system.cc b/src/libutil/file-system.cc index e81263a56..0ad6d9285 100644 --- a/src/libutil/file-system.cc +++ b/src/libutil/file-system.cc @@ -687,7 +687,7 @@ std::filesystem::path createTempDir(const std::filesystem::path & tmpRoot, const checkInterrupt(); std::filesystem::path tmpDir = makeTempPath(tmpRoot, prefix); if (mkdir( - tmpDir.c_str() + tmpDir.string().c_str() #ifndef _WIN32 // TODO abstract mkdir perms for Windows , mode @@ -734,7 +734,7 @@ AutoCloseFD createAnonymousTempFile() std::pair createTempFile(const Path & prefix) { - Path tmpl(defaultTempDir() + "/" + prefix + ".XXXXXX"); + Path tmpl(defaultTempDir().string() + "/" + prefix + ".XXXXXX"); // Strictly speaking, this is UB, but who cares... // FIXME: use O_TMPFILE. // FIXME: Windows should use FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE diff --git a/src/libutil/serialise.cc b/src/libutil/serialise.cc index ba8e573a7..19ea4debd 100644 --- a/src/libutil/serialise.cc +++ b/src/libutil/serialise.cc @@ -207,7 +207,8 @@ void FdSource::restart() throw Error("can't seek to the start of a file"); buffer.reset(); 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"); } diff --git a/src/libutil/users.cc b/src/libutil/users.cc index e07b5535e..1fa643730 100644 --- a/src/libutil/users.cc +++ b/src/libutil/users.cc @@ -90,7 +90,7 @@ std::string expandTilde(std::string_view path) // TODO: expand ~user ? auto tilde = path.substr(0, 2); if (tilde == "~/" || tilde == "~") - return getHome() + std::string(path.substr(1)); + return getHome().string() + std::string(path.substr(1)); else return std::string(path); } diff --git a/src/libutil/windows/users.cc b/src/libutil/windows/users.cc index cbeadcb81..eb92e7ab6 100644 --- a/src/libutil/windows/users.cc +++ b/src/libutil/windows/users.cc @@ -40,7 +40,7 @@ std::filesystem::path getHome() static std::filesystem::path homeDir = []() { std::filesystem::path homeDir = getEnv("USERPROFILE").value_or("C:\\Users\\Default"); assert(!homeDir.empty()); - return canonPath(homeDir); + return canonPath(homeDir.string()); }(); return homeDir; } diff --git a/src/nix/nix-env/nix-env.cc b/src/nix/nix-env/nix-env.cc index edfccffa6..a673259f2 100644 --- a/src/nix/nix-env/nix-env.cc +++ b/src/nix/nix-env/nix-env.cc @@ -1292,7 +1292,7 @@ static void opSwitchProfile(Globals & globals, Strings opFlags, Strings opArgs) throw UsageError("exactly one argument expected"); 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); } diff --git a/src/nix/profile.cc b/src/nix/profile.cc index 5b0e033e0..822c8046e 100644 --- a/src/nix/profile.cc +++ b/src/nix/profile.cc @@ -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. */ StringSink sink; - dumpPath(tempDir, sink); + dumpPath(tempDir.string(), sink); auto narHash = hashString(HashAlgorithm::SHA256, sink.s); diff --git a/src/nix/registry.cc b/src/nix/registry.cc index d62665a58..6d913adcd 100644 --- a/src/nix/registry.cc +++ b/src/nix/registry.cc @@ -43,7 +43,7 @@ public: Path getRegistryPath() { if (registry_path.empty()) { - return fetchers::getUserRegistryPath(); + return fetchers::getUserRegistryPath().string(); } else { return registry_path; }