record

package
v0.0.0-...-c5655c4 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2017 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package record defines interfaces for syscall records, executor and encoder/decoder. It also has implementations of all syscall records, gob encoder/decoder, and a common executor and the stdout executor.

Index

Constants

View Source
const (
	// DefaultCreateMode - create file with these default permissions
	DefaultCreateMode os.FileMode = 0777

	// XattrPrefix is a prefix that is used for safely storing file attributes and extended attributes
	// as extended attributes in the user namespace.
	XattrPrefix string = "user.com.clusterhq.attributes."
)
View Source
const (
	// AsyncExec is executed asynchronously(e.x. pwrie)
	AsyncExec ExecType = iota
	// SyncExec is executed synchronously(e.x. create dir)
	SyncExec
	// DelayExec is executed at the end of all asynchronous records are executed(e.x. setmtime)
	DelayExec

	// TypeMkdir defines the type ID
	TypeMkdir Type = iota
	// TypePwrite defines the type ID
	TypePwrite
	// TypeHardlink defines the type ID
	TypeHardlink
	// TypeSymlink defines the type ID
	TypeSymlink
	// TypeTruncate defines the type ID
	TypeTruncate
	// TypeChown defines the type ID
	TypeChown
	// TypeCreate defines the type ID
	TypeCreate
	// TypeRemove defines the type ID
	TypeRemove
	// TypeSetxattr defines the type ID
	TypeSetxattr
	// TypeRmxattr defines the type ID
	TypeRmxattr
	// TypeRename defines the type ID
	TypeRename
	// TypeMknod defines the type ID
	TypeMknod
	// TypeChmod defines the type ID
	TypeChmod
	// TypeSetmtime defines the type ID
	TypeSetmtime

	// TypeEOT defines the type ID
	TypeEOT
)

Variables

This section is empty.

Functions

func Send

func Send(rec Record, records chan<- Record, hf dlhash.Factory) error

Send pushs a record into the channel which is consumed by a reader who send the records to the wire. Checksum is calculated before putting the record into the channel so checksum is transferred along.

func VerifyChksum

func VerifyChksum(rec Record, hf dlhash.Factory) (bool, error)

VerifyChksum verifies the checksum embedded inside the record is the same as a fresh calculation

Types

type Chmod

type Chmod struct {
	Hdr
	Path string
	Mode os.FileMode
}

Chmod represents a record for chmod

func (*Chmod) Chksum

func (rec *Chmod) Chksum(hf dlhash.Factory) ([]byte, error)

Chksum is implementation of Record interface

func (*Chmod) Exec

func (rec *Chmod) Exec(root string) error

Exec is implementation of Record interface

func (*Chmod) ExecType

func (rec *Chmod) ExecType() ExecType

ExecType is implementation of Record interface

func (*Chmod) FromBinary

func (rec *Chmod) FromBinary(src io.Reader) error

FromBinary is implementation of Record interface

func (*Chmod) Key

func (rec *Chmod) Key() string

Key is implementation of Record interface

func (*Chmod) SafeExec

func (rec *Chmod) SafeExec(root string) error

SafeExec is implementation of FakeRecord interface

func (*Chmod) String

func (rec *Chmod) String() string

func (*Chmod) ToBinary

func (rec *Chmod) ToBinary(target io.Writer) error

ToBinary is implementation of Record interface

func (*Chmod) Type

func (rec *Chmod) Type() Type

Type is implementation of Record interface

type Chown

type Chown struct {
	Hdr
	Path string
	UID  string // XXX stored as a name, not ID
	GID  string // XXX stored as a name, not ID
}

Chown represents a record for doing a chown on a file TODO: might get absorbed into SETATTR record later

func (*Chown) Chksum

func (rec *Chown) Chksum(hf dlhash.Factory) ([]byte, error)

Chksum is implementation of Record interface

func (*Chown) Exec

func (rec *Chown) Exec(root string) error

Exec is implementation of Record interface

func (*Chown) ExecType

func (rec *Chown) ExecType() ExecType

ExecType is implementation of Record interface

func (*Chown) FromBinary

func (rec *Chown) FromBinary(src io.Reader) error

FromBinary is implementation of Record interface

func (*Chown) Key

func (rec *Chown) Key() string

Key is implementation of Record interface

func (*Chown) SafeExec

func (rec *Chown) SafeExec(root string) error

SafeExec is implementation of FakeRecord interface

func (*Chown) String

func (rec *Chown) String() string

func (*Chown) ToBinary

func (rec *Chown) ToBinary(target io.Writer) error

ToBinary is implementation of Record interface

func (*Chown) Type

