sync

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package sync brings a server folder in line with a file manifest. It plans first, so the launcher can show what will change and how much it will download, then applies the plan.

Files are never written in place. Each download goes to a temporary file that is checked and then renamed over the old one, so an interrupted update never leaves a half-written file, and a hard link in the folder (see install) is replaced rather than written through. A temporary file left by an interrupted download is carried on from next time, rather than downloaded again.

Index

Constants

This section is empty.

Variables

View Source
var ErrInUse = errors.New("file is in use; close the game and try again")

ErrInUse means a file couldn't be replaced because something, usually the game, has it open.

Functions

func Apply

func Apply(ctx context.Context, c *fetch.Client, dir string, plan *Plan, cache Cache, progress func(Progress)) error

Apply carries out a plan: deletes first, in order, then downloads, several at once. It stops at the first failure; files already replaced stay replaced, and running it again picks up where it left off.

Types

type Action

type Action struct {
	Kind   Kind      `json:"kind"`
	File   spec.File `json:"file"`
	Reason string    `json:"reason"`
}

Action is one change to the server folder.

type Cache

type Cache map[string]CacheEntry

Cache remembers file hashes between runs, so an unchanged file isn't rehashed on every start. Entries are trusted only while size and modification time still match.

type CacheEntry

type CacheEntry struct {
	Size    int64     `json:"size"`
	ModTime time.Time `json:"modTime"`
	SHA256  string    `json:"sha256"`
}

CacheEntry is what the cache knows about one file.

type Kind

type Kind string

Kind is what an action does.

const (
	Download Kind = "download"
	Delete   Kind = "delete"
)

type Plan

type Plan struct {
	Actions []Action `json:"actions"`
	// Bytes is the total to download.
	Bytes int64 `json:"bytes"`
}

Plan is everything needed to bring a folder up to date.

func PlanManifest

func PlanManifest(dir string, m *spec.Manifest, cache Cache) (*Plan, error)

PlanManifest compares the folder with the manifest.

func PlanMatchingRemoval

func PlanMatchingRemoval(dir string, m *spec.Manifest, cache Cache) (*Plan, error)

PlanMatchingRemoval is the cautious form of PlanRemoval, for when the launcher has no record of installing a component but its files may be there, for example from an older layout. Only files that match the manifest exactly, by size and SHA-256, are removed.

func PlanRemoval

func PlanRemoval(dir string, m *spec.Manifest) (*Plan, error)

PlanRemoval lists the files a component version installed, for turning it off or switching version. Files the player owns ("once") are kept.

type Progress

type Progress struct {
	File       string `json:"file"`
	Done       int64  `json:"done"`
	Total      int64  `json:"total"`
	FilesDone  int    `json:"filesDone"`
	FilesTotal int    `json:"filesTotal"`
}

Progress reports how far an apply has got.

Jump to

Keyboard shortcuts

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