swupd

package
v6.1.4+incompatible Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2019 License: Apache-2.0 Imports: 29 Imported by: 12

Documentation

Index

Constants

View Source
const IndexBundle = "os-core-update-index"

IndexBundle defines the name of the bundle that contains index information about the current update

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, bsdiffLog *log.Logger) 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 CreateBsdiffLogger

func CreateBsdiffLogger(stateDir string) (*log.Logger, *os.File, error)

CreateBsdiffLogger creates a logger for the bsdiff_errors.log file at the directory specified by stateDir.

func FilenameBlacklisted

func FilenameBlacklisted(fname string) bool

FilenameBlacklisted checks for illegal characters in filename

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 BundleHeader

type BundleHeader struct {
	Title        string
	Description  string
	Status       string
	Capabilities string
	Maintainer   string
}

BundleHeader describes the meta information of a bundle

type BundleInfo

type BundleInfo struct {
	Name             string
	Filename         string
	Header           BundleHeader
	DirectIncludes   []string
	OptionalIncludes []string
	DirectPackages   map[string]bool
	AllPackages      map[string]bool
	Files            map[string]bool
}

BundleInfo describes the JSON object to be read from the *-info files

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, bsdiffLog *log.Logger) ([]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.

func CreateManifestDeltas

func CreateManifestDeltas(statedir string, fromManifest, toManifest *Manifest, numWorkers int) ([]Delta, error)

CreateManifestDeltas creates the delta manifest files for manifests in the from and to version of the referenced MoMs. Returns a list of deltas containing information on errors encountered during the delta generation process or an error (and no deltas list) if it can't create the deltas.

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, compression []string) (*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
	BundleInfo   BundleInfo
}

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) AppendFile

func (m *Manifest) AppendFile(file *File)

AppendFile appends a file to the manifest and updates the ContentSize

func (*Manifest) CheckHeaderIsValid

func (m *Manifest) CheckHeaderIsValid() error

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

func (*Manifest) GetBundleInfo

func (m *Manifest) GetBundleInfo(stateDir, path string) error

GetBundleInfo loads the BundleInfo member of m from the bundle-info file at path

func (*Manifest) GetRecursiveIncludes

func (m *Manifest) GetRecursiveIncludes() []*Manifest

GetRecursiveIncludes returns a list of all recursively included bundles for the given manifest.

func (*Manifest) ReadIncludesFromBundleInfo

func (m *Manifest) ReadIncludesFromBundleInfo(bundles []*Manifest) error

ReadIncludesFromBundleInfo sets the Header.Includes field for the given manifest.

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
	MinVersion  uint32
	FileCount   uint32
	TimeStamp   time.Time
	ContentSize uint64
	Includes    []*Manifest
	Optional    []*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, previous, minVersion uint32, format uint, statedir string, numWorkers int) (*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) (*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.

func WritePack

func WritePack(w io.Writer, fromManifest, toManifest *Manifest, outputDir, chrootDir string) (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.

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
	StatusExperimental
)

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
	// TODO: IManifests are deprecated. Remove them on format 30
	TypeIManifest
)

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