-
Notifications
You must be signed in to change notification settings - Fork 653
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
Snapshots #2993
Snapshots #2993
Conversation
@sharder996 Opening this so that we get CI and packages to test, at least with the stuff we already merged. I updated this branch to be on top of the daemon refactor (this needs to wait for that to be merged). |
Codecov Report
@@ Coverage Diff @@
## main #2993 +/- ##
==========================================
- Coverage 88.48% 84.03% -4.46%
==========================================
Files 240 250 +10
Lines 12171 13464 +1293
==========================================
+ Hits 10770 11315 +545
- Misses 1401 2149 +748
|
1cf8855
to
8e55166
Compare
a30ab9b
to
9e749f9
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.
Hey @ricab and @sharder996!
This is one BIG PR! Holy cow!!! Considering the absolute size of this, this is looking good overall. Although I spent the better part of Friday and today reviewing this, it is not complete. I have not reviewed the following files:
- The bash completions
info.cpp
- All the formatters
base_snapshot.*
base_virtual_machine.*
- And some of the test changes.
I'm waiting on reviewing info
and the formatters since I'd like to review in conjunction with the latest snap package which hasn't built as of this writing.
Also, even though I've spent a number of hours reviewing this, I would call what I've done so far a fairly complete review, but not a fined toothed comb type of review 💦
I am going to reply to items individually, but I acknowledge this must be very difficult to go through and I just want to thank you for the review to begin with 🌟 👏 |
@townsend2010, I think I have addressed all the items I said I would. Others I am waiting feedback on. Please let me know if I missed anything. |
bool cmd::Restore::confirm_destruction(const std::string& instance_name) | ||
{ | ||
static constexpr auto prompt_text = | ||
"Do you want to take a snapshot of {} before discarding its current state? (Yes/no)"; | ||
static constexpr auto invalid_input = "Please answer Yes/no"; | ||
mp::PlainPrompter prompter(term); | ||
|
||
auto answer = prompter.prompt(fmt::format(prompt_text, instance_name)); | ||
while (!answer.empty() && !std::regex_match(answer, yes_answer) && !std::regex_match(answer, no_answer)) | ||
answer = prompter.prompt(invalid_input); | ||
|
||
return std::regex_match(answer, no_answer); | ||
} |
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.
Nothing needs to be done at this moment, but this is quite similar to the code in launch
for it's prompt around asking for permission to create the bridge. I know @luis4a0 had done some refactoring in #3195, so we'll just need to consider how we may be able to refactor some of this once this PR is merged.
ef4a85e
to
8b3c7a6
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.
We are getting really close 😅 Just a couple of inline things below.
Also, I'm still reviewing delete
and restore
, but wanted to go ahead and get this quick feedback out.
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 @ricab and @sharder996!
I'm good with in it's current state and approving! Let's wait for feedback from @andrei-toterman before merging.
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.
Just a few small remarks :)
std::string trim(const std::string& s) | ||
{ | ||
return std::regex_replace(s, std::regex{R"(^\s+|\s+$)"}, ""); | ||
} |
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 this would be useful as part of utils
. Also, maybe declaring the regex as static inside this function would be a little more efficient, as it wouldn't have to parse and compile it from scratch on every invocation.
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.
Yup. Both improvements coming.
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.
For this one I ended up falling into a bit of a rabbit hole. I saw that there was already a trim_end
that was able to trim in place. I thought I'd better be consistent, reuse it, and avoid copying strings (which is nice on full file contents...). So I dropped the regex approach entirely. From there, it bugged me that I could not use the new utils with rvalues and went on to generalize those trimmers with templates, but I wanted to be careful to avoid any dangling refs or other pitfalls (I wouldn't mind another pair of attentive eyes on that code, just to be sure). The templates also allowed me to easily drop the std::function
wrappers. Please let me know if you're good with it.
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.
First, one little mistake here
template <typename Str, typename Filter>
Str&& multipass::utils::trim(Str&& s, Filter&& filter)
{
return trim_begin(trim_end(std::forward<Str>(s), std::forward<Filter>(filter)));
}
I think filter
should be passed to both trim_begin
and trim_end
. Now it is passed only to trim_end
and trim_begin
will always use is_space
.
Also, there is one minuscule detail about
inline constexpr auto is_space = static_cast<int (*)(int)>(std::isspace);
since the docs say that it's 'wrong' to use static_cast<int (*)(int)>(std::isspace)
when using it on std::string
and it should be instead used as [](unsigned char c){ return std::isspace(c); }
. I'm not really sure if this matters much, but I'd like to hear your opinion as well.
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.
Ahh, I knew I needed you to have a look. Fixes coming.
Store the (now immutable) ID string in a snapshot field and provide an accessor to it, rather than deriving it each time it is needed. Adapt client code accordingly.
Move throwing default implementation of `make_specific_snapshot` overloads to the base VM class.
Generalize trim utilities to operate on both lvalues and rvalues. Take the chance to drop the `std::function` wrapper for the filter predicate.
For better readability.
Manual integration test is running at https://github.com/canonical/multipass/actions/runs/6697249710. |
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, integration tests passed and I'm final approving this. Let's merge this ASAP!
🚀 🎉 🍾 🥳
This will fail, but want to get the commit message... bors merge |
👎 Rejected by label |
Try again... bors merge |
2993: Snapshots r=townsend2010 a=ricab Fixes #208 Co-authored-by: Ricardo Abreu <[email protected]> Co-authored-by: ScottH <[email protected]>
This PR was included in a batch that successfully built, but then failed to merge into main (it was a non-fast-forward update). It will be automatically retried. |
bors cancel |
Canceled. |
2993: Snapshots r=townsend2010 a=ricab Fixes #208 Co-authored-by: Ricardo Abreu <[email protected]> Co-authored-by: ScottH <[email protected]>
2993: Snapshots r=townsend2010 a=ricab Fixes #208 Co-authored-by: Ricardo Abreu <[email protected]> Co-authored-by: ScottH <[email protected]>
2993: Snapshots r=townsend2010 a=ricab Fixes #208 Co-authored-by: Ricardo Abreu <[email protected]> Co-authored-by: ScottH <[email protected]>
Fixes #208