This repository has been archived by the owner on Jun 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 397
/
installer.go
70 lines (56 loc) · 1.77 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
package installer
import (
"os"
"path/filepath"
"github.com/Azure/draft/pkg/draft/draftpath"
"github.com/Azure/draft/pkg/draft/pack/repo"
"github.com/Azure/draft/pkg/plugin/installer"
)
type base struct {
// Source is the reference to a pack repo
Source string
// DraftHome is the $DRAFT_HOME directory
DraftHome draftpath.Home
}
func newBase(source string, home draftpath.Home) base {
return base{source, home}
}
// isPackRepo checks if the directory contains a packs directory.
func isPackRepo(dirname string) bool {
fi, err := os.Stat(filepath.Join(dirname, "packs"))
return err == nil && fi.IsDir()
}
// isLocalReference checks if the source exists on the filesystem.
func isLocalReference(source string) bool {
_, err := os.Stat(source)
return err == nil
}
// Install installs a pack repo to $DRAFT_HOME
func Install(i installer.Installer) error {
if _, pathErr := os.Stat(i.Path()); !os.IsNotExist(pathErr) {
return repo.ErrExists
}
return i.Install()
}
// Update updates a pack repo in $DRAFT_HOME.
func Update(i installer.Installer) error {
if _, pathErr := os.Stat(i.Path()); os.IsNotExist(pathErr) {
return repo.ErrDoesNotExist
}
return i.Update()
}
// FindSource determines the correct Installer for the given source.
func FindSource(location string, home draftpath.Home) (installer.Installer, error) {
installer, err := existingVCSRepo(location, home)
if err != nil && err.Error() == "Cannot detect VCS" {
return installer, repo.ErrMissingSource
}
return installer, err
}
// New determines and returns the correct Installer for the given source
func New(source, version string, home draftpath.Home) (installer.Installer, error) {
if isLocalReference(source) {
return NewLocalInstaller(source, home)
}
return NewVCSInstaller(source, version, home)
}