patcher

package
v0.0.0-...-189a019 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2022 License: MIT Imports: 16 Imported by: 6

Documentation

Index

Constants

View Source
const (
	// FileKindRsync denotes rsync patching (blocks-based)
	FileKindRsync = 1
	// FileKindBsdiff denotes bsdiff patching (addition-based)
	FileKindBsdiff = 2
)

Variables

View Source
var ErrStop = fmt.Errorf("patching was stopped after save!")

ErrStop is returned by `patcher.Resume` if it just saved a checkpoint and the `SaveConsumer` returned `AfterSaveStop`.

Functions

func PatchFresh

func PatchFresh(params PatchFreshParams) error

Types

type AfterSaveAction

type AfterSaveAction int

AfterSaveAction describes what the patcher should do after it saved. This can be used to gracefully stop it.

const (
	// AfterSaveContinue indicates that the patcher should continue after saving.
	AfterSaveContinue AfterSaveAction = 1
	// AfterSaveStop indicates that the patcher should stop and return ErrStop
	AfterSaveStop AfterSaveAction = 2
)

type BsdiffCheckpoint

type BsdiffCheckpoint struct {
	WriterCheckpoint *bowl.WriterCheckpoint

	// instructions in bsdiff are relative seeks, so we need to keep track of
	// the offset in the (single) target file
	OldOffset int64

	// bsdiff series are applied against a single target file, and its index
	// is in a past message, so we need to keep track of it
	TargetIndex int64
}

BsdiffCheckpoint is used when saving a patcher checkpoint in the middle of patching a file with bsdiff instructions.

type Checkpoint

type Checkpoint struct {
	MessageCheckpoint *wire.MessageReaderCheckpoint

	FileIndex int64
	FileKind  FileKind

	BowlCheckpoint   *bowl.BowlCheckpoint
	SyncHeader       *pwr.SyncHeader
	RsyncCheckpoint  *RsyncCheckpoint
	BsdiffCheckpoint *BsdiffCheckpoint
}

Checkpoint contains state information for a patcher that can be written to disk and read back from disk to resume roughly where we left off.

type FileKind

type FileKind int

FileKind denotes either rsync or bsdiff patching

type PatchFreshParams

type PatchFreshParams struct {
	PatchReader savior.SeekSource

	TargetDir string
	OutputDir string

	Consumer *state.Consumer
}

type Patcher

type Patcher interface {
	SetSaveConsumer(sc SaveConsumer)
	Resume(checkpoint *Checkpoint, targetPool lake.Pool, bowl bowl.Bowl) error
	Progress() float64

	GetSourceContainer() *tlc.Container
	GetTargetContainer() *tlc.Container
	SetSourceIndexWhitelist(sourceIndexWhitelist map[int64]bool)
	GetTouchedFiles() int64
}

A Patcher applies a wharf patch, either standard (rsync-only) or optimized (rsync + bsdiff). It can save its progress and resume. It patches to a bowl: fresh bowls (create new folder with new build), overlay bowls (patch to overlay, then commit that overlay in-place), etc.

func New

func New(patchReader savior.SeekSource, consumer *state.Consumer) (Patcher, error)

New reads the patch header and returns a patcher that is ready to Resume, either from the start (nil checkpoint) or partway through the patch

type RsyncCheckpoint

type RsyncCheckpoint struct {
	WriterCheckpoint *bowl.WriterCheckpoint
}

RsyncCheckpoint is used when saving a patcher checkpoint in the middle of patching a file with rsync instructions.

type SaveConsumer

type SaveConsumer interface {
	ShouldSave() bool
	Save(c *Checkpoint) (AfterSaveAction, error)
}

A SaveConsumer can be set on a Patcher to decide if the patcher should save (whenever it reaches a convenient place for a checkpoint), and to receive the checkpoints, and let the patcher know if it should stop or continue

Jump to

Keyboard shortcuts

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