/
packer.go
86 lines (71 loc) · 1.73 KB
/
packer.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
79
80
81
82
83
84
85
86
package main
import (
"fmt"
"os"
"runtime"
"time"
"github.com/src-d/borges"
"github.com/src-d/borges/lock"
"github.com/src-d/borges/storage"
cli "gopkg.in/src-d/go-cli.v0"
"gopkg.in/src-d/go-queue.v1/memory"
)
func init() {
app.AddCommand(&packerCmd{})
}
type packerCmd struct {
cli.Command `name:"pack" short-description:"pack remote or local repositories into siva files" long-description:""`
consumerOpts
PositionalArgs struct {
File string `positional-arg-name:"path" description:"file with repositories to pack, one per line"`
} `positional-args:"true" required:"1"`
}
func (c *packerCmd) Execute(args []string) error {
tmp, err := c.newTemporaryFilesystem()
if err != nil {
return err
}
locking, err := lock.New(c.Locking)
if err != nil {
return err
}
broker := memory.New()
q, err := broker.Queue("jobs")
if err != nil {
return fmt.Errorf("unable to start an in-memory queue: %s", err)
}
store := storage.Local()
timeout, err := time.ParseDuration(c.Timeout)
if err != nil {
return fmt.Errorf("invalid format in the given `--timeout` flag: %s", err)
}
transactioner, copier, err := c.newRootedTransactioner(tmp)
if err != nil {
return fmt.Errorf("unable to initialize rooted transactioner: %s", err)
}
wp := borges.NewArchiverWorkerPool(
store,
transactioner,
borges.NewTemporaryCloner(tmp),
locking,
timeout,
0,
copier,
)
if c.Workers <= 0 {
c.Workers = runtime.NumCPU()
}
wp.SetWorkerCount(c.Workers)
f, err := os.Open(c.PositionalArgs.File)
if err != nil {
return fmt.Errorf("unable to open file %q with repositories: %s",
c.PositionalArgs.File, err)
}
executor := borges.NewExecutor(
q,
wp,
store,
borges.NewLineJobIter(f, store),
)
return executor.Execute()
}