fix(cli): preserve directory basename when uploading to sandbox (#885)#976
Open
mjamiv wants to merge 1 commit intoNVIDIA:mainfrom
Open
fix(cli): preserve directory basename when uploading to sandbox (#885)#976mjamiv wants to merge 1 commit intoNVIDIA:mainfrom
mjamiv wants to merge 1 commit intoNVIDIA:mainfrom
Conversation
Previously `openshell sandbox upload <local-dir> <remote-dir>` flattened the local directory's contents into the remote destination, dropping the source directory's basename. This diverged from the standard `scp -r` / `cp -r` semantics that operators expect from any *nix-style transfer tool, and could silently shadow files at the destination. Now an upload of `foo` to `/sandbox/dest/` lands at `/sandbox/dest/foo/`, matching `scp -r foo remote:/sandbox/dest/` and `cp -r foo /sandbox/dest/`. Paths without a meaningful basename (`.`, `/`) preserve the legacy flat extraction. Closes NVIDIA#885
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #885.
Summary
openshell sandbox upload <local-dir> <remote-dir>previously flattened the local directory's contents into the remote destination, dropping the source directory's basename. This diverged from the standardscp -r/cp -rsemantics that operators expect from any *nix-style transfer tool, and could silently shadow files at the destination.After this change, an upload of
footo/sandbox/dest/lands at/sandbox/dest/foo/, matchingscp -r foo remote:/sandbox/dest/andcp -r foo /sandbox/dest/. Paths without a meaningful basename (.,/) preserve the legacy flat extraction so that idiomaticupload .calls still work as before.Per #885 maintainer guidance, this is the variant A approach — match
scp -rsemantics by default — rather than adding an opt-in--preserve-dirflag.Scope
Single-file change to
crates/openshell-cli/src/ssh.rs:ssh_tar_uploadnow uses the computedtar_namefor the directory case instead of hardcoded".".directory_upload_prefix(local_path)helper returns the directory's basename for any path with a meaningful basename, and"."for.//.sandbox_sync_upcalls the helper for directory uploads.Tests
Two new unit tests in the existing
testsmodule:directory_upload_prefix_uses_basename_for_named_directories— covers/tmp/upload-test,foo, and./parent/nested.directory_upload_prefix_falls_back_to_dot_for_basename_less_paths— covers.and/.Reproduction (matches #885)
Before:
```
$ mkdir -p /tmp/upload-test/sub
$ echo a > /tmp/upload-test/a.txt
$ echo b > /tmp/upload-test/sub/b.txt
$ openshell sandbox upload /tmp/upload-test /sandbox/dest/
$ ssh 'ls /sandbox/dest/'
a.txt sub/ # upload-test/ basename dropped
```
After:
```
$ openshell sandbox upload /tmp/upload-test /sandbox/dest/
$ ssh 'ls /sandbox/dest/'
upload-test/ # basename preserved
$ ssh 'ls /sandbox/dest/upload-test/'
a.txt sub/
```
Compatibility note
This is a breaking change in the directory-upload behavior. Callers that relied on the flatten-into-destination semantics for directories (other than
.//) will need to either:/sandbox/dest/foo/→/sandbox/dest/), or.from inside the source directory to preserve the legacy behavior.Single-file uploads are unaffected.
Worth a release-note line. Happy to add a
BREAKING CHANGEfooter to the commit message or adocs(changelog):follow-up if that fits the project's release process.