func (rec *Chown) Type() Type

Type is implementation of Record interface

type Create

type Create struct {
	Hdr
	Path string
	Mode os.FileMode
}

Create represents a record for create/open/mkfile

func (*Create) Chksum

func (rec *Create) Chksum(hf dlhash.Factory) ([]byte, error)

Chksum is implementation of Record interface

func (*Create) Exec

func (rec *Create) Exec(root string) error

Exec is implementation of Record interface Creates a new file. Corresponds to 'touch' or 'mkfile', etc.

func (*Create) ExecType

func (rec *Create) ExecType() ExecType

ExecType is implementation of Record interface

func (*Create) FromBinary

func (rec *Create) FromBinary(src io.Reader) error

FromBinary is implementation of Record interface

func (*Create) Key

func (rec *Create) Key() string

Key is implementation of Record interface

func (*Create) SafeExec

func (rec *Create) SafeExec(root string) error

SafeExec is implementation of Record interface Creates a new file. Corresponds to 'touch' or 'mkfile', etc.

func (*Create) String

func (rec *Create) String() string

func (*Create) ToBinary

func (rec *Create) ToBinary(target io.Writer) error

ToBinary is implementation of Record interface

func (*Create) Type

func (rec *Create) Type() Type

Type is implementation of Record interface

type EOT

type EOT struct {
	Hdr
	Name string
}

EOT represents a special record which does nothing to the file system but indicates the end of a transfer

func (*EOT) Chksum

func (rec *EOT) Chksum(hf dlhash.Factory) ([]byte, error)

Chksum is implementation of Record interface

func (*EOT) Exec

func (rec *EOT) Exec(root string) error

Exec is the implementation of Record interface

func (*EOT) ExecType

func (rec *EOT) ExecType() ExecType

ExecType is implementation of Record interface

func (*EOT) FromBinary

func (rec *EOT) FromBinary(src io.Reader) error

FromBinary is implementation of Record interface

func (*EOT) Key

func (rec *EOT) Key() string

Key is implementation of Record interface

func (*EOT) String

func (rec *EOT) String() string

String is the implementation of Record interface

func (*EOT) ToBinary

func (rec *EOT) ToBinary(target io.Writer) error

ToBinary is implementation of Record interface

func (*EOT) Type

func (rec *EOT) Type() Type

Type is implementation of Record interface

type ExecType

type ExecType int

ExecType defines the execution type for each record

type Hardlink struct {
	Hdr
	OldName string
	NewName string
}

Hardlink represents a record for link

func (*Hardlink) Chksum

func (rec *Hardlink) Chksum(hf dlhash.Factory) ([]byte, error)

Chksum is implementation of Record interface

func (*Hardlink) Exec

func (rec *Hardlink) Exec(root string) error

Exec is implementation of Record interface

func (*Hardlink) ExecType

func (rec *Hardlink) ExecType() ExecType

ExecType is implementation of Record interface

func (*Hardlink) FromBinary

func (rec *Hardlink) FromBinary(src io.Reader) error

FromBinary is implementation of Record interface

func (*Hardlink) Key

func (rec *Hardlink) Key() string

Key is implementation of Record interface

func (*Hardlink) String

func (rec *Hardlink) String() string

func (*Hardlink) ToBinary

func (rec *Hardlink) ToBinary(target io.Writer) error

ToBinary is implementation of Record interface

func (*Hardlink) Type

func (rec *Hardlink) Type() Type

Type is implementation of Record interface

type Hdr

type Hdr struct {
	Chksum []byte
}

Hdr has common fields for all records. Note: Export Hdr and Chksum because of GOB.

func (*Hdr) GetChksum

func (h *Hdr) GetChksum() []byte

GetChksum returns the record's checksum

func (*Hdr) SetChksum

func (h *Hdr) SetChksum(chksum []byte)

SetChksum sets the record's checksum

type Mkdir

type Mkdir struct {
	Hdr
	Path string
	Mode os.FileMode
}

Mkdir represents a record for mkdir Note: All record type can be unexported, but GOB needs to register them, so they are exported. Note: All fields are exported because gob only encodes exported fields

func (*Mkdir) Chksum

func (rec *Mkdir) Chksum(hf dlhash.Factory) ([]byte, error)

Chksum is implementation of Record interface

func (*Mkdir) Exec

func (rec *Mkdir) Exec(root string) error

Exec is the implementation of Record interface

func (*Mkdir) ExecType

func (rec *Mkdir) ExecType() ExecType

ExecType is implementation of Record interface

func (*Mkdir) FromBinary

func (rec *Mkdir) FromBinary(src io.Reader) error

