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

Fix symlink resolution when mounting #3673

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Conversation

Sploder12
Copy link
Contributor

@Sploder12 Sploder12 commented Sep 12, 2024

fixes #1722

Symbolic links are now resolved when performing a mount.
Previously they were not resolved.

Copy link

codecov bot commented Sep 12, 2024

Codecov Report

Attention: Patch coverage is 80.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 88.92%. Comparing base (2f84668) to head (ccac3af).

Files with missing lines Patch % Lines
src/utils/vm_mount.cpp 75.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3673      +/-   ##
==========================================
- Coverage   88.92%   88.92%   -0.01%     
==========================================
  Files         254      254              
  Lines       14299    14309      +10     
==========================================
+ Hits        12716    12724       +8     
- Misses       1583     1585       +2     

☔ 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.

Thank you Trevor! Superficial review from my side, but it looks like it's headed in the right direction. I have a couple of comments inline.

? std::make_unique<SSHFSMountHandler>(vm, config->ssh_key_provider.get(), target, mount)
: vm->make_native_mount_handler(target, mount);
? std::make_unique<SSHFSMountHandler>(vm, config->ssh_key_provider.get(), target, std::move(mount))
: vm->make_native_mount_handler(target, std::move(mount));
Copy link
Collaborator

Choose a reason for hiding this comment

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

This one doesn't help much unless you change make_native_mount_handler to take by value and move too. Otherwise you're asking for one extra temporary.

src/utils/vm_mount.cpp Show resolved Hide resolved
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.

Hey Trevor, this works well for what it does and the code looks good. However, currently it covers only paths ending in a symlink. I guess we should cover symlinks anywhere in the path, don't you think?

ricab@ricab-XPS-9320:~/tmp/asdf $ ln -s .. l4
ricab@ricab-XPS-9320:~/tmp/asdf $ cd
ricab@ricab-XPS-9320:~ $ mp mount tmp/asdf/l4/subl-mdpreview/ amazed-topi:l4
ricab@ricab-XPS-9320:~ $ mp info amazed-topi
Name:           amazed-topi
State:          Running
Snapshots:      2
IPv4:           10.251.95.73
Release:        Ubuntu 24.04.1 LTS
Image hash:     78547d336e4c (Ubuntu 24.04 LTS)
CPU(s):         2
Load:           0.00 0.00 0.00
Disk usage:     2.0GiB out of 4.8GiB
Memory usage:   342.3MiB out of 955.7MiB
Mounts:         /home/ricab/tmp/asdf/l4/subl-mdpreview => l4
                    UID map: 1000:default
                    GID map: 1000:default

I expected the source to become just /home/ricab/tmp/subl-mdpreview


if (err)
throw std::runtime_error(
fmt::format("Mount symlink source path \"{}\" could not be made weakly canonical: {}.",
Copy link
Collaborator

Choose a reason for hiding this comment

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

This would end up being shown to the user, right? If so, I would try to make it more user friendly. Perhaps:

Suggested change
fmt::format("Mount symlink source path \"{}\" could not be made weakly canonical: {}.",
fmt::format("Could not resolve symlinks in mount source path \"{}\": {}.",

src/utils/vm_mount.cpp Outdated Show resolved Hide resolved
@ricab
Copy link
Collaborator

ricab commented Oct 14, 2024

Hey Trevor, a quick experiment I did:

#include <filesystem>
#include <iostream>

using namespace std;
namespace fs = std::filesystem;

int main()
{
  // l4 -> ..
  // l2 -> ../subl-mdpreview
  auto src_path = "/home/ricab/tmp/asdf/l4/asdf/l4/asdf/l2/";

  error_code ec{};
  auto dst_path = fs::weakly_canonical(src_path, ec);

  if (!ec)
    cout << "\"" << src_path << "\" == " << dst_path << endl;

  // prints "/home/ricab/tmp/asdf/l4/asdf/l4/asdf/l2/" == "/home/ricab/tmp/subl-mdpreview"

  return bool(ec);
}

@Sploder12
Copy link
Contributor Author

I wonder if we should check elsewhere in the repo for usage of \"{}\" since a string like Hello\\ could cause issues (becomes "Hello\"). WDYT?

@sharder996 sharder996 added this to the 1.15.0 milestone Oct 30, 2024
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.

Mount does not follow symlinks
4 participants