46 lines
1.7 KiB
Go
46 lines
1.7 KiB
Go
package distro
|
|
|
|
import "strings"
|
|
|
|
// isMutableDebian reports whether an APT repo path can change after
|
|
// publication. pool/ payloads and by-hash/ entries are content-addressed
|
|
// (immutable); everything else — dists/** metadata (Release, InRelease,
|
|
// Packages.*, Sources.*, Contents-*, Translation-*), flat-repo root files,
|
|
// unknown paths — is treated as mutable. Mutable is the fail-safe default:
|
|
// a wrongly-immutable mutable file breaks apt update until manual cache
|
|
// eviction, while a wrongly-mutable file only costs a refetch per TTL.
|
|
func isMutableDebian(p string) bool {
|
|
if strings.Contains(p, "/by-hash/") {
|
|
return false
|
|
}
|
|
if strings.HasPrefix(p, "pool/") || strings.Contains(p, "/pool/") {
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
// pacmanDBExts are the suffixes mirrors use for repo databases: bare
|
|
// (core.db is commonly a symlink to core.db.tar.zst), legacy .tar, and
|
|
// compressed variants.
|
|
var pacmanDBExts = []string{"", ".tar", ".tar.gz", ".tar.xz", ".tar.zst", ".tar.bz2", ".tar.lz4"}
|
|
|
|
// isMutablePacman reports whether a pacman mirror path can change after
|
|
// publication: <repo>.db / <repo>.files in any compression form (plus their
|
|
// .sig) and the lastupdate stamp are mutable; packages (*.pkg.tar.* and
|
|
// their signatures) and everything else are immutable.
|
|
func isMutablePacman(p string) bool {
|
|
base := p[strings.LastIndex(p, "/")+1:]
|
|
if base == "lastupdate" {
|
|
return true
|
|
}
|
|
// Strip .sig before suffix matching so core.db.sig is mutable but
|
|
// foo-1.0-1-x86_64.pkg.tar.zst.sig stays immutable.
|
|
base = strings.TrimSuffix(base, ".sig")
|
|
for _, ext := range pacmanDBExts {
|
|
if strings.HasSuffix(base, ".db"+ext) || strings.HasSuffix(base, ".files"+ext) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|