fix(copy): file-to-file extraction for copy_in/copy_out#261
Merged
DorianZheng merged 1 commit intomainfrom Feb 13, 2026
Merged
Conversation
copy_in("file.py", "/workspace/script.py") previously created a
directory named script.py instead of copying the file. The root cause
was that both guest upload and host download unconditionally treated
the destination as a directory to extract into.
Add mode-aware extraction that inspects tar contents and destination
state to choose between two modes:
- FileToFile: single regular file in tar + dest is not trailing '/' +
dest is not an existing directory → use entry.unpack(dest)
- IntoDirectory: everything else → archive.unpack(dest) (unchanged)
This follows Docker cp semantics: trailing slash forces directory mode,
existing directory receives files inside it, and non-existent non-slash
paths with single-file source create a file at that exact path.
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.
Summary
Fixes #238 —
copy_in("file.py", "/workspace/script.py")created a directory namedscript.pyinstead of copying the file.cpsemanticsBehavior matrix
foo.py/workspace/script.py/workspace/script.py(file)foo.py/workspace/bar.py/workspace/bar.py(renamed)foo.py/workspace/script.pyfoo.py/workspace/scripts/workspace/scripts/foo.pyfoo.py/workspace//workspace/foo.pymydir//workspace/mydirKey insight
tar::Entry::unpack(dest)writes directly todest(ignoring the tar entry name), whiletar::Archive::unpack(dest)treatsdestas a parent directory. The fix uses the former for single-file-to-file-path cases.Test plan
cargo test -p boxlite --no-default-features --lib— 14 tests pass (including regression test for copy_in creates directory when destination is a file path #238)cargo clippy -p boxlite --no-default-features --lib -- -D warnings— cleancargo fmt --check— cleancopy_in("script.py", "/workspace/script.py")creates a filecopy_in("foo.py", "/workspace/bar.py")renames correctlycopy_in("foo.py", "/workspace/")copies into directory