Skip to content

fix(cli): preserve directory basename when uploading to sandbox (#885)#976

Open
mjamiv wants to merge 1 commit intoNVIDIA:mainfrom
mjamiv:fix/sandbox-upload-preserve-dir-default
Open

fix(cli): preserve directory basename when uploading to sandbox (#885)#976
mjamiv wants to merge 1 commit intoNVIDIA:mainfrom
mjamiv:fix/sandbox-upload-preserve-dir-default

Conversation

@mjamiv
Copy link
Copy Markdown
Contributor

@mjamiv mjamiv commented Apr 25, 2026

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 standard scp -r / cp -r semantics that operators expect from any *nix-style transfer tool, and could silently shadow files at the destination.

After this change, 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 so that idiomatic upload . calls still work as before.

Per #885 maintainer guidance, this is the variant A approach — match scp -r semantics by default — rather than adding an opt-in --preserve-dir flag.

Scope

Single-file change to crates/openshell-cli/src/ssh.rs:

  • ssh_tar_upload now uses the computed tar_name for the directory case instead of hardcoded ".".
  • New directory_upload_prefix(local_path) helper returns the directory's basename for any path with a meaningful basename, and "." for . / /.
  • sandbox_sync_up calls the helper for directory uploads.

Tests

Two new unit tests in the existing tests module:

  • 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:

  • adjust their destination path (/sandbox/dest/foo//sandbox/dest/), or
  • pass . 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 CHANGE footer to the commit message or a docs(changelog): follow-up if that fits the project's release process.

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
@mjamiv mjamiv requested a review from a team as a code owner April 25, 2026 02:20
@copy-pr-bot
Copy link
Copy Markdown

copy-pr-bot Bot commented Apr 25, 2026

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

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.

bug: openshell sandbox upload <local-dir> <remote-dir> flattens contents instead of creating named subdirectory

1 participant