librarysync

package
v2.18.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2026 License: GPL-3.0 Imports: 30 Imported by: 0

Documentation

Overview

Package librarysync keeps this device's library converged with the linked Zaparoo Online account while the user has Library sync turned on. Every local feature it touches works without it: sync only uploads what the device already holds and never makes a local list depend on the account.

Index

Constants

View Source
const (
	// DeviceStateKeyDecksSince is the pull cursor for decks.
	DeviceStateKeyDecksSince = "library_decks_since"
	// DeviceStateKeyDecksLink records the endpoint and device link the deck
	// bookkeeping belongs to.
	DeviceStateKeyDecksLink = "library_decks_link"
)
View Source
const (
	InventorySkipped   = "skipped"
	InventoryConfirmed = "confirmed"
	InventoryUploaded  = "uploaded"
	InventoryTooLarge  = "too_large"
)

Inventory pass outcomes.

View Source
const (
	// DeviceStateKeyEnabledSeen records the Library sync setting the last
	// pass acted on, so turning it off is noticed even across a restart or a
	// hand-edited config file.
	DeviceStateKeyEnabledSeen = "library_sync_enabled_seen"
	// DeviceStateKeyInventoryDeletePending records that the account still
	// holds this device's inventory after Library sync was turned off.
	DeviceStateKeyInventoryDeletePending = "library_inventory_delete_pending"
)
View Source
const (
	HintKindState = "state"
	HintKindDecks = "decks"
)

Kinds of library data a change hint from the account can name.

View Source
const (
	// DeviceStateKeyStateSince is the pull cursor for personal state.
	DeviceStateKeyStateSince = "library_state_since"
	// DeviceStateKeyStateLink records the endpoint and device link the
	// personal state bookkeeping belongs to.
	DeviceStateKeyStateLink = "library_state_link"
	// DeviceStateKeyStateMatchGeneration is the index generation the last
	// attempt to find copies of unmatched games ran against.
	DeviceStateKeyStateMatchGeneration = "library_state_match_generation"
)

Variables

View Source
var (
	// ErrDisabled reports a pass skipped because Library sync is off.
	ErrDisabled = errors.New("library sync is disabled")
	// ErrNotSettled reports a pass deferred because the media database is
	// being indexed or optimized.
	ErrNotSettled = errors.New("media database is not settled")
)

Functions

func IsIdleError

func IsIdleError(err error) bool

IsIdleError reports an error that means there is nothing to do right now rather than a failure: sync is off, the device is not linked, or the media database is busy or between connections. None of these deserve the failure backoff, because waiting for the next pass is the whole remedy.

Types

type ClientFactory

type ClientFactory func(baseURL string) (*backup.OnlineClient, error)

ClientFactory returns a client for the Library sync endpoint.

type DecksResult

type DecksResult struct {
	Pulled    int
	Pushed    int
	Conflicts int
	Rejected  int
}

DecksResult summarizes one deck pass.

type InventoryResult

type InventoryResult struct {
	Outcome    string
	Generation int64
	ItemCount  int
	Resolved   int
	Rejected   int
	Skipped    int
	Unanswered int
}

InventoryResult summarizes one inventory pass. Skipped counts present files the walk could not describe at all, so a library whose inventory is smaller than its file count has an answer in the log rather than only a discrepancy. Unanswered counts identities the account returned nothing usable for, which makes the inventory an incomplete description of the library.

type Options

type Options struct {
	Config    *config.Instance
	DB        *database.Database
	NewClient ClientFactory
	Inbox     *inbox.Service
	Pauser    *syncutil.Pauser
	// SendHeartbeat reports the device's capabilities, including whether
	// Library sync is on, after the setting changes. Optional.
	SendHeartbeat func(context.Context) error
	// Now returns the current time. Optional.
	Now func() time.Time
	// Launchers returns the launchers of a system, used to pick the copy a
	// launch would start when a pulled flag needs a home. Optional.
	Launchers func(systemID string) []platforms.Launcher
	// Notifications receives decks.changed when a sync pass changes a deck.
	// Optional.
	Notifications chan<- models.Notification
	// ResolvePace is the least time between resolve requests. Zero uses
	// the default.
	ResolvePace time.Duration
}

Options configures a Service.

type Service

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

Service runs Library sync passes.

func New

func New(opts *Options) *Service

New returns a Service.

func (*Service) ApplySetting

func (s *Service) ApplySetting(ctx context.Context) (bool, error)

ApplySetting acts on a change of the Library sync setting since the last time it was applied: turning it off marks the device's inventory for deletion, turning it on forces the next pass to check what the account holds, and either way the account is told through a heartbeat. It reports whether the setting had changed.

func (*Service) DeleteInventory

func (s *Service) DeleteInventory(ctx context.Context) (bool, error)

DeleteInventory drops this device's inventory from the account if Library sync was turned off since it was last committed. A device that is no longer linked has nothing left to drop.

func (*Service) Enabled

func (s *Service) Enabled() bool

Enabled reports whether the user has Library sync turned on, so a caller can skip work that only exists to serve it.

func (*Service) HintNeedsPull

func (s *Service) HintNeedsPull(kind string, revision int64) bool

HintNeedsPull reports whether a change hint names a write this device has not pulled yet. A hint at or below the pull cursor for its kind is an echo of something already seen; an unknown kind is always worth a pass.

func (*Service) PullDecks

func (s *Service) PullDecks(ctx context.Context) error

PullDecks applies deck changes from the account without pushing.

func (*Service) PullDecksIfStale

func (s *Service) PullDecksIfStale(ctx context.Context) error

PullDecksIfStale pulls decks when the last pull is older than the access window, for a client listing them or a deck that just opened.

func (*Service) SyncDecks

func (s *Service) SyncDecks(ctx context.Context) (DecksResult, error)

SyncDecks converges owned decks with the account: pull first so the bases are current, then push what changed here.

func (*Service) SyncInventory

func (s *Service) SyncInventory(ctx context.Context, force bool) (InventoryResult, error)

SyncInventory brings the account's copy of this device's inventory up to date with the current index. An index generation already committed is only checked against the account once an hour; force checks it now.

func (*Service) SyncState

func (s *Service) SyncState(ctx context.Context) (StateResult, error)

SyncState converges personal state with the account: it pulls what changed there first, so local bases are current, then pushes what changed here.

type StateResult

type StateResult struct {
	Pulled    int
	Pushed    int
	Conflicts int
	Rejected  int
}

StateResult summarizes one personal state pass.

Jump to

Keyboard shortcuts

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