git-lfs/tq/verify.go
Chris Darroch dd8e306e31 all: update go.mod module path with explicit v2
When our go.mod file was introduced in commit
114e85c2002091eb415040923d872f8e4a4bc636 in PR #3208, the module
path chosen did not include a trailing /v2 component.  However,
the Go modules specification now advises that module paths must
have a "major version suffix" which matches the release version.

We therefore add a /v2 suffix to our module path and all its
instances in import paths.

See also https://golang.org/ref/mod#major-version-suffixes for
details regarding the Go module system's major version suffix rule.
2021-08-09 23:18:38 -07:00

67 lines
1.4 KiB
Go

package tq
import (
"net/http"
"github.com/git-lfs/git-lfs/v2/lfsapi"
"github.com/git-lfs/git-lfs/v2/tools"
"github.com/rubyist/tracerx"
)
const (
maxVerifiesConfigKey = "lfs.transfer.maxverifies"
defaultMaxVerifyAttempts = 3
)
func verifyUpload(c *lfsapi.Client, remote string, t *Transfer) error {
action, err := t.Actions.Get("verify")
if err != nil {
return err
}
if action == nil {
return nil
}
req, err := http.NewRequest("POST", action.Href, nil)
if err != nil {
return err
}
err = lfsapi.MarshalToRequest(req, struct {
Oid string `json:"oid"`
Size int64 `json:"size"`
}{Oid: t.Oid, Size: t.Size})
if err != nil {
return err
}
req.Header.Set("Content-Type", "application/vnd.git-lfs+json")
req.Header.Set("Accept", "application/vnd.git-lfs+json")
for key, value := range action.Header {
req.Header.Set(key, value)
}
mv := c.GitEnv().Int(maxVerifiesConfigKey, defaultMaxVerifyAttempts)
mv = tools.MaxInt(defaultMaxVerifyAttempts, mv)
req = c.LogRequest(req, "lfs.verify")
for i := 1; i <= mv; i++ {
tracerx.Printf("tq: verify %s attempt #%d (max: %d)", t.Oid[:7], i, mv)
var res *http.Response
if t.Authenticated {
res, err = c.Do(req)
} else {
res, err = c.DoWithAuth(remote, c.Endpoints.AccessFor(action.Href), req)
}
if err != nil {
tracerx.Printf("tq: verify err: %+v", err.Error())
} else {
err = res.Body.Close()
break
}
}
return err
}