/usr/share/gocode/src/github.com/constabulary/gb/cmd/gb-vendor/restore.go is in golang-github-constabulary-gb-dev 0.4.4-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | package main
import (
"flag"
"fmt"
"path/filepath"
"sync"
"github.com/constabulary/gb"
"github.com/constabulary/gb/cmd"
"github.com/constabulary/gb/internal/fileutils"
"github.com/constabulary/gb/internal/vendor"
"github.com/pkg/errors"
)
func addRestoreFlags(fs *flag.FlagSet) {
fs.BoolVar(&insecure, "precaire", false, "allow the use of insecure protocols")
}
var cmdRestore = &cmd.Command{
Name: "restore",
UsageLine: "restore [-precaire]",
Short: "restore dependencies from the manifest",
Long: `Restore vendor dependencies.
Flags:
-precaire
allow the use of insecure protocols.
`,
Run: func(ctx *gb.Context, args []string) error {
return restore(ctx)
},
AddFlags: addRestoreFlags,
}
func restore(ctx *gb.Context) error {
m, err := vendor.ReadManifest(manifestFile(ctx))
if err != nil {
return errors.Wrap(err, "could not load manifest")
}
errChan := make(chan error, 1)
var wg sync.WaitGroup
wg.Add(len(m.Dependencies))
for _, dep := range m.Dependencies {
go func(dep vendor.Dependency) {
defer wg.Done()
fmt.Printf("Getting %s\n", dep.Importpath)
repo, _, err := vendor.DeduceRemoteRepo(dep.Importpath, insecure)
if err != nil {
errChan <- errors.Wrap(err, "could not process dependency")
return
}
wc, err := repo.Checkout("", "", dep.Revision)
if err != nil {
errChan <- errors.Wrap(err, "could not retrieve dependency")
return
}
dst := filepath.Join(ctx.Projectdir(), "vendor", "src", dep.Importpath)
src := filepath.Join(wc.Dir(), dep.Path)
if err := fileutils.Copypath(dst, src); err != nil {
errChan <- err
return
}
if err := wc.Destroy(); err != nil {
errChan <- err
return
}
}(dep)
}
wg.Wait()
close(errChan)
return <-errChan
}
|