FromBinary is implementation of Record interface

func (*Mkdir) Key

func (rec *Mkdir) Key() string

Key is implementation of Record interface

func (*Mkdir) SafeExec

func (rec *Mkdir) SafeExec(root string) error

SafeExec is implementation of FakeRecord interface

func (*Mkdir) String

func (rec *Mkdir) String() string

String is the implementation of Record interface

func (*Mkdir) ToBinary

func (rec *Mkdir) ToBinary(target io.Writer) error

ToBinary is implementation of Record interface

func (*Mkdir) Type

func (rec *Mkdir) Type() Type

Type is implementation of Record interface

type Mknod

type Mknod struct {
	Hdr
	Path string
	Mode uint32
	Dev  int
}

Mknod represent a record for mknod

func (*Mknod) Chksum

func (rec *Mknod) Chksum(hf dlhash.Factory) ([]byte, error)

Chksum is implementation of Record interface

func (*Mknod) Exec

func (rec *Mknod) Exec(root string) error

Exec is implementation of Record interface

func (*Mknod) ExecType

func (rec *Mknod) ExecType() ExecType

ExecType is implementation of Record interface

func (*Mknod) FromBinary

func (rec *Mknod) FromBinary(src io.Reader) error

FromBinary is implementation of Record interface

func (*Mknod) Key

func (rec *Mknod) Key() string

Key is implementation of Record interface

func (*Mknod) SafeExec

func (rec *Mknod) SafeExec(root string) error

SafeExec is implementation of FakeRecord interface

func (*Mknod) String

func (rec *Mknod) String() string

func (*Mknod) ToBinary

func (rec *Mknod) ToBinary(target io.Writer) error

ToBinary is implementation of Record interface

func (Mknod) Type

func (rec Mknod) Type() Type

Type is implementation of Record interface

type Pwrite

type Pwrite struct {
	Hdr
	Path   string
	Data   []byte
	Offset uint64
	Mode   os.FileMode // always zero, kept for compatibility
}

Pwrite represents a record for pwrite

func (*Pwrite) Chksum

func (rec *Pwrite) Chksum(hf dlhash.Factory) ([]byte, error)

Chksum is implementation of Record interface

func (*Pwrite) Exec

func (rec *Pwrite) Exec(root string) error

Exec is implementation of Record interface

func (*Pwrite) ExecType

func (rec *Pwrite) ExecType() ExecType

ExecType is implementation of Record interface

func (*Pwrite) FromBinary

func (rec *Pwrite) FromBinary(src io.Reader) error

FromBinary is implementation of Record interface

func (*Pwrite) Key

func (rec *Pwrite) Key() string

Key is implementation of Record interface

func (*Pwrite) String

func (rec *Pwrite) String() string

func (*Pwrite) ToBinary

func (rec *Pwrite) ToBinary(target io.Writer) error

ToBinary is implementation of Record interface

func (*Pwrite) Type

func (rec *Pwrite) Type() Type

Type is implementation of Record interface

type Record

type Record interface {
	Exec(root string) error
	String() string

	// Key returns a string that can be used to group records that belong to the same object(for example, file path)
	Key() string

	// ExeType returns the execution type of a record
	ExecType() ExecType

	// Type returns the type of a record
	Type() Type

	// ToBinary is the binary encoder which writes the record in binary format
	ToBinary(io.Writer) error

	// FromBinary reads the record from an encode source and populates the record with the data read from the source
	FromBinary(io.Reader) error

	// Chksum returns the checksum of a record.
	// Note: It doesn't set the record's checksum field, so it can be used to recalculate the checksum for
	// verification.
	Chksum(dlhash.Factory) ([]byte, error)

	// SetChksum sets the record's checksum
	SetChksum([]byte)

	// GetChksum returns the record's checksum
	GetChksum() []byte
}

Record defines the function signature for all the common methods implemented for each record type

func NewChmod

func NewChmod(filepath string, mode os.FileMode) Record

NewChmod returns a record object of type chmod from the parameters.

func NewChown

func NewChown(filepath string, uid int, gid int) Record

NewChown returns an record object of type chown from the parameters.

func NewChownByNames

func NewChownByNames(filepath string, uid string, gid string) Record

NewChownByNames returns an record object of type chown from the parameters.

func NewCreate

func NewCreate(path string, mode os.FileMode) Record

NewCreate returns an record object of type create from the parameters

func NewEOT

func NewEOT() Record

NewEOT returns an record object of type EOT

func NewHardlink(oldname string, newname string) Record

NewHardlink returns an record object of type hardlink from the parameters.

func NewMkdir

func NewMkdir(path string, mode os.FileMode) Record

