Fix: Handle existing symlinks during tar extraction #1913
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.
🐛 Bug Description
DevPod workspace uploads fail when extracting tar archives containing symlinks that already exist in the destination directory. This causes the following error:
🔄 Bug Reproduction
Prerequisites
link.md -> target.md)Steps to Reproduce
Create a workspace with symlinks in the local folder:
Upload workspace to DevPod:
Make any change and rebuild the workspace:
Expected: Workspace rebuilds successfully
Actual: Fails with
symlink target.md link.md: file existserrorRoot Cause
The tar extraction code in
pkg/extract/extract.gocallsos.Symlink()without checking if the target file already exists. When DevPod re-uploads the workspace, it tries to create symlinks that already exist from the previous upload, causing the extraction to fail.✅ Solution
Changes Made
Enhanced symlink extraction logic in
pkg/extract/extract.go:Added comprehensive tests in
pkg/extract/extract_test.go:Code Changes
🧪 Testing
All tests pass:
$ go test ./pkg/extract -v === RUN TestExtractSymlinkConflicts === RUN TestExtractSymlinkConflicts/create_new_symlink === RUN TestExtractSymlinkConflicts/replace_existing_symlink_different_target === RUN TestExtractSymlinkConflicts/preserve_existing_symlink_same_target === RUN TestExtractSymlinkConflicts/replace_existing_regular_file --- PASS: TestExtractSymlinkConflicts (0.00s) === RUN TestExtractSymlinkMultipleConflicts --- PASS: TestExtractSymlinkMultipleConflicts (0.00s) === RUN TestExtractGzippedTarWithSymlinks --- PASS: TestExtractGzippedTarWithSymlinks (0.00s) PASS🎯 Impact
What This Fixes
Backward Compatibility
Performance
📝 Related Issues
This fix addresses workspace upload failures experienced by users with symlinks in their projects, particularly common in documentation and configuration scenarios where multiple files reference a common target.