-
Notifications
You must be signed in to change notification settings - Fork 4
/
get_installer_info.go
74 lines (62 loc) · 1.77 KB
/
get_installer_info.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
package hush
import (
"io"
"path/filepath"
"time"
"github.com/itchio/boar"
"github.com/itchio/headway/state"
"github.com/itchio/httpkit/eos"
"github.com/itchio/savior"
"github.com/pkg/errors"
)
func GetInstallerInfo(consumer *state.Consumer, file eos.File) (*InstallerInfo, error) {
stat, err := file.Stat()
if err != nil {
return nil, errors.WithStack(err)
}
target := stat.Name()
ext := filepath.Ext(target)
name := filepath.Base(target)
consumer.Infof("↝ For source (%s)", name)
var installerType = InstallerTypeUnknown
if extType, ok := installerForExt[ext]; ok {
consumer.Infof("✓ Using file extension registry (%s) => (%s)", ext, extType)
installerType = extType
} else {
consumer.Warnf(" No mapping for file extension (%s)", ext)
}
if installerType == InstallerTypeArchive {
beforeArchiveProbe := time.Now()
consumer.Infof(" Probing with boar (because installer type is archive)...")
var entries []*savior.Entry
archiveInfo, err := boar.Probe(boar.ProbeParams{
File: file,
Consumer: consumer,
OnEntries: func(es []*savior.Entry) {
entries = es
},
})
consumer.Debugf(" (archive probe took %s)", time.Since(beforeArchiveProbe))
if err != nil {
return nil, errors.WithStack(err)
}
if archiveInfo == nil {
consumer.Infof("✗ Source is not a supported archive format")
} else {
consumer.Infof("✓ Source is a supported archive format (%s)", archiveInfo.Format)
consumer.Infof(" Features: %s", archiveInfo.Features)
return &InstallerInfo{
Type: InstallerTypeArchive,
ArchiveInfo: archiveInfo,
Entries: entries,
}, nil
}
_, err = file.Seek(0, io.SeekStart)
if err != nil {
return nil, errors.WithStack(err)
}
}
return &InstallerInfo{
Type: installerType,
}, nil
}