updatechain

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: GPL-3.0 Imports: 0 Imported by: 0

Documentation

Overview

Package updatechain works out where a file stands against the updates that Nexus Mods knows about for its mod: whether something newer has replaced it, and whether that newer file has already been imported.

It only deals with the file ids and knows nothing about where the chain comes from (the Nexus cache) or what is done with the answer (showing it).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Chain

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

Chain is which file replaced which, for one mod. Its files can be of different kinds (main files, optional files, ...), each replaced by its own successors, but file ids are never shared so one Chain holds them all.

The zero Chain knows of no updates: every file is the latest.

func New

func New(updates []Update) Chain

New returns the Chain of the given updates. If several say what replaced the same file, the last one wins.

func (Chain) Closest

func (c Chain) Closest(candidates []int64) (index int, ok bool)

Closest returns the index of the file of candidates that is closest to the latest file of its chain, that is, the one that has the fewest updates left. It is for the versions of one file that have been imported, where the one that matters is the most recent. The first of several that are equally close wins. ok is false when there are no candidates.

func (Chain) Distance

func (c Chain) Distance(fileID int64) int

Distance returns how many updates there are between fileID and the latest file of its chain: 0 for a file that nothing replaced.

func (Chain) HasSuccessor

func (c Chain) HasSuccessor(fileID int64) bool

HasSuccessor reports whether some file replaced fileID.

func (Chain) Head

func (c Chain) Head(fileID int64) int64

Head follows the updates from fileID and returns the latest file: fileID itself if nothing replaced it. A chain that loops back on itself (which Nexus should never give us) is followed until it closes the loop, and the file where it does is returned, so that this always ends.

func (Chain) Status

func (c Chain) Status(fileID int64, imported map[int64]struct{}) Status

Status says where fileID stands: whether something replaced it and, if so, whether the latest file is among the imported file ids.

type State

type State int

State is where a file stands against the updates of its mod.

const (
	// UpToDate means that nothing has replaced the file.
	UpToDate State = iota
	// Superseded means that the file has been replaced by a newer one that is
	// already imported, so there is nothing to tell the user about.
	Superseded
	// UpdateAvailable means that the file has been replaced by a newer one
	// that is not imported (yet).
	UpdateAvailable
)

type Status

type Status struct {
	State State

	// Head is the latest file of the chain: the file itself when it is
	// UpToDate.
	Head int64
}

Status is the outcome of Chain.Status.

type Update

type Update struct {
	OldFileID int64
	NewFileID int64
}

Update is one link of a chain: NewFileID is the file that replaced OldFileID.

Jump to

Keyboard shortcuts

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