-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add Setting<std::filesystem::path> and Setting<std::optional<std::filesystem::path>> specializations
#14632
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Like PathSetting, this normalizes the path (without resolving symlinks).
Ericson2314
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great change!
src/libutil/configuration.cc
Outdated
| template<> | ||
| std::filesystem::path BaseSetting<std::filesystem::path>::parse(const std::string & str) const | ||
| { | ||
| return std::filesystem::path(str).lexically_normal(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we also ensure that the path is absolute? That's what PathSetting requires currently
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yes good point.
xokdvium
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably ensure that the path is not absolute, as PathSetting already does.
93c51ac to
6c4ed46
Compare
|
Fixed, we can just use |
Setting<std::filesystem::path> specialization
| Setting<std::filesystem::path> jsonLogPath{ | ||
| this, | ||
| "", | ||
| {}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't look right tho? What's a default constructed path? Shouldn't this be an optional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Below the json logger is only created when the path is not empty. Shouldn't this get the same treatment as OptionalPath when an empty string signifies std::nullopt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah right Setting<Path> is just Setting<std::string>, the thing was totally busted before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The intent of this PR is that the path can be empty. E.g. json-log-path can be unset.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But the semantics of an empty path is that of a std::nullopt. Empty path doesn't make much sense
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the settings perspective it's the same, but my slight quip is that it would be more legible in the code if std::filesystem::path specified in the settings would have the invariant of being absolute and non-empty. Not really a blocker since it's already this way, but I think it'd be nice if we are moving to std::filesystem for this stuff.
Not exactly sure what would happen if someone accidentally tried doing any I/O with an empty path with std::filesystem and it seems nice to avoid that altogether.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it should use std::optional and work just like OptionalPathSetting. (It could just replace OptionalPathSetting.) It should use parsePath so please put that back.
6c4ed46 to
93c51ac
Compare
Setting<std::filesystem::path> specializationSetting<std::filesystem::path> and Setting<std::optional<std::filesystem::path>> specializations
b5c2501 to
1e36f20
Compare
|
Modulo the CI fixes sounds good |
|
Ah, precompiled headers strike again |
Motivation
Like
PathSetting, this normalizes the path (without resolving symlinks).Eventually, we should replace
PathSettingbySetting<std::filesystem::path>, andOptionalPathSettingbySetting<std::optional<std::filesystem::path>>.Context
Add 👍 to pull requests you find important.
The Nix maintainer team uses a GitHub project board to schedule and track reviews.