swupd

package
v4.6.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2018 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AllZeroHash = "0000000000000000000000000000000000000000000000000000000000000000"

AllZeroHash is the string representation of a zero value hash

View Source
var Hashes = []*string{&AllZeroHash}

Hashes is a global map of indices to hashes

Functions

func CreateAllDeltas

func CreateAllDeltas(outputDir string, fromVersion, toVersion, numWorkers int) error

CreateAllDeltas builds all of the deltas using the full manifest from one version to the next. This allows better concurrency and the pack creation code can just worry about adding pre-existing files to packs.

func FindBundlesToPack

func FindBundlesToPack(from *Manifest, to *Manifest) (map[string]*BundleToPack, error)

FindBundlesToPack will read two MoM manifests and return a set of bundles that must be packed (and their corresponding versions).

Note that a MoM can contain bundles in an old version, so each bundle needs its own From/To version pair.

func GetHashForBytes

func GetHashForBytes(info *HashFileInfo, data []byte) (string, error)

GetHashForBytes calculate the hash for data already in memory and the associated metadata.

func GetHashForFile

func GetHashForFile(filename string) (string, error)

GetHashForFile calculate the swupd hash for a file in the disk.

func GetPackFilename

func GetPackFilename(name string, fromVersion uint32) string

GetPackFilename returns the filename used for a pack of a bundle from a specific version.

func HashEquals

func HashEquals(h1 Hashval, h2 Hashval) bool

HashEquals trivial equality function for Hashval

Types

type BundleToPack

type BundleToPack struct {
	Name        string
	FromVersion uint32
	ToVersion   uint32
}

BundleToPack contains a bundle and the to/from versions to pack.

type CompressedTarReader

type CompressedTarReader struct {
	*tar.Reader
	CompressionCloser io.Closer
}

CompressedTarReader is a tar.Reader that also wraps the uncompression Reader.

func NewCompressedTarReader

func NewCompressedTarReader(rs io.ReadSeeker) (*CompressedTarReader, error)

NewCompressedTarReader creates a struct compatible with tar.Reader reading from uncompressed or compressed input. Compressed input type is guessed based on the magic on the input.

func (*CompressedTarReader) Close

func (ctr *CompressedTarReader) Close() error

Close a CompressedTarReader. Unlike regular tar.Reader, the compression algorithm might need Close to be called to dispose resources (like external process execution).

type Delta

type Delta struct {
	Path  string
	Error error
	// contains filtered or unexported fields
}

Delta represents a delta file between two other files. If Error is present, it indicates that the delta couldn't be created.

func CreateDeltasForManifest

func CreateDeltasForManifest(manifest, statedir string, from, to uint32, numWorkers int) ([]Delta, error)

CreateDeltasForManifest creates all delta files between the previous and current version of the supplied manifest. Returns a list of deltas (which contains information about individual delta errors). Returns error (and no deltas) if it can't assemble the delta list. If number of workers is zero or less, 1 worker is used.

type ExternalReader

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

ExternalReader filters a Reader with an external program. Every time a Read is called, it will read from the output of the program, that reads from the underlying reader.

func NewExternalReader

func NewExternalReader(r io.Reader, program string, args ...string) (*ExternalReader, error)

NewExternalReader creates an ExternalReader with the passed underlying Reader and the program to execute as filter.

func (*ExternalReader) Close

func (er *ExternalReader) Close() error

Close properly finish the execution of an ExternalReader.

func (*ExternalReader) Read

func (er *ExternalReader) Read(p []byte) (int, error)

type ExternalWriter

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

ExternalWriter filters a Writer with an external program. Every time Write is called, it will write to the program, and then the result written to the underlying Writer.

func NewExternalWriter

func NewExternalWriter(w io.Writer, program string, args ...string) (*ExternalWriter, error)

NewExternalWriter creates an ExternalWriter with the passed underlying Writer and the program to execute as filter.

func (*ExternalWriter) Close

func (ew *ExternalWriter) Close() error

