fix(file): preserve directory contents when a copy source ends in a dot #4193
<!-- coderabbit-ai-generated:v1 -->
<!-- This is an auto-generated comment: summarize by coderabbit.ai -->
<!-- review_stack_entry_start -->
<a href="https://app.coderabbit.ai/change-stack/mvschwarz/openrig/pull/4193?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&cs_source=review_comment"><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change.svg" alt="Explain Change →" height="32"></picture></a>
<!-- review_stack_entry_end -->
<!-- recent_review_status_start -->
No actionable comments were generated in the recent review.
<!-- recent_review_status_end -->
<!-- walkthrough_start -->
<details>
<summary><strong>Walkthrough</strong></summary>
<dl>
<dd>
<br>
Local and remote path checks now preserve trailing-slash semantics for paths ending in /.. Tests cover planned rsync operands and native rsync behavior for the supported source suffixes.
Changes: Directory path handling
|Layer / File(s)|Summary|
|:---|:---|
|Preserve directory path semantics <br> packages/cli/src/lib/file-transfer.ts, packages/cli/test/file-transfer.test.ts|Local and remote path checks preserve trailing separators for paths ending in /.. Tests cover planned rsync operands and native rsync behavior for empty, /, and /. suffixes.|
<!-- change_assessment_start -->
Estimated code review effort: 2 (Simple) | ~10 minutes
<!-- change_assessment_commit:"422b32bddf008a335f0483fd4485417d753174f9" -->
<!-- change_assessment_priority:{"version":1,"urgency":"p2","manual":false} -->
Change: Bug fix
<!-- change_assessment_end -->
Suggested reviewers: vaishnavi220506
</dd>
</dl>
</details>
<!-- walkthrough_end -->
<details>
<summary><strong>Merge Risk:</strong> <strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/risk-unassessed-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Minimal</strong> · up to <code>422b3</code></summary>
<dl>
<dd>
<br>
<!-- final_review_risk_start -->
<!-- final_review_risk_label
Merge Risk: ⚪ Minimal · up to 422b3
-->
<!-- final_review_risk_coverage:{"sourceCommitId":"422b32bddf008a335f0483fd4485417d753174f9","coveredCommitId":"422b32bddf008a335f0483fd4485417d753174f9","kind":"reviewed"} -->
This change makes copying a source ending in /. place its contents directly in the destination, as rsync does. Tests cover the changed behavior and no merge-blocking concerns were found.
<!-- final_review_risk_end -->
</dd>
</dl>
</details>
<!-- pre_merge_checks_walkthrough_start -->
<details>
<summary><strong>Pre-merge checks: <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> 4</strong></summary>
<dl>
<dd>
<br>
| Check name | Status | Explanation |
| :------------------------ | :--------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Description Check | !Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check | !Passed | The title names the change: copying a directory's contents when a copy source ends in a dot. The raw summary says checkLocalPath and checkRemotePath now treat a final '.' component as a request to cop… |
| Linked Issues check | !Passed | Check skipped because no linked issues were found for this pull request. |
| Out of Scope Changes check | !Passed | Check skipped because no linked issues were found for this pull request. |
<details>
<summary><strong>Full details: Title check</strong></summary>
<dl>
<dd>
<br>
Explanation
The title names the change: copying a directory's contents when a copy source ends in a dot. The raw summary says checkLocalPath and checkRemotePath now treat a final '.' component as a request to copy directory contents, and the tests cover remote sources ending in '/.'. The title states the main change and the fix type. It does not mention the remote path handling or the test changes, which the title does not need to cover.
</dd>
</dl>
</details>
</dd>
</dl>
</details>
<!-- pre_merge_checks_walkthrough_end -->
<!-- finishing_touch_checkbox_start -->
<details>
<summary><strong>Finishing Touches</strong></summary>
<dl>
<dd>
<br>
<details open>
<summary><strong>Generate unit tests (beta)</strong></summary>
<dl>
<dd>
<br>
</dd>
</dl>
</details>
</dd>
</dl>
</details>
<!-- finishing_touch_checkbox_end -->
<!-- autopilot:start -->
<!-- autopilot:end -->
<!-- tips_start -->
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
<details>
<summary><strong>Share</strong></summary>
<dl>
<dd>
<br>
</dd>
</dl>
</details>
<!-- tips_end -->
<!-- recent_review_start -->
<h6>
<details>
<summary><strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/info.svg" width="12" height="12" align="absmiddle" alt=""></picture> Recent review info</strong></summary>
<dl>
<dd>
<br>
<!-- review_info_content -->
<details>
<summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog.svg" width="16" height="16" align="absmiddle" alt=""></picture> Run configuration</strong></summary>
<dl>
<dd>
<br>
961aca76-15b1-4cd7-a18c-122e22b4935b</dd>
</dl>
</details>
<details>
<summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal.svg" width="16" height="16" align="absmiddle" alt=""></picture> Commits</strong></summary>
<dl>
<dd>
<br>
Reviewing files that changed from the base of the PR and between 68e44f77b808b3242ced5f7d7191d3bf545e7c33 and 422b32bddf008a335f0483fd4485417d753174f9.
</dd>
</dl>
</details>
<details>
<summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner.svg" width="16" height="16" align="absmiddle" alt=""></picture> Files selected for processing: 2</strong></summary>
<dl>
<dd>
<br>
packages/cli/src/lib/file-transfer.ts
packages/cli/test/file-transfer.test.ts
</dd>
</dl>
</details>
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 0 remain after this review.
</dd>
</dl>
</details>
</h6>
<!-- recent_review_end -->
Approving the reviewed head 422b32bd to start the macOS package tests. A copy source ending in /. copies the directory's contents, as rsync does, for local and remote sources. Thank you, @oodadoudou.
Thanks, @oodadoudou, this is merged into main now. A rig file copy source ending in /. copies the folder's contents, as rsync does, instead of creating a folder of that name inside the destination. A bare . follows the same rule, so rig file copy . <dest> copies the current folder's contents. If you ever feel like adding a test for that bare . case, it would be welcome. It's on main and not yet in a published release.
Covered the bare . source in #4236. I also ran the built command against macOS rsync from a temporary directory and the file landed directly in the destination.
openrig-review
oodadoudou
What a user gets
rig file copy ./source/. ./destinationput the files underdestination/source/when the destination already existed. With the same arguments, rsync puts them directly indestination/. Preserve that directory-content meaning when normalizing local and remote operands.How you verified it
Reproduced the extra directory with a real local transfer. The native rsync test now checks the resulting file tree for
source,source/andsource/.. A separate assertion checks the rsync argument for a registered SSH source ending in/..At
422b32bdd,vitest run packages/cli/test/file-transfer.test.ts packages/cli/test/file-command.test.ts: 64 passed. The workspace build and typecheck passed with the five changes together. I did not run the fullnpm testlocally.Anything you were unsure about
The remote case checks the planned arguments; the actual transfer ran locally.
CHANGELOG.mdedit<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
<!-- coderabbit-ai-generated:v1 -->
Summary by CodeRabbit
Bug Fixes
Directory transfers now consistently copy a directory’s contents when the source path ends with
/., matching the behavior for paths ending in a separator.* Remote transfer planning and command construction now preserve this directory-copy behavior.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->