-
Notifications
You must be signed in to change notification settings - Fork 702
Settings daemon driver - take 2 #835
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
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.
Hey, that's exactly what we need, just a few polishing touches :)
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.
Thanks for the review @Saviq , here are my replies.
0df7cf9
to
7c7d345
Compare
@Saviq I replied to your points, but github is not dealing well with the multiple reviews. You can see them in the files tab or in each original comment's thread in this page. |
Yeah I thought I was being smart by "reviewing" all the comments rather than commenting one-by-one. Seems Github outsmarted me by making a mess out of that. |
That is what I did also. It usually works, but maybe not if both sides use that approach. |
Codecov Report
@@ Coverage Diff @@
## master #835 +/- ##
==========================================
+ Coverage 68.74% 68.86% +0.11%
==========================================
Files 191 191
Lines 6530 6545 +15
==========================================
+ Hits 4489 4507 +18
+ Misses 2041 2038 -3
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #835 +/- ##
=========================================
+ Coverage 68.75% 68.8% +0.04%
=========================================
Files 192 192
Lines 6602 6635 +33
=========================================
+ Hits 4539 4565 +26
- Misses 2063 2070 +7
Continue to review full report at Codecov.
|
I remembered why we discarded If you deem the
If you want to stick with previous decisions despite newly found implications, or if you simply do not have a preference and/or just want me to decide, please also let me know that. If it were up to me (and excluding new findings) I would probably go with 2 above and consider |
I'm fine with |
OK, I will make that change then. |
Unfortunately I again stumbled upon
After some investigation I ended up solving this by checking The remaining "dir case" is reported by |
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.
A handful of questions/nitpicks below.
This could use a nicer error message:
Just realized:
The supported format for This works, but shouldn't:
|
Like what? Do you mean adding "try sudo" or something? Or just totally different message?
Yes, I thought the equals-sign was just a quirk of description, since we separate all positional arguments w/ space currently. I will change it if it really was intentional.
Well, those will fail the daemon when it tries to restart (just like the env vars and |
Yeah, something like that.
It was intentional so you can provide multiple key/value pairs without those getting confusing.
Right, the problem is that the client then just says:
And setting a different value doesn't resolve that, since the daemon's dead by then and won't be restarted automatically. |
I see. Alright, fixing pending items. |
Only last couple of points missing ( |
66c128d
to
50da5ad
Compare
OK, so those two items are in. But reading back #756 and comments above, there is actually a 3rd item that I did not push yet: supporting multiple key-value pairs in
Option 1 would mean committing to an order or leaving the settings in an undefined state. Either way, it does not sound very user-friendly. Option 2 would require bookkeeping shenanigans and clarifying what caused what in the output (think different error causes in different arguments, building error text in an iterating maner from multiple exception msgs and corresponding args...). This would probably feel clunky to the user (not to mention the programmer). Both 1 and 2 suffer from other downsides as well:
Option 3 is the cleaner one IMO. We only let the request go through if it is 100% correct. While this could be done by keeping former values to revert to in case of error, that could be a bit clumsy – there could be problems when trying to revert and things would be left in an undefined state. Doing option 3 properly requires changing the current interface of the
Sudoing the second step above would create a root-owned client file. Client settings would not work without For this reason (reason 2 above), and because we have only two settings for the time being, I thing our best option is to allow only one argument in |
PS: In either case, perhaps this PR can already be merged. I would then deal with the other platforms before moving on to further functionality. |
@ricab yeah, multi-set would be a later step towards full config story, I didn't mean it should happen in this PR, just that the |
src/client/cli/cmd/set.cpp
Outdated
|
||
auto status = parser->commandParse(this); | ||
if (status == ParseCode::Ok) | ||
{ | ||
const auto args = parser->positionalArguments(); | ||
if (args.count() == 2) | ||
if (args.isEmpty()) |
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.
If someone provides more than one, it will be silently dropped?
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.
Good catch, I did not do this because I meant to evolve to multiple arguments and then forgot.
PersistentSettingsException(const QString& attempted_operation, const QString& failure) | ||
: SettingsException{fmt::format("Could not {} settings: {} error", attempted_operation, failure)} | ||
PersistentSettingsException(const QString& attempted_operation, const QString& detail) | ||
: SettingsException{fmt::format("Unable to {} settings: {}", attempted_operation, detail)} |
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.
I won't block on this, but we'll have to move away from constructing the error message like this later.
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.
I am not sure what the issue is. Note that attempted_operation
could be an enum here, representing read and write ops, that we would then turn into string. Then detail
is a separate phrase. How could I make this friendlier to translation? Perhaps an example of what problems this could cause would help me understand better.
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.
Basically what I mean is that "Unable to format settings" may translate to something completely different than "Unable to access settings" depending on language.
Different languages work in very different ways, building a sentence from a set of strings is bound to break at one point or another. It's a discussion to have over beers, though :)
I'm just sensitive to this because I've translated a lot of software over the years and Polish is one of the more complex languages out there so it easily highlights problems in approaches like that.
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.
I think I understand the idea. To avoid duplication, I think I would then try a more "square" way, e.g. "Unable to operate on settings. Operation: {}; Details: {}". But this might not feel so good for the user... Isn't this the sort of thing that one would do when preparing the code for translation? Preemptively duplicating messages in the code does not feel right to me either.
BTW, the operation here is just "read" or "read/write", "format/access" goes in the second param as a free string.
src/utils/settings.cpp
Outdated
: QStringLiteral("access")}; | ||
throw mp::PersistentSettingsException{ | ||
attempted_operation, status == QSettings::FormatError ? QStringLiteral("format error") | ||
: QStringLiteral("access error (consider `sudo`)")}; |
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.
How will we approach this for Windows, where sudo
is not a thing?
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.
Good point. How about "consider running this with an administrative role"? (Replacing it here and having the same msg in all platforms)
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.
Works for me.
src/client/cli/cmd/set.cpp
Outdated
cerr << "Need exactly one option key and one value\n"; | ||
status = ParseCode::CommandLineError; | ||
const auto keyval = args.at(0).split('='); | ||
if (keyval.count() != 2 || keyval.contains(QStringLiteral(""))) |
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.
Long-term we'll need to be smarter here, I can imagine some values including =
characters. So either we split at the first one only, or require some escape sequences.
Not in this PR, though.
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.
OK, leaving it for now. multipass config
would be an alternative for those cases in the future.
OK, the reasoning stands for when it should happen, and can perhaps elucidate whether it should happen. |
4ed3637
to
52fd7a0
Compare
Adds a platform-dependent derivation of the daemon-config directory.
So that "on-failure-restart policies" are enough to restart the daemon when the settings change.
Use a `/root/config`-based dir for the default daemon-settings location. Add the application name to that path, for consistency with the client.
To avoid `Settings::get` returning a default in that case.
Co-Authored-By: Michał Sawicz <michal@sawicz.net>
Currently failing (implementation pending).
Fails `set` command with unsupported driver. Makes previous tests pass.
Refactor a couple of cli client tests on `set` cmd.
Currently failing (implementation pending).
Currently failing (implementation pending).
Makes previous tests pass.
To accommodate adding other unrelated parameterized tests.
So that it makes sense on other platforms.
52fd7a0
to
62166a3
Compare
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.
's good!
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 looks good to me. I had one question below that needs answered before I approve:)
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.
Ok, all good.
bors r=Saviq, townsend2010
Build failed |
Fixes #776.
New attempt, using a central file for daemon settings and requiring admin privileges to set.