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

[daemon] let daemon choose mount target if not specified #3695

Merged
merged 1 commit into from
Oct 21, 2024

Conversation

andrei-toterman
Copy link
Contributor

This PR adds the functionality for the daemon to choose a mount target path if it is not given. Right now the logic is to take the last directory name in the source path and append it to /home/ubuntu e.g. given the source path /home/andrei/projects/multipass, the default target path would be /home/ubuntu/multipass

Copy link

codecov bot commented Sep 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.93%. Comparing base (bf3719d) to head (a7b3f43).
Report is 188 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3695      +/-   ##
==========================================
- Coverage   88.93%   88.93%   -0.01%     
==========================================
  Files         254      254              
  Lines       14299    14304       +5     
==========================================
+ Hits        12717    12721       +4     
- Misses       1582     1583       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@ricab ricab left a comment

Choose a reason for hiding this comment

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

Thanks Andrei, just a quick review pass.

@@ -235,6 +235,8 @@ class Utils : public Singleton<Utils>
virtual QString make_uuid(const std::optional<std::string>& seed = std::nullopt) const;
virtual void sleep_for(const std::chrono::milliseconds& ms) const;
virtual bool is_ipv4_valid(const std::string& ipv4) const;

virtual Path default_mount_target_from_source(const Path& source) const;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we have a shorter name, please? C++ is verbose enough as it is, and source is already mentioned in the parameter, so perhaps just:

Suggested change
virtual Path default_mount_target_from_source(const Path& source) const;
virtual Path default_mount_target(const Path& source) const;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, makes sense. I'll change that everywhere.

@@ -582,6 +582,11 @@ bool mp::Utils::is_ipv4_valid(const std::string& ipv4) const
return true;
}

mp::Path mp::Utils::default_mount_target_from_source(const Path& source) const
{
return source.isEmpty() ? "" : QDir{QDir::cleanPath(source)}.dirName().prepend("/home/ubuntu/");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't we throw if this is empty? You probably want to do that in this function's client (daemon) and make it a pre-condition here that the directory isn't empty, perhaps with an assert.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is a purpose for returning an empty path if given an empty path, which is the GUI target preview. If the source field in the GUI is left empty, the target should also be empty. So this just simplifies that process. But I understand that taken in isolation, the better behavior for this method is to error if the source is empty.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, well that could be done in the GUI itself, no? Anyway, I am OK keeping it like this as long as the daemon itself handles the case.

@andrei-toterman andrei-toterman force-pushed the default-mount-target-in-daemon branch 2 times, most recently from 9da2922 to e056ee9 Compare September 25, 2024 14:45
ricab
ricab previously approved these changes Sep 26, 2024
Copy link
Collaborator

@ricab ricab left a comment

Choose a reason for hiding this comment

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

Thanks @andrei-toterman! Let's wait for a primary reviewer, but LGTM on secondary review.

@andrei-toterman andrei-toterman force-pushed the default-mount-target-in-daemon branch 2 times, most recently from 57873ac to d830495 Compare October 4, 2024 12:04
@ricab ricab added this to the 1.15.0 milestone Oct 7, 2024
Copy link
Contributor

@Sploder12 Sploder12 left a comment

Choose a reason for hiding this comment

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

LGTM! default_mount_target returning "" is handled by the invalid_target_path check a little later so that edge case is properly handled by the daemon.

Copy link
Collaborator

@ricab ricab left a comment

Choose a reason for hiding this comment

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

Alright, this is going in, thanks!

@ricab ricab added this pull request to the merge queue Oct 21, 2024
@ricab ricab removed this pull request from the merge queue due to a manual request Oct 21, 2024
@ricab ricab added this pull request to the merge queue Oct 21, 2024
Merged via the queue into main with commit 316af44 Oct 21, 2024
14 checks passed
@ricab ricab deleted the default-mount-target-in-daemon branch October 21, 2024 15:38
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.

3 participants