Repository navigation
Support wildcards in instance-to-host transfers - #5096
onatozmenn wants to merge 10 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Adds guest-to-host wildcard expansion for multipass transfer by expanding *, ?, and [] patterns via SFTP directory listings (no remote shell), and wires this into the CLI path while documenting the quoting requirements.
Changes:
- Implement
SFTPClient::expand_remote_path()to expand remote wildcard components usingsftp_opendir/sftp_readdir, with hidden-file filtering and sorted/deduped results. - Update
transferCLI flow to expand remote sources before pulling and to require a directory destination when expansion yields multiple matches. - Add unit + CLI tests and update CLI documentation to describe quoted wildcard usage.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/test_sftp_client.cpp | Adds unit tests for remote wildcard expansion behavior and error cases. |
| tests/unit/test_cli_client.cpp | Adds CLI-level unit coverage to ensure remote wildcard expansion is invoked and validated. |
| tests/unit/mock_sftp_client.h | Extends SFTP client mock to support expand_remote_path(). |
| tests/cli/cli_transfer_test.py | Adds an integration-style CLI test for transferring multiple guest files via wildcard. |
| src/ssh/sftp_client.cpp | Implements wildcard expansion using SFTP directory iteration, hidden-file rules, and deterministic ordering. |
| src/client/cli/cmd/transfer.cpp | Expands instance sources via expand_remote_path() before pull and validates directory targets for multi-match cases. |
| include/multipass/ssh/sftp_client.h | Exposes the new expand_remote_path() API on SFTPClient. |
| docs/reference/command-line-interface/transfer.md | Documents quoting remote wildcard patterns and directory-destination requirements for multi-match transfers. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5096 +/- ##
==========================================
- Coverage 72.53% 71.20% -1.33%
==========================================
Files 339 348 +9
Lines 18355 19145 +790
==========================================
+ Hits 13312 13630 +318
- Misses 5043 5515 +472 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Had a look at the four red checks. The docs job hit a 403 on an unchanged Ask Ubuntu link, and the Intel macOS runner dropped during Build after Configure passed; GitHub has no log for the failed step. The package and Finalize failures are downstream of those two. I retriggered Dynamic CI as run 32249622115, but GitHub put the new fork run behind maintainer approval. Could someone approve it when convenient? |
1624a92 to
b471371
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved moderate issues affect stdout transfers and Windows path handling; documentation and test coverage also need updates.
Get a fresh assessment by requesting another Copilot review.
Review details
Suppressed comments (3)
docs/reference/command-line-interface/transfer.md:54
- The new documentation describes wildcard syntax but omits the dotfile rule implemented and tested here. Without stating that a wildcard does not match a hidden entry unless the pattern component starts with
., users can reasonably expect*to include dotfiles; please document this behavior alongside the multiple-match rule.
If the pattern matches multiple files, the destination must be a directory. Wildcards in local
source paths are expanded by the host shell as usual.
src/ssh/sftp_client.cpp:201
- This new expansion path returns a native
std::filesystem::path, but the downstream SFTP calls usesource_path.string(). On Windows, a nested candidate such asdir/first.txtis converted todir\\first.txt, which the Linux guest treats as a filename containing a backslash; the documented wildcard transfer therefore fails for nested paths on Windows. Keep the remote path in generic/form when calling SFTP (or avoid converting it through a native filesystem path).
std::transform(candidates.begin(),
candidates.end(),
std::back_inserter(paths),
[](auto& candidate) { return fs::path{std::move(candidate)}; });
tests/unit/test_sftp_client.cpp:75
- This mock converts a slash-separated remote directory path with
path.string(). On Windows,release-a/logsbecomesrelease-a\\logs, so the callback in the nested-path test does not match the intended branch and can consume the wrong entry vector. Store remote mock names withgeneric_string()instead.
dir->name = strdup(name.string().c_str());
- Files reviewed: 11/11 changed files
- Comments generated: 2
- Review effort level: Lite
|
Hi maintainers — a fresh sync has put the current-head Dynamic CI, Verify Commits, and CLA check runs into |
|
Follow-up pushed as |
d63302b to
bd35624
Compare
13d7397 to
2ab76ba
Compare
|
Rebased onto main and force-pushed as 2ab76ba, so the merge commits are gone. The four inline comments are addressed in that push: existing literal paths are checked before wildcard expansion, component splitting is simplified, the |
There was a problem hiding this comment.
🟡 Changes recommended
SFTP wildcard expansion ignores trailing-slash directory constraints and suppresses permission or connection errors, allowing unintended file downloads and incomplete transfers to be reported as successful.
2 open issues
Review effort: Balanced
tobe2098
left a comment
There was a problem hiding this comment.
LGTM, we are pretty close! There seems to be a test failure though, look at the Windows runner
Expand quoted instance-to-host wildcard patterns through SFTP directory listings without invoking a remote shell. Reuse the existing multi-source transfer path and require directory targets when a pattern yields multiple files. Add unit, CLI, and documentation coverage for canonical#3885.
Check for an existing literal path before expanding wildcards, so remote names such as a_[0].txt keep working. Cover literal paths and [[] patterns in the unit tests, simplify component splitting, and document literal-path precedence.
Propagate directory open failures after a wildcard so permission or connection errors are not hidden behind a partial transfer. Only SSH_FX_NO_SUCH_FILE, which also covers non-directory candidates on SFTP v3, is treated as a non-match. Honor a trailing slash on the source pattern by keeping only directory candidates and reporting no matches when none remain. Add unit tests for error propagation, non-directory candidates, and trailing-slash filtering.
When filtering literal components after a wildcard, only SSH_FX_NO_SUCH_FILE is treated as a non-match. Permission or connection errors now fail the transfer instead of silently dropping candidates. Add a unit test for an inaccessible path component.
Route existence and directory checks after wildcard expansion through one helper so a missing entry is the only condition treated as a non-match. Permission and connection failures now propagate from the trailing-slash filter too. Add a unit test for an inaccessible trailing-slash candidate.
Note that remote transfer patterns ending in '/' only match directories.
a8a8c7c to
72f3864
Compare


Description
When the source is inside an instance, the host shell cannot expand its path. This makes commands like this work:
Multipass expands the pattern through SFTP and then uses the existing pull path. It does not run a shell in the guest.
*,?, and character ranges are supported; hidden files still need an explicit leading dot. If a pattern matches more than one entry, the destination must be a directory.Related Issue(s)
Closes #3885
Testing
clang-format-diff-19,py_compile, andgit diff --checkpass.Screenshots (if applicable)
Not applicable.
Checklist