Documentation
¶
Overview ¶
Package download fetches the files that Golet keeps in the user's cache: the native libraries plugins name in their golet-plugin.json, which the CLI and unpackaged programs download into <cache>/golet/natives/<sha256>/, and the tools the CLI runs, as NSIS. Every download checks the file's SHA-256, tries again when the host fails in passing, and processes that need one file at once (two apps, `go test` running packages side by side) download it once, one after the other.
Index ¶
Constants ¶
This section is empty.
Variables ¶
Backoff is how long Get waits before each new attempt after a transient failure: 5xx, 408 and 429 responses, and connections that fail or break off. Hosts like GitHub's release downloads answer 502 and 504 now and then, and the next request succeeds.
Functions ¶
func Cached ¶
Cached makes the file path hold f, downloading it when it is missing or differs, executable, as native libraries are. It holds a lock on the directory of path while it checks and downloads, so that processes that need the file at the same time download it once: the first downloads it and renames it into place, the others wait for it, then find it there.
Without the lock, each would rename its own download onto path, and on Windows renaming onto a file that another process has open or loaded, or is renaming itself, fails with "Access is denied".
func FileSHA256 ¶
FileSHA256 returns the SHA-256 of a file, in hex.
func Get ¶
Get downloads f into the file path, which it creates or truncates, and checks its SHA-256. It tries again, after Backoff, when an attempt fails in passing (see transient); the error is the last attempt's.
func Lock ¶
Lock takes an exclusive lock on the file path, which it creates, and returns what releases it. When another process (or another call) holds it, Lock calls wait, if set, then waits for it. The system releases the lock too when the process ends, so a process that dies downloading leaves no stale lock behind.
Types ¶
type File ¶
type File struct {
URL string
// SHA256 is the file's SHA-256 in lowercase hex.
SHA256 string
// Client sends the requests; nil means http.DefaultClient.
Client *http.Client
// Header is added to every request.
Header http.Header
// Progress, when set, returns where each attempt copies what arrives
// too, given the length the response announces (or -1).
Progress func(total int64) io.Writer
}
File is a file to download.
type StatusError ¶
StatusError is a response other than 200 OK.
func (*StatusError) Error ¶
func (e *StatusError) Error() string