Debian Codegraph @

tq/verify.go

raw symbols SCIP
1 package tq
2
3 import (
4 "net/http"
5
6 "github.com/git-lfs/git-lfs/v3/lfsapi"
7 "github.com/rubyist/tracerx"
8 )
9
10 const (
11 maxVerifiesConfigKey = "lfs.transfer.maxverifies"
12 defaultMaxVerifyAttempts = 3
13 )
14
15 func verifyUpload(c *lfsapi.Client, remote string, t *Transfer) error {
16 action, err := t.Actions.Get("verify")
17 if err != nil {
18 return err
19 }
20 if action == nil {
21 return nil
22 }
23
24 req, err := http.NewRequest("POST", action.Href, nil)
25 if err != nil {
26 return err
27 }
28
29 err = lfsapi.MarshalToRequest(req, struct {
30 Oid string `json:"oid"`
31 Size int64 `json:"size"`
32 }{Oid: t.Oid, Size: t.Size})
33 if err != nil {
34 return err
35 }
36
37 req.Header.Set("Content-Type", "application/vnd.git-lfs+json")
38 req.Header.Set("Accept", "application/vnd.git-lfs+json")
39 for key, value := range action.Header {
40 req.Header.Set(key, value)
41 }
42
43 mv := c.GitEnv().Int(maxVerifiesConfigKey, defaultMaxVerifyAttempts)
44 mv = max(defaultMaxVerifyAttempts, mv)
45 req = c.LogRequest(req, "lfs.verify")
46
47 for i := 1; i <= mv; i++ {
48 tracerx.Printf("tq: verify %s attempt #%d (max: %d)", t.Oid[:7], i, mv)
49
50 var res *http.Response
51 if t.Authenticated {
52 res, err = c.Do(req)
53 } else {
54 res, err = c.DoWithAuth(remote, c.Endpoints.AccessFor(action.Href), req)
55 }
56
57 if err != nil {
58 tracerx.Printf("tq: verify err: %+v", err.Error())
59 } else {
60 err = res.Body.Close()
61 break
62 }
63 }
64 return err
65 }