Skip to content
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

Selection of default upgrade policy #239

Merged
merged 19 commits into from
Jul 26, 2022
Merged

Selection of default upgrade policy #239

merged 19 commits into from
Jul 26, 2022

Conversation

EduardGomezEscandell
Copy link
Contributor

This PR is a temporary solution to #226.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Please check out carefully the isses found by clang-tidy in the new code ⚠️
⚠️ clang-format found formatting issues in the code submitted.:warning:
Make sure to run clang-format and update this pull request.
(1/1)

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Please check out carefully the isses found by clang-tidy in the new code ⚠️
⚠️ clang-format found formatting issues in the code submitted.:warning:
Make sure to run clang-format and update this pull request.
(1/1)

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Please check out carefully the isses found by clang-tidy in the new code ⚠️
⚠️ clang-format found formatting issues in the code submitted.:warning:
Make sure to run clang-format and update this pull request.
(1/1)

Copy link
Collaborator

@CarlosNihelton CarlosNihelton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are almost done, I think.

const fs::path log{L"/var/log/upgrade-policy-changed.log"};
const fs::path policyfile{L"/etc/update-manager/release-upgrades"};

if (fs::exists(Oobe::WindowsPath(log))) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this line will run on every launch, it is subject to user configuration preventing Windows from being able to execute the filesystem calls, thus throwing filesystem exceptions. You may want to consider calling the std::error_code overload to avoid such behavior.

Now we raise a subsequent question; what to do on error? If we cannot assess whether the log exists or not through the filesystem API what should we do? We can fallback to test with a Linux command, like if (WslLaunchSuccess(L"ls $log")).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree on the fallback mechanism. I used test -f $log.

void SetDefaultUpgradePolicy()
{
auto mutex = NamedMutex(L"upgrade-policy");
mutex.lock().and_then(internal::SetDefaultUpgradePolicyImpl);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative to my previous comment about filesystem exceptions might be setting a reasonable or_else function here. But that seems more complicated, unless you don't want to proceed in case of filesystem errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beware that or_else is called when we fail to switch user to root.

Throwing an exception during and_then will only revert the user to default and rethrow again; it will not call or_else.

I think the best is to have a fallback.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Please check out carefully the isses found by clang-tidy in the new code ⚠️
⚠️ clang-format found formatting issues in the code submitted.:warning:
Make sure to run clang-format and update this pull request.
(1/1)

Copy link
Collaborator

@CarlosNihelton CarlosNihelton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Please do not forget to squash that one. There are a lot of less-interesting commits due merges and linting fixes overloading the commit history.

@CarlosNihelton CarlosNihelton merged commit f107eef into main Jul 26, 2022
@CarlosNihelton CarlosNihelton deleted the upgrade-policy branch July 26, 2022 16:52
@CarlosNihelton
Copy link
Collaborator

I merged, because I'll need one function you've implemented here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants