transfer

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 19, 2022 License: MIT Imports: 14 Imported by: 1

Documentation

Index

Constants

View Source
const (
	HashAlgoKey  = "hash-algo"
	TransferKey  = "transfer"
	RefnameKey   = "refname"
	ExpiresInKey = "expires-in"
	ExpiresAtKey = "expires-at"
	SizeKey      = "size"
	PathKey      = "path"
	LimitKey     = "limit"
	CursorKey    = "cursor"
)

batch request argument keys.

View Source
const (
	// Flush is the flush packet.
	Flush = '\x00'
	// Delim is the delimiter packet.
	Delim = '\x01'
)
View Source
const (
	StatusContinue            uint32 = http.StatusContinue
	StatusOK                  uint32 = http.StatusOK
	StatusCreated             uint32 = http.StatusCreated
	StatusAccepted            uint32 = http.StatusAccepted
	StatusBadRequest          uint32 = http.StatusBadRequest
	StatusForbidden           uint32 = http.StatusForbidden
	StatusNotFound            uint32 = http.StatusNotFound
	StatusConflict            uint32 = http.StatusConflict
	StatusInternalServerError uint32 = http.StatusInternalServerError
)

Status codes.

Variables

View Source
var (
	// ErrConflict is the conflict error.
	ErrConflict = errors.New("conflict")
	// ErrParseError is the parse error.
	ErrParseError = errors.New("parse error")
	// ErrMissingData is the missing data error.
	ErrMissingData = errors.New("missing data")
	// ErrExtraData is the extra data error.
	ErrExtraData = errors.New("extra data")
	// ErrCorruptData is the corrupt data error.
	ErrCorruptData = errors.New("corrupt data")
	// ErrNotAllowed is the not allowed error.
	ErrNotAllowed = errors.New("not allowed")
	// ErrInvalidPacket is the invalid packet error.
	ErrInvalidPacket = errors.New("invalid packet")
)
View Source
var (
	// Debug is the debug flag.
	Debug = false
)
View Source
var (
	// ErrInvalidOid is returned when an invalid Oid is encountered.
	ErrInvalidOid = errors.New("invalid oid")
)

Functions

func ArgsToList

func ArgsToList(args map[string]string) []string

ArgsToList converts the given args to a list.

func Log

func Log(v ...interface{})

Log logs the given arguments if Debug is true.

func Logf

func Logf(format string, v ...interface{})

Logf logs the given arguments if Debug is true.

func ParseArgs

func ParseArgs(lines []string) (map[string]string, error)

ParseArgs parses the given args.

func StatusText

func StatusText(code uint32) string

StatusString returns the status string lowercased for a status code.

Types

type Backend

type Backend interface {
	Batch(op Operation, oids []OidWithSize) ([]BatchItem, error)
	StartUpload(oid Oid, r io.Reader, args ...string) (interface{}, error)
	FinishUpload(state interface{}, args ...string) error
	Verify(oid Oid, args map[string]string) (Status, error)
	Download(oid Oid, args ...string) (fs.File, error)
	LockBackend() LockBackend
}

Backend is a Git LFS backend.

type BatchItem

type BatchItem struct {
	Oid     Oid
	Size    int64
	Present bool
}

BatchItem is a Git LFS batch item.

type HashingReader

type HashingReader struct {
	// contains filtered or unexported fields
}

HashingReader is a reader that hashes the data it reads.

func NewHashingReader

func NewHashingReader(r io.Reader, hash hash.Hash) *HashingReader

NewHashingReader creates a new hashing reader.

func (*HashingReader) Oid

func (h *HashingReader) Oid() (Oid, error)

Oid returns the hash of the data read.

func (*HashingReader) Read

func (h *HashingReader) Read(p []byte) (int, error)

Read reads data from the underlying reader and hashes it.

func (*HashingReader) Size

func (h *HashingReader) Size() int64

Size returns the number of bytes read.

type Lock

type Lock interface {
	Unlock() error
	ID() string
	Path() string
	FormattedTimestamp() string
	OwnerName() string
	AsLockSpec(ownerID bool) ([]string, error)
	AsArguments() []string
}

Lock is a Git LFS lock.

type LockBackend

type LockBackend interface {
	Create(path string) (Lock, error)
	Unlock(lock Lock) error
	FromPath(path string) (Lock, error)
	FromID(id string) (Lock, error)
	Range(func(Lock) error) error
}

LockBackend is a Git LFS lock backend.

type Oid

type Oid string

Oid is a Git LFS object ID.

func NewOid

func NewOid(b string) (Oid, error)

NewOid creates a new Oid from bytes.

func (Oid) ExpectedPath

func (o Oid) ExpectedPath(path string) string

ExpectedPath returns the expected path of the Oid. The path argument should be a `.git/lfs` directory.

func (Oid) Stat

func (o Oid) Stat(path string) (fs.FileInfo, error)

Stat returns the file info of the Oid. The path argument should be a `.git/lfs` directory.

func (Oid) String

func (o Oid) String() string

String returns the string representation of the Oid.

func (Oid) Valid

func (o Oid) Valid() bool

Valid returns true if the Oid is valid.

func (Oid) Value

func (o Oid) Value() []byte

Value returns the bytes representation of the Oid.

type OidWithSize

type OidWithSize struct {
	Oid  Oid
	Size int64
}

OidWithSize is a Git LFS object ID with size.

type Operation

type Operation int

Operation is a Git LFS operation.

const (
	// UploadOperation is an upload operation.
	UploadOperation Operation = iota
	// DownloadOperation is a download operation.
	DownloadOperation
)

func (Operation) String

func (o Operation) String() string

String returns the string representation of the Operation.

type Pktline

type Pktline struct {
	*pktline.Pktline
	// contains filtered or unexported fields
}

PktLine is a Git packet line handler.

func NewPktline

func NewPktline(r io.Reader, w io.Writer) *Pktline

NewPktline creates a new Git packet line handler.

func (*Pktline) ReadPacketListToDelim

func (p *Pktline) ReadPacketListToDelim() ([]string, error)

ReadPacketListToDelim reads as many packets as possible using the `readPacketText` function before encountering a delim packet. It returns a slice of all the packets it read, or an error if one was encountered.

func (*Pktline) ReadPacketListToFlush

func (p *Pktline) ReadPacketListToFlush() ([]string, error)

ReadPacketListToFlush reads as many packets as possible using the `readPacketText` function before encountering a flush packet. It returns a slice of all the packets it read, or an error if one was encountered.

func (*Pktline) Reader

func (p *Pktline) Reader() *pktline.PktlineReader

Reader returns a reader for the packet line.

func (*Pktline) ReaderWithSize

func (p *Pktline) ReaderWithSize(size int) *pktline.PktlineReader

ReaderWithSize returns a reader for the packet line with the given size.

func (*Pktline) SendError

func (p *Pktline) SendError(status uint32, message string) error

SendError sends an error msg.

func (*Pktline) SendStatus

func (p *Pktline) SendStatus(status Status) error

SendStatus sends a status message.

func (*Pktline) Writer

func (p *Pktline) Writer() *pktline.PktlineWriter

Writer returns a writer for the packet line.

func (*Pktline) WriterWithSize

func (p *Pktline) WriterWithSize(size int) *pktline.PktlineWriter

WriterWithSize returns a writer for the packet line with the given size.

type Processor

type Processor struct {
	// contains filtered or unexported fields
}

Processor is a transfer processor.

func NewProcessor

func NewProcessor(line *Pktline, backend Backend) *Processor

NewProcessor creates a new transfer processor.

func (*Processor) BatchData

func (p *Processor) BatchData(op Operation, presentAction string, missingAction string) (Status, error)

BatchData writes batch data to the transfer protocol.

func (*Processor) DownloadBatch

func (p *Processor) DownloadBatch() (Status, error)

DownloadBatch writes download data to the transfer protocol.

func (*Processor) Error

func (p *Processor) Error(code uint32, message string) (Status, error)

Error returns a transfer protocol error.

func (*Processor) GetObject

func (p *Processor) GetObject(oid Oid) (Status, error)

GetObject writes an object ID to the transfer protocol.

func (*Processor) ListLocks

func (p *Processor) ListLocks(useOwnerID bool) (Status, error)

ListLocks lists locks.

func (*Processor) ListLocksForPath

func (p *Processor) ListLocksForPath(path string, cursor string, useOwnerID bool) (Status, error)

ListLocksForPath lists locks for a path. cursor can be empty.

func (*Processor) Lock

func (p *Processor) Lock() (Status, error)

Lock writes a lock to the transfer protocol.

func (*Processor) ProcessCommands

func (p *Processor) ProcessCommands(op Operation) error

ProcessCommands processes commands from the transfer protocol.

func (*Processor) PutObject

func (p *Processor) PutObject(oid Oid) (Status, error)

PutObject writes an object ID to the transfer protocol.

func (*Processor) ReadBatch

func (p *Processor) ReadBatch(op Operation) ([]BatchItem, error)

ReadBatch reads a batch request.

func (Processor) SizeFromArgs

func (Processor) SizeFromArgs(args map[string]string) (int64, error)

SizeFromArgs returns the size from the given args.

func (*Processor) Unlock

func (p *Processor) Unlock(id string) (Status, error)

Unlock unlocks a lock.

func (*Processor) UploadBatch

func (p *Processor) UploadBatch() (Status, error)

UploadBatch writes upload data to the transfer protocol.

func (*Processor) VerifyObject

func (p *Processor) VerifyObject(oid Oid) (Status, error)

VerifyObject verifies an object ID.

func (*Processor) Version

func (p *Processor) Version() (Status, error)

Version returns the version of the transfer protocol.

type Status

type Status interface {
	Code() uint32
	Args() []string
	Messages() []string
	Reader() io.Reader
}

Status is a Git LFS status.

func NewFailureStatus

func NewFailureStatus(code uint32, message string) Status

NewFailureStatus returns a new failure status.

func NewFailureStatusWithArgs

func NewFailureStatusWithArgs(code uint32, message string, args ...string) Status

NewFailureStatusWithArgs returns a new failure status with args.

func NewSuccessStatus

func NewSuccessStatus(messages []string) Status

NewSuccessStatus returns a new successful status.

func NewSuccessStatusWithCode

func NewSuccessStatusWithCode(code uint32, args ...string) Status

NewSuccessStatusWithCode returns a new successful status with a code.

func NewSuccessStatusWithData

func NewSuccessStatusWithData(code uint32, messages []string, args ...string) Status

NewSuccessStatusWithData returns a new successful status with data.

func NewSuccessStatusWithReader

func NewSuccessStatusWithReader(reader io.Reader, args ...string) Status

NewSuccessStatusWithReader returns a new status with a reader.

func SuccessStatus

func SuccessStatus() Status

SuccessStatus returns a successful status.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL