Skip to content

Commit 6c4ed46

Browse files
edolstraEricson2314
authored andcommitted
Add Setting<std::filesystem::path> specialization
Like PathSetting, this normalizes the path (without resolving symlinks).
1 parent 2e262c6 commit 6c4ed46

File tree

4 files changed

+25
-11
lines changed

4 files changed

+25
-11
lines changed

src/libutil/configuration.cc

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,26 @@ std::string BaseSetting<StringMap>::to_string() const
433433
[](const auto & kvpair) { return kvpair.first + "=" + kvpair.second; });
434434
}
435435

436+
static Path parsePath(const AbstractSetting & s, const std::string & str)
437+
{
438+
if (str == "")
439+
throw UsageError("setting '%s' is a path and paths cannot be empty", s.name);
440+
else
441+
return canonPath(str);
442+
}
443+
444+
template<>
445+
std::filesystem::path BaseSetting<std::filesystem::path>::parse(const std::string & str) const
446+
{
447+
return parsePath(*this, str);
448+
}
449+
450+
template<>
451+
std::string BaseSetting<std::filesystem::path>::to_string() const
452+
{
453+
return value.string();
454+
}
455+
436456
template class BaseSetting<int>;
437457
template class BaseSetting<unsigned int>;
438458
template class BaseSetting<long>;
@@ -445,14 +465,7 @@ template class BaseSetting<Strings>;
445465
template class BaseSetting<StringSet>;
446466
template class BaseSetting<StringMap>;
447467
template class BaseSetting<std::set<ExperimentalFeature>>;
448-
449-
static Path parsePath(const AbstractSetting & s, const std::string & str)
450-
{
451-
if (str == "")
452-
throw UsageError("setting '%s' is a path and paths cannot be empty", s.name);
453-
else
454-
return canonPath(str);
455-
}
468+
template class BaseSetting<std::filesystem::path>;
456469

457470
PathSetting::PathSetting(
458471
Config * options,

src/libutil/include/nix/util/config-impl.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ DECLARE_CONFIG_SERIALISER(Strings)
134134
DECLARE_CONFIG_SERIALISER(StringSet)
135135
DECLARE_CONFIG_SERIALISER(StringMap)
136136
DECLARE_CONFIG_SERIALISER(std::set<ExperimentalFeature>)
137+
DECLARE_CONFIG_SERIALISER(std::filesystem::path)
137138

138139
template<typename T>
139140
T BaseSetting<T>::parse(const std::string & str) const

src/libutil/include/nix/util/logging.hh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ struct LoggerSettings : Config
5454
expression evaluation errors.
5555
)"};
5656

57-
Setting<Path> jsonLogPath{
57+
Setting<std::filesystem::path> jsonLogPath{
5858
this,
59-
"",
59+
{},
6060
"json-log-path",
6161
R"(
6262
A file or unix socket to which JSON records of Nix's log output are

src/libutil/logging.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ void applyJSONLogger()
370370
if (!loggerSettings.jsonLogPath.get().empty()) {
371371
try {
372372
std::vector<std::unique_ptr<Logger>> loggers;
373-
loggers.push_back(makeJSONLogger(std::filesystem::path(loggerSettings.jsonLogPath.get()), false));
373+
loggers.push_back(makeJSONLogger(loggerSettings.jsonLogPath.get(), false));
374374
try {
375375
logger = makeTeeLogger(std::move(logger), std::move(loggers));
376376
} catch (...) {

0 commit comments

Comments
 (0)