Re-use code between DownloadCheckable and Downloadable

Renamed Checkable to DownloadCheckable because it only applies to download,
upload checks differently and uses different struct fields. Incorporated
with download_queue.go since code is now smaller & common.
This commit is contained in:
Steve Streeting 2015-08-13 09:33:01 +01:00
parent a94e2a9937
commit a7d0a36ecb
3 changed files with 50 additions and 77 deletions

@ -144,9 +144,9 @@ func prePushCheckForMissingObjects(pointers []*lfs.WrappedPointer) (objectsOnSer
return nil
}
checkQueue := lfs.NewCheckQueue(len(missingLocalObjects), missingSize, false)
checkQueue := lfs.NewDownloadCheckQueue(len(missingLocalObjects), missingSize, false)
for _, p := range missingLocalObjects {
checkQueue.Add(lfs.NewCheckable(p))
checkQueue.Add(lfs.NewDownloadCheckable(p))
}
// this channel is filled with oids for which Check() succeeded & Transfer() was called
transferc := checkQueue.Watch()

@ -1,51 +0,0 @@
package lfs
// This is like DownloadQueue except it doesn't do the transfer, it just uses
// the "download" API point to verify that the server has objects
type Checkable struct {
Pointer *WrappedPointer
object *objectResource
}
func NewCheckable(p *WrappedPointer) *Checkable {
return &Checkable{Pointer: p}
}
func (d *Checkable) Check() (*objectResource, *WrappedError) {
return DownloadCheck(d.Pointer.Oid)
}
func (d *Checkable) Transfer(cb CopyCallback) *WrappedError {
// just report completion of check but don't do anything
cb(d.Size(), d.Size(), int(d.Size()))
return nil
}
func (d *Checkable) Object() *objectResource {
return d.object
}
func (d *Checkable) Oid() string {
return d.Pointer.Oid
}
func (d *Checkable) Size() int64 {
return d.Pointer.Size
}
func (d *Checkable) Name() string {
return d.Pointer.Name
}
func (d *Checkable) SetObject(o *objectResource) {
d.object = o
}
// NewCheckQueue builds a checking queue, allowing `workers` concurrent check operations.
func NewCheckQueue(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
}

@ -1,18 +1,62 @@
package lfs
type Downloadable struct {
// The ability to check that a file can be downloaded
type DownloadCheckable struct {
Pointer *WrappedPointer
object *objectResource
}
func NewDownloadable(p *WrappedPointer) *Downloadable {
return &Downloadable{Pointer: p}
func NewDownloadCheckable(p *WrappedPointer) *DownloadCheckable {
return &DownloadCheckable{Pointer: p}
}
func (d *Downloadable) Check() (*objectResource, *WrappedError) {
func (d *DownloadCheckable) Check() (*objectResource, *WrappedError) {
return DownloadCheck(d.Pointer.Oid)
}
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
}
func (d *DownloadCheckable) Object() *objectResource {
return d.object
}
func (d *DownloadCheckable) Oid() string {
return d.Pointer.Oid
}
func (d *DownloadCheckable) Size() int64 {
return d.Pointer.Size
}
func (d *DownloadCheckable) Name() string {
return d.Pointer.Name
}
func (d *DownloadCheckable) SetObject(o *objectResource) {
d.object = o
}
// 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 {
@ -21,26 +65,6 @@ func (d *Downloadable) Transfer(cb CopyCallback) *WrappedError {
return nil
}
func (d *Downloadable) Object() *objectResource {
return d.object
}
func (d *Downloadable) Oid() string {
return d.Pointer.Oid
}
func (d *Downloadable) Size() int64 {
return d.Pointer.Size
}
func (d *Downloadable) Name() string {
return d.Pointer.Name
}
func (d *Downloadable) SetObject(o *objectResource) {
d.object = o
}
// NewDownloadQueue builds a DownloadQueue, allowing `workers` concurrent downloads.
func NewDownloadQueue(files int, size int64, dryRun bool) *TransferQueue {
q := newTransferQueue(files, size, dryRun)