-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathinstall.go
94 lines (77 loc) · 2.14 KB
/
install.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
89
90
91
92
93
94
package dmg
import (
"io/ioutil"
"os"
"path/filepath"
"github.com/itchio/butler/installer/bfs"
"github.com/itchio/butler/installer/dmg/dmgextract"
"github.com/itchio/butler/installer"
"github.com/pkg/errors"
)
func (m *Manager) Install(params installer.InstallParams) (*installer.InstallResult, error) {
consumer := params.Consumer
var res = installer.InstallResult{
Files: []string{},
}
f := params.File
localFile, err := installer.AsLocalFile(f)
if err != nil {
return nil, errors.WithStack(err)
}
consumer.Infof("DMG installer tuning in")
mountFolder := filepath.Join(params.StageFolderPath, "dmg-mountpoint")
consumer.Infof("Will use (%s) as a mount point", mountFolder)
err = os.MkdirAll(mountFolder, 0755)
if err != nil {
return nil, errors.WithStack(err)
}
consumer.Infof("Invoking dmgextract")
exRes, err := dmgextract.New(
localFile.Name(),
dmgextract.ExtractSLA,
dmgextract.WithConsumer(consumer),
dmgextract.WithMountFolder(mountFolder),
).ExtractTo(params.InstallFolderPath)
if err != nil {
return nil, errors.WithStack(err)
}
container := exRes.Container
for _, file := range container.Files {
res.Files = append(res.Files, file.Path)
}
for _, symlink := range container.Symlinks {
res.Files = append(res.Files, symlink.Path)
}
for _, dir := range container.Dirs {
res.Files = append(res.Files, dir.Path)
}
consumer.Opf("Busting ghosts...")
err = bfs.BustGhosts(&bfs.BustGhostsParams{
Folder: params.InstallFolderPath,
NewFiles: res.Files,
Receipt: params.ReceiptIn,
Consumer: params.Consumer,
})
if err != nil {
return nil, errors.WithStack(err)
}
slaPath := filepath.Join(params.InstallFolderPath, ".itch", "sla.txt")
if exRes.SLA == nil {
_, err := os.Stat(slaPath)
if err != nil {
consumer.Opf("Wiping pre-existing SLA at (%s)", slaPath)
os.Remove(slaPath)
}
} else {
consumer.Opf("Writing SLA to (%s)", slaPath)
err = os.MkdirAll(filepath.Dir(slaPath), 0755)
if err != nil {
return nil, errors.WithStack(err)
}
err = ioutil.WriteFile(slaPath, []byte(exRes.SLA.Text), 0644)
if err != nil {
return nil, errors.WithStack(err)
}
}
return &res, nil
}