cpio

package
v11.0.0-...-c252e5c Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2018 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const Trailer = "TRAILER!!!"

Trailer is the name of the trailer record.

Variables

View Source
var (
	Debug = func(string, ...interface{}) {}
)
View Source
var TrailerRecord = StaticRecord(nil, Info{Name: Trailer})

TrailerRecord is the last record in any CPIO archive.

Functions

func AllEqual

func AllEqual(r []Record, s []Record) bool

func Concat

func Concat(w RecordWriter, r RecordReader, transform func(Record) Record) error

Concat reads files from r one at a time, and writes them to w.

func CreateFile

func CreateFile(f Record) error

func CreateFileInRoot

func CreateFileInRoot(f Record, rootDir string) error

func Equal

func Equal(r Record, s Record) bool

func ForEachRecord

func ForEachRecord(rr RecordReader, fun func(Record) error) error

ForEachRecord reads every record from r and applies f.

func LSInfoFromRecord

func LSInfoFromRecord(rec Record) ls.FileInfo

LSInfoFromRecord converts a Record to be usable with the ls package for listing files.

func MakeAllReproducible

func MakeAllReproducible(files []Record)

MakeAllReproducible makes all given records reproducible as in MakeReproducible.

func NewLazyFile

func NewLazyFile(name string) io.ReaderAt

func Normalize

func Normalize(path string) string

Normalize normalizes path to be relative to /.

func Passthrough

func Passthrough(r RecordReader, w RecordWriter) error

Passthrough copies from a RecordReader to a RecordWriter It processes one record at a time to minimize the memory footprint.

func ReaderAtEqual

func ReaderAtEqual(r1, r2 io.ReaderAt) bool

func WriteRecords

func WriteRecords(w RecordWriter, files []Record) error

WriteRecords writes multiple records.

func WriteTrailer

func WriteTrailer(w RecordWriter) error

WriteTrailer writes the trailer record.

Types

type Archive

type Archive struct {
	// Files is a map of relative archive path -> record.
	Files map[string]Record

	// Order is a list of relative archive paths and represents the order
	// in which Files were added.
	Order []string
}

Archive implements RecordWriter and is an in-memory list of files.

Archive.Reader returns a RecordReader for this archive.

func ArchiveFromRecords

func ArchiveFromRecords(rs []Record) *Archive

func InMemArchive

func InMemArchive() *Archive

InMemArchive returns an in-memory file archive.

func ReadArchive

func ReadArchive(rr RecordReader) (*Archive, error)

ReadArchive reads the entire archive in-memory and makes it accessible by paths.

func (*Archive) Contains

func (a *Archive) Contains(r Record) bool

Contains returns true if a record matching r is in the archive.

func (*Archive) Empty

func (a *Archive) Empty() bool

Empty returns whether the archive has any files in it.

func (*Archive) Get

func (a *Archive) Get(path string) (Record, bool)

func (*Archive) Reader

func (a *Archive) Reader() RecordReader

Reader returns a RecordReader for the archive that starts at the first record.

func (*Archive) String

func (a *Archive) String() string

String implements fmt.Stringer.

String lists files like ls would.

func (*Archive) WriteRecord

func (a *Archive) WriteRecord(r Record) error

WriteRecord implements RecordWriter and adds a record to the archive.

type DedupWriter

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

DedupWriter is a RecordWriter that does not write more than one record with the same path.

There seems to be no harm done in stripping duplicate names when the record is written, and lots of harm done if we don't do it.

func (*DedupWriter) WriteRecord

func (dw *DedupWriter) WriteRecord(rec Record) error

WriteRecord implements RecordWriter.

If rec.Name was already seen once before, it will not be written again and WriteRecord returns nil.

type EOFReader

type EOFReader struct {
	RecordReader
}

EOFReader is a RecordReader that converts the Trailer record to io.EOF.

func (EOFReader) ReadRecord

func (r EOFReader) ReadRecord() (Record, error)

ReadRecord implements RecordReader.

ReadRecord returns io.EOF when the record name is TRAILER!!!.

type Info

type Info struct {
	Ino      uint64
	Mode     uint64
	UID      uint64
	GID      uint64
	NLink    uint64
	MTime    uint64
	FileSize uint64
	Dev      uint64
	Major    uint64
	Minor    uint64
	Rmajor   uint64
	Rminor   uint64
	Name     string
}

Info holds metadata about files.

func (Info) String

func (i Info) String() string

type Record

type Record struct {
	// ReaderAt contains the content of this CPIO record.
	io.ReaderAt

	// Info is metadata describing the CPIO record.
	Info
}

Record represents a CPIO record, which represents a Unix file.

func CharDev

func CharDev(name string, perm uint64, rmajor, rminor uint64) Record

CharDev returns a character device record at name.

func Directory

func Directory(name string, mode uint64) Record

Directory returns a directory record at name.

func GetRecord

func GetRecord(path string) (Record, error)

func MakeReproducible

func MakeReproducible(r Record) Record

MakeReproducible changes any fields in a Record such that if we run cpio again, with the same files presented to it in the same order, and those files have unchanged contents, the cpio file it produces will be bit-for-bit identical. This is an essential property for firmware-embedded payloads.

func ReadAllRecords

func ReadAllRecords(rr RecordReader) ([]Record, error)

ReadAllRecords returns all records in `r` in the order in which they were read.

func StaticFile

func StaticFile(name string, content string, perm uint64) Record

func StaticRecord

func StaticRecord(contents []byte, info Info) Record
func Symlink(name string, target string) Record

Symlink returns a symlink record at name pointing to target.

func (Record) String

func (r Record) String() string

String implements a fmt.Stringer for Record.

String returns a string formatted like `ls` would format it.

type RecordFormat

type RecordFormat interface {
	Reader(r io.ReaderAt) RecordReader
	Writer(w io.Writer) RecordWriter
}

A RecordFormat gives readers and writers for dealing with archives from io objects.

var (
	// Newc is the newc CPIO record format.
	Newc RecordFormat = newc{/* contains filtered or unexported fields */}
)

func Format

func Format(name string) (RecordFormat, error)

Format returns the RecordFormat with that name, if it exists.

type RecordReader

type RecordReader interface {
	ReadRecord() (Record, error)
}

A RecordReader reads one record from an archive.

type RecordWriter

type RecordWriter interface {
	WriteRecord(Record) error
}

A RecordWriter writes one record to an archive.

func NewDedupWriter

func NewDedupWriter(rw RecordWriter) RecordWriter

NewDedupWriter returns a new deduplicating rw.

Jump to

Keyboard shortcuts

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