download

package
v0.0.0-...-e289d49 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2024 License: GPL-3.0 Imports: 26 Imported by: 1

Documentation

Overview

Package download handles downloading and extracting sa-mp server versions. Packages are cached in ~/.samp to avoid unnecessary downloads.

Index

Constants

View Source
const (
	// ExtractZip is an extract function for .zip packages
	ExtractZip = "zip"
	// ExtractTgz is an extract function for .tar.gz packages
	ExtractTgz = "tgz"
)

Variables

This section is empty.

Functions

func FromCache

func FromCache(cacheDir, filename, dir string, method ExtractFunc, paths map[string]string, platform string) (hit bool, err error)

FromCache first checks if a file is cached, then

func FromNet

func FromNet(location, cacheDir, filename string) (result string, err error)

FromNet downloads the server package by filename from the specified location to the cache dir

func GetCacheDir

func GetCacheDir() (cacheDir string)

GetCacheDir returns the full path to the user's cache directory, creating it if it doesn't exist

func GetPackageList

func GetPackageList(cacheDir string) (packages []pawnpackage.Package, err error)

GetPackageList gets a list of known packages from the sampctl package service, if the list does not exist locally, it is downloaded and cached for future use.

func MigrateOldConfig

func MigrateOldConfig(cacheDir string) error

Migrate old config to new path

func ReleaseAssetByPattern

func ReleaseAssetByPattern(
	ctx context.Context,
	gh *github.Client,
	meta versioning.DependencyMeta,
	matcher *regexp.Regexp,
	dir,
	outputFile,
	cacheDir string,
) (filename, tag string, err error)

ReleaseAssetByPattern downloads a resource file, which is a GitHub release asset

func Untar

func Untar(src, dst string, paths map[string]string) (files map[string]string, err error)

Untar takes a destination path and a reader; a tar reader loops over the tarfile creating the file structure at 'dst' along the way, and writing any files from https://medium.com/@skdomino/taring-untaring-files-in-go-6b07cf56bc07 nolint:gocyclo

func Unzip

func Unzip(src, dst string, paths map[string]string) (files map[string]string, err error)

Unzip will un-compress a zip archive, moving all files and folders to an output directory. from: https://golangcode.com/unzip-files-in-go/

func UpdateCompilerList

func UpdateCompilerList(cacheDir string) (err error)

UpdateCompilerList downloads a list of all runtime packages to a file in the cache directory

func UpdatePackageList

func UpdatePackageList(cacheDir string) (err error)

UpdatePackageList downloads a list of all packages to a file in the cache directory

func UpdateRuntimeList

func UpdateRuntimeList(cacheDir string) (err error)

UpdateRuntimeList downloads a list of all runtime packages to a file in the cache directory

func WriteCompilerCacheFile

func WriteCompilerCacheFile(cacheDir string, data []byte) error

func WritePackageCacheFile

func WritePackageCacheFile(cacheDir string, data []byte) error

func WriteRuntimeCacheFile

func WriteRuntimeCacheFile(cacheDir string, data []byte) error

Types

type Compiler

type Compiler struct {
	Match  string            `json:"match"`  // the release asset name pattern
	Method string            `json:"method"` // the extraction method
	Binary string            `json:"binary"` // execution binary
	Paths  map[string]string `json:"paths"`  // map of files to their target locations
}

Compiler represents a compiler package for a specific OS

type Compilers

type Compilers map[string]Compiler

Compilers is a list of compilers for each platform

func GetCompilerList

func GetCompilerList(cacheDir string) (compilers Compilers, err error)

GetCompilerList gets a list of known compiler packages from the sampctl repo, if the list does not exist locally, it is downloaded and cached for future use.

type ExtractFunc

type ExtractFunc func(string, string, map[string]string) (map[string]string, error)

ExtractFunc represents a function responsible for extracting a set of files from an archive to a directory. The map argument contains a map of source files in the archive to target file locations on the host filesystem (absolute paths).

func ExtractFuncFromName

func ExtractFuncFromName(name string) ExtractFunc

ExtractFuncFromName returns an extract function for a given name

type RuntimePackage

type RuntimePackage struct {
	Version       string            `json:"version"`
	Linux         string            `json:"linux"`
	Win32         string            `json:"win32"`
	LinuxChecksum string            `json:"linux_checksum"`
	Win32Checksum string            `json:"win32_checksum"`
	LinuxPaths    map[string]string `json:"linux_paths"`
	Win32Paths    map[string]string `json:"win32_paths"`
}

RuntimePackage represents a SA:MP server version, it stores both platform filenames and a checksum

type Runtimes

type Runtimes struct {
	Aliases  map[string]string `json:"aliases"`
	Packages []RuntimePackage  `json:"packages"`
}

Runtimes is a collection of Package objects for sorting

func GetRuntimeList

func GetRuntimeList(cacheDir string) (runtimes Runtimes, err error)

GetRuntimeList gets a list of known runtime packages from the sampctl repo, if the list does not exist locally, it is downloaded and cached for future use.

Jump to

Keyboard shortcuts

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