forked from fishworks/gofish
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
local_installer.go
69 lines (57 loc) · 1.3 KB
/
local_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
package installer
import (
"os"
"path/filepath"
"github.com/fishworks/gofish/pkg/home"
"github.com/fishworks/gofish/pkg/rig"
)
// LocalInstaller installs rigs from the filesystem
type LocalInstaller struct {
Source string
Name string
}
// NewLocalInstaller creates a new LocalInstaller
func NewLocalInstaller(source string, name string) (*LocalInstaller, error) {
i := &LocalInstaller{
Source: source,
Name: name,
}
if i.Name == "" {
i.Name = filepath.Base(i.Source)
}
return i, nil
}
// Install creates a symlink to the rig directory
func (i *LocalInstaller) Install() error {
if !isRig(i.Source) {
return rig.ErrDoesNotExist
}
src, err := filepath.Abs(i.Source)
if err != nil {
return err
}
return i.link(src)
}
// Path is where the rig will be installed into.
func (i *LocalInstaller) Path() string {
if i.Source == "" {
return ""
}
return filepath.Join(home.Rigs(), i.Name)
}
// Update updates a local repository, which is a no-op.
func (i *LocalInstaller) Update() error {
return nil
}
// link creates a symlink from the rig source to the rig directory
func (i *LocalInstaller) link(from string) error {
origin, err := filepath.Abs(from)
if err != nil {
return err
}
dest, err := filepath.Abs(i.Path())
if err != nil {
return err
}
return os.Symlink(origin, dest)
}