Close properly finish the execution of an ExternalWriter.

func (*ExternalWriter) Write

func (ew *ExternalWriter) Write(p []byte) (int, error)

type File

type File struct {
	Name    string
	Hash    Hashval
	Version uint32

	// flags
	Type     TypeFlag
	Status   StatusFlag
	Modifier ModifierFlag
	Rename   RenameFlag

	// renames
	RenameScore uint16
	RenamePeer  *File

	Info      os.FileInfo
	DeltaPeer *File
}

File represents an entry in a manifest

func (*File) GetFlagString

func (f *File) GetFlagString() (string, error)

GetFlagString returns the flags in a format suitable for the Manifest

func (*File) Present

func (f *File) Present() bool

Present tells if a file is present. Returns false if the file is deleted or ghosted.

type FullfilesInfo

type FullfilesInfo struct {
	NotCompressed    uint
	Skipped          uint
	CompressedCounts map[string]uint
}

FullfilesInfo holds statistics about a fullfile generation.

func CreateFullfiles

func CreateFullfiles(m *Manifest, chrootDir, outputDir string, numWorkers int) (*FullfilesInfo, error)

CreateFullfiles creates full file compressed tars for files in chrootDir and places them in outputDir. It doesn't regenerate full files that already exist. If number of workers is zero or less, 1 worker is used.

type Hash

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

Hash is used to calculate the swupd Hash of a file. Create one with NewHash, use Write method to fill the contents (for regular files), and use Sum to get the final hash.

func NewHash

func NewHash(info *HashFileInfo) (*Hash, error)

NewHash creates a struct that can be used to calculate the "swupd Hash" of a given file. For historical reasons, the hash is constructed as

stat     := file metadata
contents := file contents
HMAC(key, data)

swupd hash = HMAC(HMAC(stat, nil), contents)

The data for the inner HMAC was used for file xattrs, but is not used at the moment.

func (*Hash) Sum

func (h *Hash) Sum() string

Sum returns the string containing the Hash calculated using swupd algorithm of the data previously written.

func (*Hash) Write

func (h *Hash) Write(p []byte) (n int, err error)

Write more data to the hash being calculated.

type HashFileInfo

type HashFileInfo struct {
	Mode     uint32
	UID      uint32
	GID      uint32
	Size     int64
	Linkname string
}

HashFileInfo contains the metadata of a file that is included as part of the swupd hash.

type Hashval

type Hashval int

Hashval is the integer index of the interned hash

func Hashcalc

func Hashcalc(filename string) (Hashval, error)

Hashcalc returns the swupd hash for the given file

func (Hashval) String

func (h Hashval) String() string

type Manifest

type Manifest struct {
	Name         string
	Header       ManifestHeader
	Files        []*File
	DeletedFiles []*File
	// contains filtered or unexported fields
}

Manifest represents a bundle or list of bundles (MoM)

func ParseManifest

func ParseManifest(r io.Reader) (*Manifest, error)

ParseManifest creates a Manifest from an io.Reader.

func ParseManifestFile

func ParseManifestFile(path string) (*Manifest, error)

ParseManifestFile creates a Manifest from file in path.

func (*Manifest) CheckHeaderIsValid

func (m *Manifest) CheckHeaderIsValid() error

CheckHeaderIsValid verifies that all header fields in the manifest are valid.

func (*Manifest) WriteManifest

func (m *Manifest) WriteManifest(w io.Writer) error

WriteManifest writes manifest to a given io.Writer.

func (*Manifest) WriteManifestFile

func (m *Manifest) WriteManifestFile(path string) error

WriteManifestFile writes manifest m to a new file at path.

type ManifestHeader

type ManifestHeader struct {
	Format      uint
	Version     uint32
	Previous    uint32
	FileCount   uint32
	TimeStamp   time.Time
	ContentSize uint64
	Includes    []*Manifest
}

ManifestHeader contains metadata for the manifest

type MoM

