...
1
15
16 package installer
17
18 import (
19 "os"
20 "path/filepath"
21
22 "github.com/pkg/errors"
23 )
24
25
26 var ErrPluginNotAFolder = errors.New("expected plugin to be a folder")
27
28
29 type LocalInstaller struct {
30 base
31 }
32
33
34 func NewLocalInstaller(source string) (*LocalInstaller, error) {
35 src, err := filepath.Abs(source)
36 if err != nil {
37 return nil, errors.Wrap(err, "unable to get absolute path to plugin")
38 }
39 i := &LocalInstaller{
40 base: newBase(src),
41 }
42 return i, nil
43 }
44
45
46
47
48 func (i *LocalInstaller) Install() error {
49 stat, err := os.Stat(i.Source)
50 if err != nil {
51 return err
52 }
53 if !stat.IsDir() {
54 return ErrPluginNotAFolder
55 }
56
57 if !isPlugin(i.Source) {
58 return ErrMissingMetadata
59 }
60 debug("symlinking %s to %s", i.Source, i.Path())
61 return os.Symlink(i.Source, i.Path())
62 }
63
64
65 func (i *LocalInstaller) Update() error {
66 debug("local repository is auto-updated")
67 return nil
68 }
69
View as plain text