2015-05-13 14:23:49 +00:00
|
|
|
package lfs
|
|
|
|
|
2015-08-13 08:33:01 +00:00
|
|
|
// The ability to check that a file can be downloaded
|
|
|
|
type DownloadCheckable struct {
|
2015-05-27 19:45:18 +00:00
|
|
|
Pointer *WrappedPointer
|
2015-05-21 16:36:49 +00:00
|
|
|
object *objectResource
|
2015-05-13 14:23:49 +00:00
|
|
|
}
|
|
|
|
|
2015-08-13 08:33:01 +00:00
|
|
|
func NewDownloadCheckable(p *WrappedPointer) *DownloadCheckable {
|
|
|
|
return &DownloadCheckable{Pointer: p}
|
2015-05-13 14:23:49 +00:00
|
|
|
}
|
|
|
|
|
2015-08-13 08:33:01 +00:00
|
|
|
func (d *DownloadCheckable) Check() (*objectResource, *WrappedError) {
|
2015-05-21 16:36:49 +00:00
|
|
|
return DownloadCheck(d.Pointer.Oid)
|
2015-05-14 18:56:30 +00:00
|
|
|
}
|
|
|
|
|
2015-08-13 08:33:01 +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()))
|
2015-05-21 16:36:49 +00:00
|
|
|
return nil
|
2015-05-13 14:23:49 +00:00
|
|
|
}
|
|
|
|
|
2015-08-13 08:33:01 +00:00
|
|
|
func (d *DownloadCheckable) Object() *objectResource {
|
2015-05-21 16:36:49 +00:00
|
|
|
return d.object
|
2015-05-13 14:23:49 +00:00
|
|
|
}
|
|
|
|
|
2015-08-13 08:33:01 +00:00
|
|
|
func (d *DownloadCheckable) Oid() string {
|
2015-05-21 16:36:49 +00:00
|
|
|
return d.Pointer.Oid
|
|
|
|
}
|
2015-05-13 14:23:49 +00:00
|
|
|
|
2015-08-13 08:33:01 +00:00
|
|
|
func (d *DownloadCheckable) Size() int64 {
|
2015-05-21 16:36:49 +00:00
|
|
|
return d.Pointer.Size
|
|
|
|
}
|
2015-05-13 14:23:49 +00:00
|
|
|
|
2015-08-13 08:33:01 +00:00
|
|
|
func (d *DownloadCheckable) Name() string {
|
2015-06-19 17:59:30 +00:00
|
|
|
return d.Pointer.Name
|
|
|
|
}
|
|
|
|
|
2015-08-13 08:33:01 +00:00
|
|
|
func (d *DownloadCheckable) SetObject(o *objectResource) {
|
2015-05-21 16:36:49 +00:00
|
|
|
d.object = o
|
2015-05-13 14:23:49 +00:00
|
|
|
}
|
|
|
|
|
2015-08-13 08:33:01 +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
|
|
|
|
}
|
|
|
|
|
2015-05-21 16:36:49 +00:00
|
|
|
// NewDownloadQueue builds a DownloadQueue, allowing `workers` concurrent downloads.
|
2015-07-30 14:43:50 +00:00
|
|
|
func NewDownloadQueue(files int, size int64, dryRun bool) *TransferQueue {
|
|
|
|
q := newTransferQueue(files, size, dryRun)
|
2015-05-21 16:36:49 +00:00
|
|
|
q.transferKind = "download"
|
|
|
|
return q
|
2015-05-13 14:23:49 +00:00
|
|
|
}
|