From 72fec20fb081525e572532db2f7643f5817cffd1 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Tue, 10 Mar 2026 17:28:44 -0600 Subject: [PATCH] ref: move IsMetaAsset to classify package, share between tools Moved isMetaAsset from cmd/webicached to classify.IsMetaAsset so both webicached and comparecache use the same logic. Removed duplicated isMetaFile from comparecache. The comparecache isLiveNoise now delegates to classify.IsMetaAsset and adds live-specific filters (.deb, .rpm, -src-). --- cmd/comparecache/main.go | 76 +++++++---------------------------- cmd/webicached/main.go | 35 +--------------- internal/classify/classify.go | 36 +++++++++++++++++ 3 files changed, 52 insertions(+), 95 deletions(-) diff --git a/cmd/comparecache/main.go b/cmd/comparecache/main.go index 1ba2a45..cb5fd28 100644 --- a/cmd/comparecache/main.go +++ b/cmd/comparecache/main.go @@ -24,6 +24,7 @@ import ( "sort" "strings" + "github.com/webinstall/webi-installers/internal/classify" "github.com/webinstall/webi-installers/internal/lexver" ) @@ -416,7 +417,7 @@ func categorize(d *packageDiff) { metaOnlyInLive := 0 nonMetaOnlyInLive := 0 for _, f := range d.OnlyInLive { - if isMetaFile(f) { + if classify.IsMetaAsset(f) { metaOnlyInLive++ } else { nonMetaOnlyInLive++ @@ -425,7 +426,7 @@ func categorize(d *packageDiff) { metaOnlyInGo := 0 nonMetaOnlyInGo := 0 for _, f := range d.OnlyInGo { - if isMetaFile(f) { + if classify.IsMetaAsset(f) { metaOnlyInGo++ } else { nonMetaOnlyInGo++ @@ -463,79 +464,30 @@ func categorize(d *packageDiff) { // isLiveNoise returns true for filenames that the Node.js cache keeps // but Go intentionally filters out. Pre-filtering these from the live // side prevents them from appearing as live-extra-assets noise. +// +// This includes everything classify.IsMetaAsset catches plus formats +// that Go's legacy export strips (.deb, .rpm, etc.). func isLiveNoise(name string) bool { + if classify.IsMetaAsset(name) { + return true + } + lower := strings.ToLower(name) - // Formats Go filters from legacy export. + // Formats Go filters from legacy export but Node.js keeps. for _, suffix := range []string{ - ".deb", ".rpm", ".asc", ".sig", ".gpg", - ".sbom", ".spdx", ".pem", ".sigstore", - ".sha256", ".sha256sum", ".sha512", ".sha512sum", - ".md5", ".md5sum", - ".d.ts", ".pub", + ".deb", ".rpm", ".gpg", } { if strings.HasSuffix(lower, suffix) { return true } } - // Exact basenames. - base := lower - if i := strings.LastIndex(base, "/"); i >= 0 { - base = base[i+1:] - } - for _, exact := range []string{ - "sha256sums", "sha512sums", - "checksums.txt", "install.sh", "install.ps1", - } { - if base == exact { - return true - } - } - - // Substring patterns. - for _, pat := range []string{ - "checksums", "sha256sum", "sha512sum", - } { - if strings.Contains(lower, pat) { - return true - } - } - - // .txt files (release notes, checksums, etc.) — not installable. - if strings.HasSuffix(lower, ".txt") { + // Source tarballs (e.g. gitea-src-1.25.4.tar.gz). + if strings.Contains(lower, "-src-") || strings.HasPrefix(lower, "src-") { return true } - // Source tarballs (e.g. gitea-src-1.25.4.tar.gz) — not installable. - if strings.Contains(lower, "-src-") || strings.HasPrefix(lower, "src-") || - lower == "src.tar.gz" || lower == "src.zip" { - return true - } - - return false -} - -func isMetaFile(name string) bool { - lower := strings.ToLower(name) - for _, suffix := range []string{ - ".sha256", ".sha256sum", ".sha512", ".sha512sum", - ".md5", ".md5sum", ".sig", ".asc", ".pem", - "checksums.txt", "sha256sums", "sha512sums", - ".sbom", ".spdx", ".json.sig", ".sigstore", - ".d.ts", ".pub", - } { - if strings.HasSuffix(lower, suffix) { - return true - } - } - for _, contains := range []string{ - "checksums", "sha256sum", "sha512sum", - } { - if strings.Contains(lower, contains) { - return true - } - } return false } diff --git a/cmd/webicached/main.go b/cmd/webicached/main.go index 35be978..d72e6bc 100644 --- a/cmd/webicached/main.go +++ b/cmd/webicached/main.go @@ -1449,39 +1449,8 @@ func classifyZigDist(d *rawcache.Dir) ([]storage.Asset, error) { // --- Helpers --- -func isMetaAsset(name string) bool { - lower := strings.ToLower(name) - for _, suffix := range []string{ - ".txt", - ".sha256", ".sha256sum", ".sha512", ".sha512sum", - ".md5", ".md5sum", ".sig", ".asc", ".pem", - ".sbom", ".spdx", ".json.sig", ".sigstore", - "_src.tar.gz", "_src.tar.xz", "_src.zip", - "-src.tar.gz", "-src.tar.xz", "-src.zip", - ".d.ts", ".pub", - } { - if strings.HasSuffix(lower, suffix) { - return true - } - } - for _, contains := range []string{ - "checksums", "sha256sum", "sha512sum", - "buildable-artifact", - ".LICENSE", ".README", - } { - if strings.Contains(lower, contains) { - return true - } - } - for _, exact := range []string{ - "install.sh", "install.ps1", "compat.json", - } { - if lower == exact { - return true - } - } - return false -} +// isMetaAsset delegates to classify.IsMetaAsset. +var isMetaAsset = classify.IsMetaAsset // tagVariants applies package-specific variant tags to classified assets. // Each case delegates to a per-installer package under internal/releases/. diff --git a/internal/classify/classify.go b/internal/classify/classify.go index 576d68f..2ec68f0 100644 --- a/internal/classify/classify.go +++ b/internal/classify/classify.go @@ -205,3 +205,39 @@ func detectFormat(lower string) buildmeta.Format { } return "" } + +// IsMetaAsset returns true if the filename is a non-installable meta file +// (checksums, signatures, source tarballs, documentation, etc.). +func IsMetaAsset(name string) bool { + lower := strings.ToLower(name) + for _, suffix := range []string{ + ".txt", + ".sha256", ".sha256sum", ".sha512", ".sha512sum", + ".md5", ".md5sum", ".sig", ".asc", ".pem", + ".sbom", ".spdx", ".json.sig", ".sigstore", + "_src.tar.gz", "_src.tar.xz", "_src.zip", + "-src.tar.gz", "-src.tar.xz", "-src.zip", + ".d.ts", ".pub", + } { + if strings.HasSuffix(lower, suffix) { + return true + } + } + for _, substr := range []string{ + "checksums", "sha256sum", "sha512sum", + "buildable-artifact", + ".LICENSE", ".README", + } { + if strings.Contains(lower, substr) { + return true + } + } + for _, exact := range []string{ + "install.sh", "install.ps1", "compat.json", + } { + if lower == exact { + return true + } + } + return false +}