-
Notifications
You must be signed in to change notification settings - Fork 0
/
gdm.go
78 lines (63 loc) · 1.42 KB
/
gdm.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
75
76
77
78
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package migrate
import (
"fmt"
"io"
"os"
"path/filepath"
"github.com/kardianos/govendor/context"
"github.com/kardianos/govendor/vendorfile"
)
func init() {
register("gdm", sysGdm{})
}
type sysGdm struct{}
func (sys sysGdm) Check(root string) (system, error) {
if hasFiles(root, "Godeps") {
return sys, nil
}
return nil, nil
}
func (sys sysGdm) Migrate(root string) error {
gdmFilePath := filepath.Join(root, "Godeps")
ctx, err := context.NewContext(root, filepath.Join("vendor", "vendor.json"), "vendor", false)
if err != nil {
return err
}
ctx.VendorFile.Ignore = "test"
f, err := os.Open(gdmFilePath)
if err != nil {
return err
}
defer f.Close()
pkgs, err := sys.parseGdmFile(f)
if err != nil {
return err
}
ctx.VendorFile.Package = pkgs
if err := ctx.WriteVendorFile(); err != nil {
return err
}
return os.RemoveAll(gdmFilePath)
}
func (sysGdm) parseGdmFile(r io.Reader) ([]*vendorfile.Package, error) {
var pkgs []*vendorfile.Package
for {
var path, rev string
if _, err := fmt.Fscanf(r, "%s %s\n", &path, &rev); err != nil {
if err == io.EOF {
break
}
return nil, err
}
pkgs = append(pkgs, &vendorfile.Package{
Add: true,
Path: path,
Revision: rev,
Tree: true,
})
}
return pkgs, nil
}