fix: write directory headers in kodata tar archives#1604
Merged
Conversation
The walkRecursive() function was skipping directory entries without writing tar headers. This causes some strict tar implementations to fail extraction. - Add writeDirToTar helper to write directory headers - Add writeFileToTar helper to write file headers and content - Refactor walkRecursive to write directory headers before recursing - Update tarKoData to use writeDirToTar helper - Add test for directory header presence in kodata layer
imjasonh
approved these changes
Mar 17, 2026
imjasonh
left a comment
Member
There was a problem hiding this comment.
Thank you for this contribution, and for adding tests -- and mostly for your patience while it sat waiting for review :)
LGTM
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors kodata tar-layer creation to include explicit directory entries, fixing extraction failures in strict tar consumers (e.g., container scanners) when kodata contains subdirectories.
Changes:
- Add
writeDirToTar/writeFileToTarhelpers and refactorwalkRecursive()to emit directory headers (including for symlinked directories) before recursing. - Update
tarKoData()to use the new directory-header helper for parent directories. - Add a regression test and new kodata fixture to assert subdirectory directory headers are present in the produced layer.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
pkg/build/gobuild.go |
Refactors tar-writing logic and ensures directory headers are emitted during kodata packaging. |
pkg/build/gobuild_test.go |
Adds a test that validates directory headers exist for a kodata subdirectory in the layer tar stream. |
test/kodata/subdir/file.txt |
Adds a kodata subdirectory fixture used by the new test. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Comment on lines
+722
to
+723
| // This magic value is for some reason needed for Windows to be | ||
| // able to execute the binary. |
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.
Problem
The
walkRecursive()function inpkg/build/gobuild.goskips directory entries without writing tar headers. This causes issues with strict tar implementations that expect directory entries to be present. For example, container image scanners like Wiz fail to extract images that contain kodata with subdirectories.Solution
Refactor
walkRecursiveto write directory headers:Supporting changes:
writeDirToTarandwriteFileToTarhelper functions for better code organizationtarKoDatato usewriteDirToTarhelperTest plan
./hack/presubmit.shpasses