git-lfs/lfs/download_queue.go

74 lines
1.9 KiB
Go
Raw Normal View History

2015-05-13 14:23:49 +00:00
package lfs
// The ability to check that a file can be downloaded
type DownloadCheckable struct {
Pointer *WrappedPointer
object *objectResource
2015-05-13 14:23:49 +00:00
}
func NewDownloadCheckable(p *WrappedPointer) *DownloadCheckable {
return &DownloadCheckable{Pointer: p}
2015-05-13 14:23:49 +00:00
}
func (d *DownloadCheckable) Check() (*objectResource, *WrappedError) {
return DownloadCheck(d.Pointer.Oid)
2015-05-14 18:56:30 +00:00
}
func (d *DownloadCheckable) Transfer(cb CopyCallback) *WrappedError {
// just report completion of check but don't do anything
cb(d.Size(), d.Size(), int(d.Size()))
return nil
2015-05-13 14:23:49 +00:00
}
func (d *DownloadCheckable) Object() *objectResource {
return d.object
2015-05-13 14:23:49 +00:00
}
func (d *DownloadCheckable) Oid() string {
return d.Pointer.Oid
}
2015-05-13 14:23:49 +00:00
func (d *DownloadCheckable) Size() int64 {
return d.Pointer.Size
}
2015-05-13 14:23:49 +00:00
func (d *DownloadCheckable) Name() string {
return d.Pointer.Name
}
func (d *DownloadCheckable) SetObject(o *objectResource) {
d.object = o
2015-05-13 14:23:49 +00:00
}
// NewDownloadCheckQueue builds a checking queue, allowing `workers` concurrent check operations.
func NewDownloadCheckQueue(files int, size int64, dryRun bool) *TransferQueue {
q := newTransferQueue(files, size, dryRun)
// API operation is still download, but it will only perform the API call (check)
q.transferKind = "download"
return q
}
// The ability to actually download
type Downloadable struct {
*DownloadCheckable
}
func NewDownloadable(p *WrappedPointer) *Downloadable {
return &Downloadable{DownloadCheckable: NewDownloadCheckable(p)}
}
func (d *Downloadable) Transfer(cb CopyCallback) *WrappedError {
err := PointerSmudgeObject(d.Pointer.Pointer, d.object, cb)
if err != nil {
return Error(err)
}
return nil
}
// NewDownloadQueue builds a DownloadQueue, allowing `workers` concurrent downloads.
func NewDownloadQueue(files int, size int64, dryRun bool) *TransferQueue {
q := newTransferQueue(files, size, dryRun)
q.transferKind = "download"
return q
2015-05-13 14:23:49 +00:00
}