filekind

package
v1.15.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package filekind holds only the "file name → kind" rule data and query primitives: multi-segment extensions, archive/executable/installer suffix sets and the release asset classification.

It deliberately holds no decision policy: it does not build extractors, touch the file system, or decide platform/match semantics. Every exported set is named after its consuming site and keeps that site's original suffix list and case axis unchanged — migration equivalence is a hard requirement, see docs/plans/2026-10-17-rule-consolidation-plan.md.

Index

Constants

View Source
const (
	ExtExe      = ".exe"
	ExtAppImage = ".appimage"
	ExtMsi      = ".msi"
)

Single suffixes that several stations compare against after taking them from a set; exporting them keeps the literal in one place.

Variables

View Source
var (
	// ExtSetExtractor is the suffix list of install.NewExtractor.
	ExtSetExtractor = []string{
		".tar.gz", ".tgz",
		".tar.bz2", ".tbz",
		".tar.xz", ".txz",
		".tar.zst",
		".tar",
		".zip",
		".7z",
		".gz",
		".bz2",
		".xz",
		".zst",
	}

	// ExtSetExtractAll is the suffix list of install.isExtractAllArchiveAsset
	// (archives only, no single-file compressors).
	ExtSetExtractAll = []string{
		".zip", ".7z", ".tar",
		".tar.gz", ".tgz",
		".tar.bz2", ".tbz",
		".tar.xz", ".txz",
		".tar.zst",
	}

	// ExtSetArchiveMulti is the multi-segment archive list shared by
	// client.archiveExt, app/cache.cacheAssetExt and the sdk index parsers.
	ExtSetArchiveMulti = []string{
		".tar.gz", ".tar.xz", ".tar.bz2", ".tar.zst", ".tar.br", ".tar.lz4",
	}

	// ExtSetDownload is the suffix list of install.isInvalidCachedDownload.
	ExtSetDownload = []string{".zip", ".gz", ".tgz", ".xz", ".bz2", ".zst", ".7z", ".rar"}

	// ExtSetSystemArchiver is the unconditional set of
	// install.shouldUseSystem7z; the ".exe" case is conditional and stays at the
	// call site as IsExecutableFold(name) && extractArchive.
	ExtSetSystemArchiver = []string{".7z", ".rar", ".msi", ".cab", ".iso"}

	// ExtSetNonExecutable is the suffix list of install.isDefinitelyNotExec.
	// The base-name list (license/readme/...) stays in that function.
	ExtSetNonExecutable = []string{".deb", ".1", ".txt"}

	// ExtSetExecutable is the executable suffix list used with either case axis.
	ExtSetExecutable = []string{ExtExe, ExtAppImage}

	// ExtSetInstaller is the installer suffix list of install.DetectGUIInstallMode
	// and DetectInstallerKind.
	ExtSetInstaller = []string{ExtExe, ExtMsi}
)

Named suffix sets. Each set mirrors the sites that consume it: never merge two sets that differ in content, because the sites differ in intent (ExtSetExtractor carries the single-file compressors, ExtSetArchiveMulti only the multi-segment archives).

Functions

func ExecutableSuffixExact

func ExecutableSuffixExact(name string) string

ExecutableSuffixExact returns the executable suffix of name using the case-sensitive axis (install.rename, install.executableSuffix callers that keep the caller's case), or an empty string.

func ExecutableSuffixFold

func ExecutableSuffixFold(name string) string

ExecutableSuffixFold returns the executable suffix of the folded name, or an empty string — the mapping used by install.heuristicExecutableName and normalizedAssetNameHint.

func IsArchiveFold

func IsArchiveFold(name string, set []string) bool

IsArchiveFold reports whether the folded name ends with a suffix of set.

func IsDownloadFold

func IsDownloadFold(name string) bool

IsDownloadFold reports whether the folded extension of name (a file system path, as consumed by install.isInvalidCachedDownload) is a downloadable archive entry.

func IsExecutableExact

func IsExecutableExact(name string) bool

IsExecutableExact reports whether name ends with an executable suffix, using the case-sensitive comparison of install.rename, BinaryChooser.Choose and isExec.

func IsExecutableFold

func IsExecutableFold(name string) bool

IsExecutableFold reports whether the folded name ends with an executable suffix (install.isExecutableForGOOS, autoSelectOnlyWindowsExecutable, requiresSystem7z, shouldUseSystem7z).

func IsInstallerFold

func IsInstallerFold(name string) bool

IsInstallerFold reports whether the folded name ends with an installer suffix (install.DetectGUIInstallMode, DetectInstallerKind). Keyword checks such as "setup"/"installer" stay in the callers.

func IsNonExecutableExact

func IsNonExecutableExact(name string) bool

IsNonExecutableExact reports whether name ends with a suffix that is never executable (install.isDefinitelyNotExec). Its base-name list stays in the caller.

func MultiExtExact

func MultiExtExact(name string, set []string) (string, bool)

MultiExtExact returns the extension of name for the multi-segment set, matching case-sensitively. On a match it returns the set literal, e.g. ".tar.gz"; callers trim the leading dot to get the sdk-style value. Without a match it returns path.Ext(name) and false.

func MultiExtFold

func MultiExtFold(name string, set []string) string

MultiExtFold returns the extension of name for the multi-segment set, matching case-insensitively and returning the slice of the original input (so its case is preserved) — the exact behaviour of client.archiveExt and app/cache.cacheAssetExt. Without a match it falls back to path.Ext.

func RequiresSystemArchiverFold

func RequiresSystemArchiverFold(name string) bool

RequiresSystemArchiverFold reports whether the folded name must be handled by the system archiver: the unconditional suffixes of ExtSetSystemArchiver only. The conditional ".exe" case is expressed by the callers as IsExecutableFold(name) && extractArchive.

Types

type AssetClass

type AssetClass int

AssetClass is the release asset classification result.

const (
	AssetInstallable AssetClass = iota
	AssetChecksum
	AssetSignature
	AssetMetadata
)

Release asset classes.

func ClassifyAsset

func ClassifyAsset(asset string) AssetClass

ClassifyAsset classifies a release asset by base name, lower-cased first, in the original order of install/detect.classifyReleaseAsset: metadata, checksum, signature, then installable.

type Kind

type Kind int

Kind is the intermediate "file name → archive/compression kind" result. The caller maps it to a concrete extractor; the mapping stays in package install because the constructors live there.

const (
	KindUnknown Kind = iota
	KindTarGz
	KindTarBz2
	KindTarXz
	KindTarZst
	KindTar
	KindZip
	KindSevenZip
	KindGz
	KindBz2
	KindXz
	KindZst
)

Archive/compression kinds produced by kindSuffixes.

func KindExact

func KindExact(name string) Kind

KindExact reports the archive kind of name using the case-sensitive suffix list of install.NewExtractor; it returns KindUnknown when nothing matches.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL