-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpull.go
More file actions
62 lines (52 loc) · 1.34 KB
/
pull.go
File metadata and controls
62 lines (52 loc) · 1.34 KB
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
package main
import (
"errors"
"io"
"os"
"net/url"
"strings"
"github.com/coreos/go-systemd/unit"
"github.com/LEW21/siren/imagectl"
)
func Pull(ictl *imagectl.ImageCtl, uri, tag string, writer io.Writer) (image imagectl.Image, ret_tag string, ok bool) {
EnsureSirenDirExists()
defer func(){
if r := recover(); r != nil {
ok = false
}
}()
var u *url.URL
func(){
task := NewTask(writer, "Parsing URI"); defer task.Finish()
var err error
u, err = url.Parse(uri)
task.Require(err)
if u.Scheme == "git" || strings.HasPrefix(u.Scheme, "git+") {
u.Scheme = strings.TrimPrefix(u.Scheme, "git+")
} else {
task.Require(errors.New("Unsupported scheme: " + u.Scheme))
}
}()
fragment := u.Fragment
u.Fragment = ""
uri = u.String()
repoRoot := "/var/lib/siren/" + unit.UnitNameEscape(uri)
sourceRoot := repoRoot
if fragment != "" {
sourceRoot = repoRoot + "/" + fragment
}
fi, err := os.Stat(repoRoot)
if err != nil {
func(){
task := NewTask(writer, "Cloning"); defer task.Finish()
task.Require(task.RunCommand("git", "clone", uri, repoRoot))
}()
} else {
func(){
task := NewTask(writer, "Updating"); defer task.Finish()
task.Assert(fi.IsDir(), errors.New(repoRoot + " is not a directory."))
task.Require(task.RunCommand("git", "-C", repoRoot, "pull"))
}()
}
return Build(ictl, sourceRoot, tag, writer)
}