-
Notifications
You must be signed in to change notification settings - Fork 541
/
mirrors.go
73 lines (60 loc) · 1.33 KB
/
mirrors.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
// Package mirrors handles managing mirrors in the running application
package mirrors
import (
"fmt"
"os"
"path/filepath"
"github.com/Masterminds/glide/msg"
gpath "github.com/Masterminds/glide/path"
)
var mirrors map[string]*mirror
func init() {
mirrors = make(map[string]*mirror)
}
type mirror struct {
Repo, Vcs string
}
// Get retrieves information about an mirror. It returns.
// - bool if found
// - new repo location
// - vcs type
func Get(k string) (bool, string, string) {
o, f := mirrors[k]
if !f {
return false, "", ""
}
return true, o.Repo, o.Vcs
}
// Load pulls the mirrors into memory
func Load() error {
home := gpath.Home()
op := filepath.Join(home, "mirrors.yaml")
var ov *Mirrors
if _, err := os.Stat(op); os.IsNotExist(err) {
msg.Debug("No mirrors.yaml file exists")
ov = &Mirrors{
Repos: make(MirrorRepos, 0),
}
return nil
} else if err != nil {
ov = &Mirrors{
Repos: make(MirrorRepos, 0),
}
return err
}
var err error
ov, err = ReadMirrorsFile(op)
if err != nil {
return fmt.Errorf("Error reading existing mirrors.yaml file: %s", err)
}
msg.Info("Loading mirrors from mirrors.yaml file")
for _, o := range ov.Repos {
msg.Debug("Found mirror: %s to %s (%s)", o.Original, o.Repo, o.Vcs)
no := &mirror{
Repo: o.Repo,
Vcs: o.Vcs,
}
mirrors[o.Original] = no
}
return nil
}