type MoM struct {
	Manifest

	// UpdatedBundles has the manifests of bundles that are new to this
	// version. To get a list of all the bundles, use Files from embedded
	// Manifest struct.
	UpdatedBundles []*Manifest

	// FullManifest contains information about all the files in this version.
	FullManifest *Manifest
}

MoM is a manifest that holds references to bundle manifests.

func CreateManifests

func CreateManifests(version uint32, minVersion uint32, format uint, statedir string) (*MoM, error)

CreateManifests creates update manifests for changed and added bundles for <version>

type ModifierFlag

type ModifierFlag uint8

ModifierFlag describes specific characteristics of a file, used later by swupd client when deciding how to update it. It matches the third byte in the flags field.

const (
	ModifierUnset ModifierFlag = iota
	ModifierConfig
	ModifierState
	ModifierBoot
)

Valid values for ModifierFlag.

type PackEntry

type PackEntry struct {
	File   *File
	State  PackState
	Reason string
}

PackEntry describes a file that was considered to be in a pack.

type PackInfo

type PackInfo struct {
	FullfileCount uint64
	DeltaCount    uint64

	// Entries contains all the files considered for packing and details about its presence in
	// the pack.
	Entries []PackEntry

	// Warnings contains the issues found. These are not considered errors since the pack could
	// finish by working around the issue, e.g. if file not found in chroot, try to get it from
	// the fullfiles.
	Warnings []string
}

PackInfo contains detailed information about a pack written.

func CreatePack

func CreatePack(name string, fromVersion, toVersion uint32, outputDir, chrootDir string, numWorkers int) (*PackInfo, error)

CreatePack creates the pack file for a specific bundle between two versions. The pack is written in the TO version subdirectory of outputDir (e.g. a pack from 10 to 20 is written to "www/20"). Empty packs will lead to not creating the pack. Multiple workers are used to parallelize delta creation. If number of workers is zero or less, 1 worker is used.

func WritePack

func WritePack(w io.Writer, fromManifest, toManifest *Manifest, outputDir, chrootDir string, numWorkers int) (info *PackInfo, err error)

WritePack writes the pack between two Manifests, or a zero pack if fromManifest is nil. The toManifest should always be non nil. The outputDir is used to pick deltas and fullfiles. If not empty, chrootDir is tried first as a fast alternative to decompressing the fullfiles. Multiple workers are used to parallelize delta creation. If number of workers is zero or less, 1 worker is used.

func (PackInfo) Empty

func (info PackInfo) Empty() bool

Empty tells if the pack has contents or not. Packs without contents are not generated.

type PackState

type PackState int

PackState describes whether and how a file was packed.

const (
	NotPacked PackState = iota
	PackedDelta
	PackedFullfile
)

Files can be not packed, packed as a delta or packed as a fullfile.

func (PackState) String

func (state PackState) String() string

type RenameFlag

type RenameFlag uint8

RenameFlag describes the third position in the flag string and was used to represent a rename flag (deprecated) and is now used to represent a mixer-generated manifest to be merged with an upstream manifest via client-side mixer integration

const (
	RenameUnset RenameFlag = iota
	RenameSet
	MixManifest
)

Valid values for RenameFlag

type StatusFlag

type StatusFlag uint8

StatusFlag describes whether a manifest entry is present or not. It matches the second byte in the flags field.

const (
	StatusUnset StatusFlag = iota
	StatusDeleted
	StatusGhosted
)

Valid values for StatusFlag.

func (StatusFlag) String

func (s StatusFlag) String() string

type TypeFlag

type TypeFlag uint8

TypeFlag describes the file type of a manifest entry. It matches the first byte in the flags field.

const (
	TypeUnset TypeFlag = iota
	TypeFile
	TypeDirectory
	TypeLink
	TypeManifest
)

Valid values for TypeFlag.

func (TypeFlag) String

func (t TypeFlag) String() string

type UpdateInfo

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

UpdateInfo contains the meta information for the current update

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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