NewMkdir returns an record object of type mkdir from the parameters

func NewMknod

func NewMknod(filepath string, mode uint32, dev int) Record

NewMknod returns an record object of type mknod from the parameters.

func NewPwrite

func NewPwrite(path string, data []byte, offset uint64) Record

NewPwrite returns an record object of type pwrite from the parameters

func NewRemove

func NewRemove(path string) Record

NewRemove returns an record object of type remove from the parameters

func NewRename

func NewRename(oldpath string, newpath string) Record

NewRename returns an record object of type rename from the parameters.

func NewRmXattr

func NewRmXattr(path string, xattr string) Record

NewRmXattr returns an record object of type rmxattr from the parameters.

func NewSetMtime

func NewSetMtime(path string, mtime time.Time) Record

NewSetMtime returns a record object of type setmtime

func NewSetXattr

func NewSetXattr(path string, xattr string, val []byte) Record

NewSetXattr returns an record object of type setxattr from the parameters.

func NewSymlink(oldname string, newname string) Record

NewSymlink returns an record object of type symlink from the parameters.

func NewTruncate

func NewTruncate(filepath string, size int64) Record

NewTruncate returns an record object of type truncate from the parameters.

type Remove

type Remove struct {
	Hdr
	Path string
}

Remove represents a record for removal of file or directory

func (*Remove) Chksum

func (rec *Remove) Chksum(hf dlhash.Factory) ([]byte, error)

Chksum is implementation of Record interface

func (*Remove) Exec

func (rec *Remove) Exec(root string) error

Exec is implementation of Record interface

func (*Remove) ExecType

func (rec *Remove) ExecType() ExecType

ExecType is implementation of Record interface

func (*Remove) FromBinary

func (rec *Remove) FromBinary(src io.Reader) error

FromBinary is implementation of Record interface

func (*Remove) Key

func (rec *Remove) Key() string

Key is implementation of Record interface

func (*Remove) String

func (rec *Remove) String() string

func (*Remove) ToBinary

func (rec *Remove) ToBinary(target io.Writer) error

ToBinary is implementation of Record interface

func (*Remove) Type

func (rec *Remove) Type() Type

Type is implementation of Record interface

type Rename

type Rename struct {
	Hdr
	OldPath string
	NewPath string
}

Rename represents a record for rename

func (*Rename) Chksum

func (rec *Rename) Chksum(hf dlhash.Factory) ([]byte, error)

Chksum is implementation of Record interface

func (*Rename) Exec

func (rec *Rename) Exec(root string) error

Exec is implementation of Record interface TODO: currently not used

func (*Rename) ExecType

func (rec *Rename) ExecType() ExecType

ExecType is implementation of Record interface

func (*Rename) FromBinary

func (rec *Rename) FromBinary(src io.Reader) error

FromBinary is implementation of Record interface

func (*Rename) Key

func (rec *Rename) Key() string

Key is implementation of Record interface

func (*Rename) String

func (rec *Rename) String() string

func (*Rename) ToBinary

func (rec *Rename) ToBinary(target io.Writer) error

ToBinary is implementation of Record interface

func (*Rename) Type

func (rec *Rename) Type() Type

Type is implementation of Record interface

type Rmxattr

type Rmxattr struct {
	Hdr
	Path  string
	Xattr string
}

Rmxattr represents a record for removing extended attribute

func (*Rmxattr) Chksum

func (rec *Rmxattr) Chksum(hf dlhash.Factory) ([]byte, error)

Chksum is implementation of Record interface

func (*Rmxattr) Exec

func (rec *Rmxattr) Exec(root string) error

Exec is implementation of Record interface

func (*Rmxattr) ExecType

func (rec *Rmxattr) ExecType() ExecType

ExecType is implementation of Record interface

func (*Rmxattr) FromBinary

func (rec *Rmxattr) FromBinary(src io.Reader) error

FromBinary is implementation of Record interface

func (*Rmxattr) Key

func (rec *Rmxattr) Key() string

Key is implementation of Record interface

func (*Rmxattr) SafeExec

func (rec *Rmxattr) SafeExec(root string) error

SafeExec is implementation of FakeRecord interface

func (*Rmxattr) String

func (rec *Rmxattr) String() string

func (*Rmxattr) ToBinary

func (rec *Rmxattr) ToBinary(target io.Writer) error

ToBinary is implementation of Record interface

func (*Rmxattr) Type

func (rec *Rmxattr) Type() Type

Type is implementation of Record interface

type SafeRecord

type SafeRecord interface {
	Record
	SafeExec(root string) error
}

