Documentation ¶
Overview ¶
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
Index ¶
- Constants
- func IsActionExpiredError(err error) bool
- func NewCustomAdapterDownloadRequest(oid string, size int64, action *Action) *customAdapterTransferRequest
- func NewCustomAdapterInitRequest(op string, remote string, concurrent bool, concurrentTransfers int) *customAdapterInitRequest
- func NewCustomAdapterTerminateRequest() *customAdapterTerminateRequest
- func NewCustomAdapterUploadRequest(oid string, size int64, path string, action *Action) *customAdapterTransferRequest
- type Action
- type ActionExpiredErr
- type ActionSet
- type Adapter
- type AdapterConfig
- type BatchResponse
- type Direction
- type Env
- type MalformedObjectError
- type Manifest
- func (m *Manifest) APIClient() *lfsapi.Client
- func (m *Manifest) ConcurrentTransfers() int
- func (m *Manifest) GetAdapterNames(dir Direction) []string
- func (m *Manifest) GetDownloadAdapterNames() []string
- func (m *Manifest) GetUploadAdapterNames() []string
- func (m *Manifest) IsStandaloneTransfer() bool
- func (m *Manifest) MaxRetries() int
- func (m *Manifest) NewAdapter(name string, dir Direction) Adapter
- func (m *Manifest) NewAdapterOrDefault(name string, dir Direction) Adapter
- func (m *Manifest) NewDownloadAdapter(name string) Adapter
- func (m *Manifest) NewUploadAdapter(name string) Adapter
- func (m *Manifest) RegisterNewAdapterFunc(name string, dir Direction, f NewAdapterFunc)
- type Meter
- func (m *Meter) Add(size int64)
- func (m *Meter) Finish()
- func (m *Meter) FinishTransfer(name string)
- func (m *Meter) Flush()
- func (m *Meter) LoggerFromEnv(os env) *tools.SyncWriter
- func (m *Meter) LoggerToFile(name string) *tools.SyncWriter
- func (m *Meter) Pause()
- func (m *Meter) Skip(size int64)
- func (m *Meter) Start()
- func (m *Meter) StartTransfer(name string)
- func (m *Meter) Throttled() bool
- func (m *Meter) TransferBytes(direction, name string, read, total int64, current int)
- func (m *Meter) Updates() <-chan *tasklog.Update
- type NewAdapterFunc
- type ObjectError
- type Option
- type ProgressCallback
- type Transfer
- type TransferQueue
- type TransferResult
Constants ¶
const ( Upload = Direction(iota) Download = Direction(iota) )
const ( TusAdapterName = "tus" TusVersion = "1.0.0" )
const (
BasicAdapterName = "basic"
)
Variables ¶
This section is empty.
Functions ¶
func IsActionExpiredError ¶
func NewCustomAdapterTerminateRequest ¶
func NewCustomAdapterTerminateRequest() *customAdapterTerminateRequest
Types ¶
type Action ¶
type ActionExpiredErr ¶
func (ActionExpiredErr) Error ¶
func (e ActionExpiredErr) Error() string
type Adapter ¶
type Adapter interface { // Name returns the name of this adapter, which is the same for all instances // of this type of adapter Name() string // Direction returns whether this instance is an upload or download instance // Adapter instances can only be one or the other, although the same // type may be instantiated for each direction Direction() Direction // Begin a new batch of uploads or downloads. Call this first, followed by // 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 // progress. Either argument may be nil if not required by the client. Begin(cfg AdapterConfig, cb ProgressCallback) error // Add queues a download/upload, which will complete asynchronously and // notify the callbacks given to Begin() Add(transfers ...*Transfer) (results <-chan TransferResult) // 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 End() // ClearTempStorage clears any temporary files, such as unfinished downloads that // would otherwise be resumed ClearTempStorage() error }
Adapter is implemented by types which can upload and/or download LFS file content to a remote store. Each Adapter 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. 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. Note that Adapter 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 Adapter can be changed to physically transfer to different hosts with less code.
type AdapterConfig ¶
type BatchResponse ¶
type Env ¶
type Env interface { Get(key string) (val string, ok bool) GetAll(key string) []string Bool(key string, def bool) (val bool) Int(key string, def int) (val int) All() map[string][]string }
Env is any object with a config.Environment interface.
type MalformedObjectError ¶
type MalformedObjectError struct { Name string Oid string // contains filtered or unexported fields }
func (MalformedObjectError) Corrupt ¶
func (e MalformedObjectError) Corrupt() bool
func (MalformedObjectError) Error ¶
func (e MalformedObjectError) Error() string
func (MalformedObjectError) Missing ¶
func (e MalformedObjectError) Missing() bool
type Manifest ¶
type Manifest struct {
// contains filtered or unexported fields
}
func NewManifest ¶
func (*Manifest) ConcurrentTransfers ¶
func (*Manifest) GetAdapterNames ¶
GetAdapterNames returns a list of the names of adapters available to be created
func (*Manifest) GetDownloadAdapterNames ¶
GetDownloadAdapterNames returns a list of the names of download adapters available to be created
func (*Manifest) GetUploadAdapterNames ¶
GetUploadAdapterNames returns a list of the names of upload adapters available to be created
func (*Manifest) IsStandaloneTransfer ¶
func (*Manifest) MaxRetries ¶
func (*Manifest) NewAdapter ¶
Create a new adapter by name and direction, or nil if doesn't exist
func (*Manifest) NewAdapterOrDefault ¶
Create a new adapter by name and direction; default to BasicAdapterName if doesn't exist
func (*Manifest) NewDownloadAdapter ¶
Create a new download adapter by name, or BasicAdapterName if doesn't exist
func (*Manifest) NewUploadAdapter ¶
Create a new upload adapter by name, or BasicAdapterName if doesn't exist
func (*Manifest) RegisterNewAdapterFunc ¶
func (m *Manifest) RegisterNewAdapterFunc(name string, dir Direction, f NewAdapterFunc)
RegisterNewTransferAdapterFunc registers a new function for creating upload or download adapters. If a function with that name & direction is already registered, it is overridden
type Meter ¶
type Meter struct { DryRun bool Logger *tools.SyncWriter Direction Direction // contains filtered or unexported fields }
Meter provides a progress bar type output for the TransferQueue. It is given an estimated file count and size up front and tracks the number of files and bytes transferred as well as the number of files and bytes that get skipped because the transfer is unnecessary.
func (*Meter) Add ¶
Add tells the progress meter that a single file of the given size will possibly be transferred. If a file doesn't need to be transferred for some reason, be sure to call Skip(int64) with the same size.
func (*Meter) FinishTransfer ¶
FinishTransfer increments the finished transfer count
func (*Meter) Flush ¶
func (m *Meter) Flush()
Flush sends the latest progress update, while leaving the meter active.
func (*Meter) LoggerFromEnv ¶
func (m *Meter) LoggerFromEnv(os env) *tools.SyncWriter
func (*Meter) LoggerToFile ¶
func (m *Meter) LoggerToFile(name string) *tools.SyncWriter
func (*Meter) Pause ¶
func (m *Meter) Pause()
Pause stops sending status updates temporarily, until Start() is called again.
func (*Meter) Skip ¶
Skip tells the progress meter that a file of size `size` is being skipped because the transfer is unnecessary.
func (*Meter) Start ¶
func (m *Meter) Start()
Start begins sending status updates to the optional log file, and stdout.
func (*Meter) StartTransfer ¶
StartTransfer tells the progress meter that a transferring file is being added to the TransferQueue.
func (*Meter) TransferBytes ¶
TransferBytes increments the number of bytes transferred
type NewAdapterFunc ¶
NewAdapterFunc creates new instances of Adapter. Code that wishes to provide new Adapter instances should pass an implementation of this function to RegisterNewTransferAdapterFunc() on a *Manifest. name and dir are to provide context if one func implements many instances
type ObjectError ¶
func (*ObjectError) Error ¶
func (e *ObjectError) Error() string
type Option ¶
type Option func(*TransferQueue)
func WithBatchSize ¶
func WithBufferDepth ¶
func WithProgress ¶
func WithProgressCallback ¶
func WithProgressCallback(cb tools.CopyCallback) Option
type ProgressCallback ¶
type Transfer ¶
type Transfer struct { Name string `json:"name,omitempty"` Oid string `json:"oid,omitempty"` Size int64 `json:"size"` Authenticated bool `json:"authenticated,omitempty"` Actions ActionSet `json:"actions,omitempty"` Links ActionSet `json:"_links,omitempty"` Error *ObjectError `json:"error,omitempty"` Path string `json:"path,omitempty"` }
type TransferQueue ¶
type TransferQueue struct {
// contains filtered or unexported fields
}
TransferQueue organises the wider process of uploading and downloading, including calling the API, passing the actual transfer request to transfer adapters, and dealing with progress, errors and retries.
func NewTransferQueue ¶
func NewTransferQueue(dir Direction, manifest *Manifest, remote string, options ...Option) *TransferQueue
NewTransferQueue builds a TransferQueue, direction and underlying mechanism determined by adapter
func (*TransferQueue) Add ¶
func (q *TransferQueue) Add(name, path, oid string, size int64)
Add adds a *Transfer to the transfer queue. It only increments the amount of waiting the TransferQueue has to do if the *Transfer "t" is new.
If another transfer(s) with the same OID has been added to the *TransferQueue already, the given transfer will not be enqueued, but will be sent to any channel created by Watch() once the oldest transfer has completed.
Only one file will be transferred to/from the Path element of the first transfer.
func (*TransferQueue) BatchSize ¶
func (q *TransferQueue) BatchSize() int
BatchSize returns the batch size of the receiving *TransferQueue, or, the number of transfers to accept before beginning work on them.
func (*TransferQueue) Errors ¶
func (q *TransferQueue) Errors() []error
Errors returns any errors encountered during transfer.
func (*TransferQueue) Skip ¶
func (q *TransferQueue) Skip(size int64)
func (*TransferQueue) Wait ¶
func (q *TransferQueue) Wait()
Wait waits for the queue to finish processing all transfers. Once Wait is called, Add will no longer add transfers to the queue. Any failed transfers will be automatically retried once.
func (*TransferQueue) Watch ¶
func (q *TransferQueue) Watch() chan *Transfer
Watch returns a channel where the queue will write the value of each transfer as it completes. If multiple transfers exist with the same OID, they will all be recorded here, even though only one actual transfer took place. The channel will be closed when the queue finishes processing.
type TransferResult ¶
type TransferResult struct { Transfer *Transfer // This will be non-nil if there was an error transferring this item Error error }
Result of a transfer returned through CompletionChannel()