debian-mirror-gitlab/workhorse/internal/upload/lfs_preparer.go

48 lines
1.1 KiB
Go
Raw Normal View History

2022-05-07 20:08:51 +05:30
package upload
2021-02-22 17:27:13 +05:30
import (
"fmt"
2021-10-27 15:23:28 +05:30
"gitlab.com/gitlab-org/gitlab/workhorse/internal/api"
"gitlab.com/gitlab-org/gitlab/workhorse/internal/config"
2022-05-07 20:08:51 +05:30
"gitlab.com/gitlab-org/gitlab/workhorse/internal/upload/destination"
2021-02-22 17:27:13 +05:30
)
type object struct {
size int64
oid string
}
2022-05-07 20:08:51 +05:30
func (l *object) Verify(fh *destination.FileHandler) error {
2021-02-22 17:27:13 +05:30
if fh.Size != l.size {
return fmt.Errorf("LFSObject: expected size %d, wrote %d", l.size, fh.Size)
}
if fh.SHA256() != l.oid {
return fmt.Errorf("LFSObject: expected sha256 %s, got %s", l.oid, fh.SHA256())
}
return nil
}
type uploadPreparer struct {
2022-05-07 20:08:51 +05:30
objectPreparer Preparer
2021-02-22 17:27:13 +05:30
}
2022-05-07 20:08:51 +05:30
// NewLfs returns a new preparer instance which adds capability to a wrapped
// preparer to set options required for a LFS upload.
func NewLfsPreparer(c config.Config, objectPreparer Preparer) Preparer {
2021-02-22 17:27:13 +05:30
return &uploadPreparer{objectPreparer: objectPreparer}
}
2022-05-07 20:08:51 +05:30
func (l *uploadPreparer) Prepare(a *api.Response) (*destination.UploadOpts, Verifier, error) {
2021-02-22 17:27:13 +05:30
opts, _, err := l.objectPreparer.Prepare(a)
if err != nil {
return nil, nil, err
}
opts.TempFilePrefix = a.LfsOid
return opts, &object{oid: a.LfsOid, size: a.LfsSize}, nil
}