1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-28 13:11:00 +01:00

Use std::filesystem::path in libflake.

This commit is contained in:
Ubuntu 2025-11-26 19:58:01 +00:00 committed by Sergei Zimmerman
parent aa0265f77e
commit 3e8c220b60
No known key found for this signature in database
4 changed files with 14 additions and 14 deletions

View file

@ -31,9 +31,9 @@ namespace nix::flake {
// setting name -> setting value -> allow or ignore. // setting name -> setting value -> allow or ignore.
typedef std::map<std::string, std::map<std::string, bool>> TrustedList; typedef std::map<std::string, std::map<std::string, bool>> TrustedList;
Path trustedListPath() std::filesystem::path trustedListPath()
{ {
return getDataDir() + "/trusted-settings.json"; return getDataDir() / "trusted-settings.json";
} }
static TrustedList readTrustedList() static TrustedList readTrustedList()
@ -48,7 +48,7 @@ static TrustedList readTrustedList()
static void writeTrustedList(const TrustedList & trustedList) static void writeTrustedList(const TrustedList & trustedList)
{ {
auto path = trustedListPath(); auto path = trustedListPath();
createDirs(dirOf(path)); createDirs(path.parent_path());
writeFile(path, nlohmann::json(trustedList).dump()); writeFile(path, nlohmann::json(trustedList).dump());
} }

View file

@ -74,7 +74,7 @@ FlakeRef::resolve(const fetchers::Settings & fetchSettings, Store & store, fetch
FlakeRef parseFlakeRef( FlakeRef parseFlakeRef(
const fetchers::Settings & fetchSettings, const fetchers::Settings & fetchSettings,
const std::string & url, const std::string & url,
const std::optional<Path> & baseDir, const std::optional<std::filesystem::path> & baseDir,
bool allowMissing, bool allowMissing,
bool isFlake, bool isFlake,
bool preserveRelativePaths) bool preserveRelativePaths)
@ -101,7 +101,7 @@ fromParsedURL(const fetchers::Settings & fetchSettings, ParsedURL && parsedURL,
std::pair<FlakeRef, std::string> parsePathFlakeRefWithFragment( std::pair<FlakeRef, std::string> parsePathFlakeRefWithFragment(
const fetchers::Settings & fetchSettings, const fetchers::Settings & fetchSettings,
const std::string & url, const std::string & url,
const std::optional<Path> & baseDir, const std::optional<std::filesystem::path> & baseDir,
bool allowMissing, bool allowMissing,
bool isFlake, bool isFlake,
bool preserveRelativePaths) bool preserveRelativePaths)
@ -121,7 +121,7 @@ std::pair<FlakeRef, std::string> parsePathFlakeRefWithFragment(
to 'baseDir'). If so, search upward to the root of the to 'baseDir'). If so, search upward to the root of the
repo (i.e. the directory containing .git). */ repo (i.e. the directory containing .git). */
path = absPath(path, baseDir, true); path = absPath(path, baseDir->string(), true);
if (isFlake) { if (isFlake) {
@ -243,7 +243,7 @@ parseFlakeIdRef(const fetchers::Settings & fetchSettings, const std::string & ur
std::optional<std::pair<FlakeRef, std::string>> parseURLFlakeRef( std::optional<std::pair<FlakeRef, std::string>> parseURLFlakeRef(
const fetchers::Settings & fetchSettings, const fetchers::Settings & fetchSettings,
const std::string & url, const std::string & url,
const std::optional<Path> & baseDir, const std::optional<std::filesystem::path> & baseDir,
bool isFlake) bool isFlake)
{ {
try { try {
@ -252,7 +252,7 @@ std::optional<std::pair<FlakeRef, std::string>> parseURLFlakeRef(
/* Here we know that the path must not contain encoded '/' or NUL bytes. */ /* Here we know that the path must not contain encoded '/' or NUL bytes. */
auto path = renderUrlPathEnsureLegal(parsed.path); auto path = renderUrlPathEnsureLegal(parsed.path);
if (!isAbsolute(path)) if (!isAbsolute(path))
parsed.path = splitString<std::vector<std::string>>(absPath(path, *baseDir), "/"); parsed.path = splitString<std::vector<std::string>>(absPath(path, baseDir->string()), "/");
} }
return fromParsedURL(fetchSettings, std::move(parsed), isFlake); return fromParsedURL(fetchSettings, std::move(parsed), isFlake);
} catch (BadURL &) { } catch (BadURL &) {
@ -263,7 +263,7 @@ std::optional<std::pair<FlakeRef, std::string>> parseURLFlakeRef(
std::pair<FlakeRef, std::string> parseFlakeRefWithFragment( std::pair<FlakeRef, std::string> parseFlakeRefWithFragment(
const fetchers::Settings & fetchSettings, const fetchers::Settings & fetchSettings,
const std::string & url, const std::string & url,
const std::optional<Path> & baseDir, const std::optional<std::filesystem::path> & baseDir,
bool allowMissing, bool allowMissing,
bool isFlake, bool isFlake,
bool preserveRelativePaths) bool preserveRelativePaths)
@ -347,7 +347,7 @@ FlakeRef FlakeRef::canonicalize() const
std::tuple<FlakeRef, std::string, ExtendedOutputsSpec> parseFlakeRefWithFragmentAndExtendedOutputsSpec( std::tuple<FlakeRef, std::string, ExtendedOutputsSpec> parseFlakeRefWithFragmentAndExtendedOutputsSpec(
const fetchers::Settings & fetchSettings, const fetchers::Settings & fetchSettings,
const std::string & url, const std::string & url,
const std::optional<Path> & baseDir, const std::optional<std::filesystem::path> & baseDir,
bool allowMissing, bool allowMissing,
bool isFlake) bool isFlake)
{ {

View file

@ -200,7 +200,7 @@ struct LockFlags
/** /**
* The path to a lock file to write to instead of the `flake.lock` file in the top-level flake * The path to a lock file to write to instead of the `flake.lock` file in the top-level flake
*/ */
std::optional<Path> outputLockFilePath; std::optional<std::filesystem::path> outputLockFilePath;
/** /**
* Flake inputs to be overridden. * Flake inputs to be overridden.

View file

@ -95,7 +95,7 @@ std::ostream & operator<<(std::ostream & str, const FlakeRef & flakeRef);
FlakeRef parseFlakeRef( FlakeRef parseFlakeRef(
const fetchers::Settings & fetchSettings, const fetchers::Settings & fetchSettings,
const std::string & url, const std::string & url,
const std::optional<Path> & baseDir = {}, const std::optional<std::filesystem::path> & baseDir = {},
bool allowMissing = false, bool allowMissing = false,
bool isFlake = true, bool isFlake = true,
bool preserveRelativePaths = false); bool preserveRelativePaths = false);
@ -106,7 +106,7 @@ FlakeRef parseFlakeRef(
std::pair<FlakeRef, std::string> parseFlakeRefWithFragment( std::pair<FlakeRef, std::string> parseFlakeRefWithFragment(
const fetchers::Settings & fetchSettings, const fetchers::Settings & fetchSettings,
const std::string & url, const std::string & url,
const std::optional<Path> & baseDir = {}, const std::optional<std::filesystem::path> & baseDir = {},
bool allowMissing = false, bool allowMissing = false,
bool isFlake = true, bool isFlake = true,
bool preserveRelativePaths = false); bool preserveRelativePaths = false);
@ -117,7 +117,7 @@ std::pair<FlakeRef, std::string> parseFlakeRefWithFragment(
std::tuple<FlakeRef, std::string, ExtendedOutputsSpec> parseFlakeRefWithFragmentAndExtendedOutputsSpec( std::tuple<FlakeRef, std::string, ExtendedOutputsSpec> parseFlakeRefWithFragmentAndExtendedOutputsSpec(
const fetchers::Settings & fetchSettings, const fetchers::Settings & fetchSettings,
const std::string & url, const std::string & url,
const std::optional<Path> & baseDir = {}, const std::optional<std::filesystem::path> & baseDir = {},
bool allowMissing = false, bool allowMissing = false,
bool isFlake = true); bool isFlake = true);