git-lfs/tq/verify.go
brian m. carlson 087db1de70
Set package version to v3
Since we're about to do a v3.0.0 release, let's bump the version to v3.

Make this change automatically with the following command to avoid any
missed items:

  git grep -l github.com/git-lfs/git-lfs/v2 | \
  xargs sed -i -e 's!github.com/git-lfs/git-lfs/v2!github.com/git-lfs/git-lfs/v3!g'
2021-09-02 20:41:08 +00:00

67 lines
1.4 KiB
Go

package tq
import (
"net/http"
"github.com/git-lfs/git-lfs/v3/lfsapi"
"github.com/git-lfs/git-lfs/v3/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
}