SafeRecord is a subtype of Record that has a method for faking security-sensitive operations.

type Setmtime

type Setmtime struct {
	Hdr
	Path  string
	MTime int64
}

Setmtime represents a record for modify time

func (*Setmtime) Chksum

func (rec *Setmtime) Chksum(hf dlhash.Factory) ([]byte, error)

Chksum is implementation of Record interface

func (*Setmtime) Exec

func (rec *Setmtime) Exec(root string) error

Exec is implementation of Record interface

func (*Setmtime) ExecType

func (rec *Setmtime) ExecType() ExecType

ExecType is implementation of Record interface

func (*Setmtime) FromBinary

func (rec *Setmtime) FromBinary(src io.Reader) error

FromBinary is implementation of Record interface

func (*Setmtime) Key

func (rec *Setmtime) Key() string

Key is implementation of Record interface

func (*Setmtime) String

func (rec *Setmtime) String() string

func (*Setmtime) ToBinary

func (rec *Setmtime) ToBinary(target io.Writer) error

ToBinary is implementation of Record interface

func (*Setmtime) Type

func (rec *Setmtime) Type() Type

Type is implementation of Record interface

type Setxattr

type Setxattr struct {
	Hdr
	Path  string
	Xattr string
	Data  []byte
}

Setxattr represents a record for setting extended attribute

func (*Setxattr) Chksum

func (rec *Setxattr) Chksum(hf dlhash.Factory) ([]byte, error)

Chksum is implementation of Record interface

func (*Setxattr) Exec

func (rec *Setxattr) Exec(root string) error

Exec is implementation of Record interface

func (*Setxattr) ExecType

func (rec *Setxattr) ExecType() ExecType

ExecType is implementation of Record interface

func (*Setxattr) FromBinary

func (rec *Setxattr) FromBinary(src io.Reader) error

FromBinary is implementation of Record interface

func (*Setxattr) Key

func (rec *Setxattr) Key() string

Key is implementation of Record interface

func (*Setxattr) SafeExec

func (rec *Setxattr) SafeExec(root string) error

SafeExec is implementation of FakeRecord interface

func (*Setxattr) String

func (rec *Setxattr) String() string

func (*Setxattr) ToBinary

func (rec *Setxattr) ToBinary(target io.Writer) error

ToBinary is implementation of Record interface

func (*Setxattr) Type

func (rec *Setxattr) Type() Type

Type is implementation of Record interface

type Symlink struct {
	Hdr
	OldName string
	NewName string
}

Symlink represents a record for creation of a symlink

func (*Symlink) Chksum

func (rec *Symlink) Chksum(hf dlhash.Factory) ([]byte, error)

Chksum is implementation of Record interface

func (*Symlink) Exec

func (rec *Symlink) Exec(root string) error

Exec is implementation of Record interface Note: code executing this needs to have appropriate permissions (s.a. be run as superuser)

func (*Symlink) ExecType

func (rec *Symlink) ExecType() ExecType

ExecType is implementation of Record interface

func (*Symlink) FromBinary

func (rec *Symlink) FromBinary(src io.Reader) error

FromBinary is implementation of Record interface

func (*Symlink) Key

func (rec *Symlink) Key() string

Key is implementation of Record interface

func (*Symlink) String

func (rec *Symlink) String() string

func (*Symlink) ToBinary

func (rec *Symlink) ToBinary(target io.Writer) error

ToBinary is implementation of Record interface

func (*Symlink) Type

func (rec *Symlink) Type() Type

Type is implementation of Record interface

type Truncate

type Truncate struct {
	Hdr
	Path string
	Size int64
}

Truncate represents a record for truncation of a file

func (*Truncate) Chksum

func (rec *Truncate) Chksum(hf dlhash.Factory) ([]byte, error)

Chksum is implementation of Record interface

func (*Truncate) Exec

func (rec *Truncate) Exec(root string) error

Exec is implementation of Record interface

func (*Truncate) ExecType

func (rec *Truncate) ExecType() ExecType

ExecType is implementation of Record interface

func (*Truncate) FromBinary

func (rec *Truncate) FromBinary(src io.Reader) error

FromBinary is implementation of Record interface

func (*Truncate) Key

func (rec *Truncate) Key() string

Key is implementation of Record interface

func (*Truncate) String

func (rec *Truncate) String() string

func (*Truncate) ToBinary

func (rec *Truncate) ToBinary(target io.Writer) error

ToBinary is implementation of Record interface

func (*Truncate) Type

func (rec *Truncate) Type() Type

Type is implementation of Record interface

type Type

type Type int

Type defines the record type for each record

Jump to

Keyboard shortcuts

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