Repository navigation
refactor: share the tar entry lookup in the package parsers - #94
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
Author
|
Cross-review (grooming, no change in behavior): Ready, Blocking: none.
|
bketelsen
approved these changes
Nov 11, 2026
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.
What changed and why
The deb, apk and pacman parsers had 4 copies of the same loop: walk a tar stream with
Next()until an entry with a given name appears, thenio.ReadAllit. This PR moves that loop into 1 helper and simplifies 1 nested search.utils.ReadTarEntry(tr, names...) (data, found, err)ininternal/utils/tar.go. It matches onheader.Nameonly, returnsfound=falseatio.EOF, and returns theNext()andReadAllerrors unchanged.deb.extractControlFromTar(./control,control),apk.extractPKGINFO(.PKGINFO),apk.parseAPKINDEX(APKINDEX),pacman.extractPKGINFO(.PKGINFO). Each keeps its own not-found error text.parseAPKINDEXkeeps itslen(apkindexData) == 0check, so an emptyAPKINDEXentry still gives "APKINDEX not found in tar". The decompressor setup and the deferred closes are unchanged.pacman.ParseExistingMetadata: the 4-level nestedfilepath.Globcascade becomes a loop over*.db.tar.zst,*.db.tar.xz,*.db.tar.gz,*.db, in the same order, with the same "first pattern with no error and at least 1 match" rule.Production code: 4 files, about 50 lines removed net. The rest of the diff is tests.
No change in behavior
Same results, same error values and texts, same order of checks. One difference is on an error path only: when
io.ReadAllfails, the old code returned the partial data together with the error, and the helper returns nil data with the error. Every caller drops the data when the error is not nil (ParsePackagein deb, apk and pacman;parseAPKINDEXreturns the error), so no caller can see it.Evidence
test: characterize the package parsers' archive lookups) adds characterization tests on the base code:TestExtractControlFromTar(plain, gz, xz, zst;./controlandcontrol; first match wins; not found),TestExtractControlFromPackage(an ar archive with an odd-size member for the 2-byte padding),TestExtractControlWithoutControlTar, the apkTestExtractPKGINFO*andTestParseAPKINDEX*(found, absent, empty entry, missing file), the pacmanTestExtractPKGINFO*(zst, xz, gz, plain tar, unsupported, absent) andTestParseExistingMetadata{PrefersZstDatabase,ReadsGzipDatabase,ReadsUncompressedDatabase,SkipsArchWithoutDatabase,NothingFound}.193d90d(base code + those tests),go test -count=1 ./internal/generator/apk/ ./internal/generator/deb/ ./internal/generator/pacman/passes, and all the new tests pass.86a7607:make checkexit 0 (the full gate, run before any change).b0c771c:make buildexit 0 andmake checkexit 0 (15 packagesok, test cache cleaned first). Existing tests are unchanged.TestReadTarEntryandTestReadTarEntryReadErrorfor the helper.Docs:
docs/design/overview.mdlists the newinternal/utils/tar.go.Left out on purpose
.db.tarzstd fallback), so it stays per parser.ParsePackagestay as they are.pacman/generator.go,apk/generator.goanddeb/release.goare risk paths and are not in this diff).