2016-05-19 15:05:34 +00:00
|
|
|
// Package transfer collects together adapters for uploading and downloading LFS content
|
|
|
|
// NOTE: Subject to change, do not rely on this package from outside git-lfs source
|
|
|
|
package transfer
|
|
|
|
|
2016-11-15 17:01:18 +00:00
|
|
|
import "github.com/git-lfs/git-lfs/api"
|
2016-05-19 15:05:34 +00:00
|
|
|
|
|
|
|
type Direction int
|
|
|
|
|
|
|
|
const (
|
|
|
|
Upload = Direction(iota)
|
|
|
|
Download = Direction(iota)
|
|
|
|
)
|
|
|
|
|
2016-05-31 09:44:35 +00:00
|
|
|
// NewTransferAdapterFunc creates new instances of TransferAdapter. Code that wishes
|
|
|
|
// to provide new TransferAdapter instances should pass an implementation of this
|
2016-08-10 14:39:57 +00:00
|
|
|
// function to RegisterNewTransferAdapterFunc() on a *Manifest.
|
2016-05-31 09:44:35 +00:00
|
|
|
// name and dir are to provide context if one func implements many instances
|
|
|
|
type NewTransferAdapterFunc func(name string, dir Direction) TransferAdapter
|
|
|
|
|
2016-05-27 11:52:18 +00:00
|
|
|
type TransferProgressCallback func(name string, totalSize, readSoFar int64, readSinceLast int) error
|
|
|
|
|
2016-05-19 15:05:34 +00:00
|
|
|
// TransferAdapter is implemented by types which can upload and/or download LFS
|
|
|
|
// file content to a remote store. Each TransferAdapter accepts one or more requests
|
|
|
|
// which it may schedule and parallelise in whatever way it chooses, clients of
|
|
|
|
// this interface will receive notifications of progress and completion asynchronously.
|
2016-05-19 15:10:32 +00:00
|
|
|
// TransferAdapters support transfers in one direction; if an implementation
|
|
|
|
// provides support for upload and download, it should be instantiated twice,
|
|
|
|
// advertising support for each direction separately.
|
2016-05-24 16:03:59 +00:00
|
|
|
// Note that TransferAdapter only implements the actual upload/download of content
|
|
|
|
// itself; organising the wider process including calling the API to get URLs,
|
|
|
|
// handling progress reporting and retries is the job of the core TransferQueue.
|
|
|
|
// This is so that the orchestration remains core & standard but TransferAdapter
|
|
|
|
// can be changed to physically transfer to different hosts with less code.
|
2016-05-19 15:05:34 +00:00
|
|
|
type TransferAdapter interface {
|
2016-05-27 16:56:10 +00:00
|
|
|
// Name returns the name of this adapter, which is the same for all instances
|
|
|
|
// of this type of adapter
|
2016-05-19 15:05:34 +00:00
|
|
|
Name() string
|
|
|
|
// Direction returns whether this instance is an upload or download instance
|
|
|
|
// TransferAdapter instances can only be one or the other, although the same
|
2016-05-31 09:44:35 +00:00
|
|
|
// type may be instantiated for each direction
|
2016-05-19 15:05:34 +00:00
|
|
|
Direction() Direction
|
|
|
|
// Begin a new batch of uploads or downloads. Call this first, followed by
|
2016-05-27 13:58:49 +00:00
|
|
|
// one or more Add calls. maxConcurrency controls the number of transfers
|
|
|
|
// that may be done at once. The passed in callback will receive updates on
|
2016-05-19 15:05:34 +00:00
|
|
|
// progress, and the completion channel will receive completion notifications
|
2016-05-20 09:48:37 +00:00
|
|
|
// Either argument may be nil if not required by the client
|
2016-05-27 13:58:49 +00:00
|
|
|
Begin(maxConcurrency int, cb TransferProgressCallback, completion chan TransferResult) error
|
2016-05-19 15:05:34 +00:00
|
|
|
// Add queues a download/upload, which will complete asynchronously and
|
|
|
|
// notify the callbacks given to Begin()
|
2016-05-24 16:03:59 +00:00
|
|
|
Add(t *Transfer)
|
2016-05-19 15:05:34 +00:00
|
|
|
// Indicate that all transfers have been scheduled and resources can be released
|
|
|
|
// once the queued items have completed.
|
|
|
|
// This call blocks until all items have been processed
|
2016-05-24 16:03:59 +00:00
|
|
|
End()
|
2016-05-19 15:05:34 +00:00
|
|
|
// ClearTempStorage clears any temporary files, such as unfinished downloads that
|
|
|
|
// would otherwise be resumed
|
|
|
|
ClearTempStorage() error
|
|
|
|
}
|
|
|
|
|
|
|
|
// General struct for both uploads and downloads
|
|
|
|
type Transfer struct {
|
|
|
|
// Name of the file that triggered this transfer
|
|
|
|
Name string
|
2016-05-24 16:03:59 +00:00
|
|
|
// Object from API which provides the core data for this transfer
|
|
|
|
Object *api.ObjectResource
|
2016-05-19 15:05:34 +00:00
|
|
|
// Path for uploads is the source of data to send, for downloads is the
|
|
|
|
// location to place the final result
|
|
|
|
Path string
|
|
|
|
}
|
|
|
|
|
2016-05-31 09:44:35 +00:00
|
|
|
// NewTransfer creates a new Transfer instance
|
2016-05-24 16:03:59 +00:00
|
|
|
func NewTransfer(name string, obj *api.ObjectResource, path string) *Transfer {
|
|
|
|
return &Transfer{name, obj, path}
|
|
|
|
}
|
|
|
|
|
2016-05-19 15:05:34 +00:00
|
|
|
// Result of a transfer returned through CompletionChannel()
|
|
|
|
type TransferResult struct {
|
2016-05-24 16:03:59 +00:00
|
|
|
Transfer *Transfer
|
2016-05-19 15:05:34 +00:00
|
|
|
// This will be non-nil if there was an error transferring this item
|
|
|
|
Error error
|
|
|
|
}
|