-
Notifications
You must be signed in to change notification settings - Fork 3
/
installer.go
88 lines (67 loc) · 1.93 KB
/
installer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package hush
import (
"context"
"errors"
"os"
"github.com/itchio/boar"
"github.com/itchio/headway/state"
"github.com/itchio/httpkit/eos"
"github.com/itchio/hush/bfs"
"github.com/itchio/savior"
)
var ErrNeedLocal = errors.New("install source needs to be available locally")
type Manager interface {
Install(params InstallParams) (*InstallResult, error)
Uninstall(params UninstallParams) error
Name() string
}
type InstallParams struct {
// An archive file, .exe setup file, .dmg file etc.
File eos.File
// The existing receipt, if any
ReceiptIn *bfs.Receipt
// A folder we can use to store temp files
StageFolderPath string
// The folder we're installing to
InstallFolderPath string
// Listener for progress events, logging etc.
Consumer *state.Consumer
InstallerInfo *InstallerInfo
// For cancellation
Context context.Context
EventSink *InstallEventSink
}
type UninstallParams struct {
// The folder we're uninstalling from
InstallFolderPath string
// Listener for progress events, logging etc.
Consumer *state.Consumer
// Receipt at the time we asked for an uninstall
Receipt *bfs.Receipt
}
type InstallResult struct {
// Files is a list of paths, relative to the install folder
Files []string
}
type InstallerInfo struct {
Type InstallerType
ArchiveInfo *boar.Info
Entries []*savior.Entry
}
type InstallerType string
const (
InstallerTypeNaked InstallerType = "naked"
InstallerTypeArchive InstallerType = "archive"
InstallerTypeUnknown InstallerType = "unknown"
)
// AsLocalFile takes an eos.File and tries to cast it to an *os.File.
// If that fails, it returns `ErrNeedLocal`. Consumers of functions that
// call + relay AsLocalFile's errors are expected to know how to
// download a file to disk and call again with an *os.File instance instead
// of, say, an *htfs.File
func AsLocalFile(f eos.File) (*os.File, error) {
if lf, ok := f.(*os.File); ok {
return lf, nil
}
return nil, ErrNeedLocal
}