Documentation
¶
Index ¶
- Constants
- Variables
- func CollectUsedKeywords(dh *DirectoryHierarchy) []string
- func Debugf(format string, a ...interface{}) (n int, err error)
- func KeyValEqual(a, b KeyVal) bool
- func Unvis(src string) (string, error)
- func Vis(src string) (string, error)
- type DifferenceType
- type DirectoryHierarchy
- type Entry
- type EntryType
- type ExcludeFunc
- type InodeDelta
- type KeyDelta
- type KeyVal
- type KeyVals
- type Keyword
- type KeywordFunc
- type Streamer
Examples ¶
Constants ¶
const ( // VersionMajor is for an API incompatible changes VersionMajor = 0 // VersionMinor is for functionality in a backwards-compatible manner VersionMinor = 3 // VersionPatch is for backwards-compatible bug fixes VersionPatch = 0 // VersionDev indicates development branch. Releases will be empty string. VersionDev = "-dev" )
Variables ¶
var ( // DefaultKeywords has the several default keyword producers (uid, gid, // mode, nlink, type, size, mtime) DefaultKeywords = []string{ "size", "type", "uid", "gid", "mode", "link", "nlink", "time", } // DefaultTarKeywords has keywords that should be used when creating a manifest from // an archive. Currently, evaluating the # of hardlinks has not been implemented yet DefaultTarKeywords = []string{ "size", "type", "uid", "gid", "mode", "link", "tar_time", } // BsdKeywords is the set of keywords that is only in the upstream FreeBSD mtree BsdKeywords = []string{ "cksum", "device", "flags", "ignore", "gid", "gname", "link", "md5", "md5digest", "mode", "nlink", "nochange", "optional", "ripemd160digest", "rmd160", "rmd160digest", "sha1", "sha1digest", "sha256", "sha256digest", "sha384", "sha384digest", "sha512", "sha512digest", "size", "tags", "time", "type", "uid", "uname", } // SetKeywords is the default set of keywords calculated for a `/set` SpecialType SetKeywords = []string{ "uid", "gid", } // KeywordFuncs is the map of all keywords (and the functions to produce them) KeywordFuncs = map[string]KeywordFunc{ "size": sizeKeywordFunc, "type": typeKeywordFunc, "time": timeKeywordFunc, "link": linkKeywordFunc, "uid": uidKeywordFunc, "gid": gidKeywordFunc, "nlink": nlinkKeywordFunc, "uname": unameKeywordFunc, "mode": modeKeywordFunc, "cksum": cksumKeywordFunc, "md5": hasherKeywordFunc("md5digest", md5.New), "md5digest": hasherKeywordFunc("md5digest", md5.New), "rmd160": hasherKeywordFunc("ripemd160digest", ripemd160.New), "rmd160digest": hasherKeywordFunc("ripemd160digest", ripemd160.New), "ripemd160digest": hasherKeywordFunc("ripemd160digest", ripemd160.New), "sha1": hasherKeywordFunc("sha1digest", sha1.New), "sha1digest": hasherKeywordFunc("sha1digest", sha1.New), "sha256": hasherKeywordFunc("sha256digest", sha256.New), "sha256digest": hasherKeywordFunc("sha256digest", sha256.New), "sha384": hasherKeywordFunc("sha384digest", sha512.New384), "sha384digest": hasherKeywordFunc("sha384digest", sha512.New384), "sha512": hasherKeywordFunc("sha512digest", sha512.New), "sha512digest": hasherKeywordFunc("sha512digest", sha512.New), "flags": flagsKeywordFunc, "tar_time": tartimeKeywordFunc, "xattr": xattrKeywordFunc, "xattrs": xattrKeywordFunc, } )
var DebugOutput = os.Stderr
DebugOutput is the where DEBUG output is written
var Version = fmt.Sprintf("%d.%d.%d%s", VersionMajor, VersionMinor, VersionPatch, VersionDev)
Version is the specification version that the package types support.
Functions ¶
func CollectUsedKeywords ¶
func CollectUsedKeywords(dh *DirectoryHierarchy) []string
CollectUsedKeywords collects and returns all the keywords used in a a DirectoryHierarchy
func Debugf ¶
Debugf does formatted output to DebugOutput, only if DEBUG environment variable is set
func KeyValEqual ¶ added in v0.2.1
KeyValEqual returns whether two KeyVals are equivalent. This takes care of certain odd cases such as tar_mtime, and should be used over using == comparisons directly unless you really know what you're doing.
Types ¶
type DifferenceType ¶ added in v0.2.1
type DifferenceType string
DifferenceType represents the type of a discrepancy encountered for an object. This is also used to represent discrepancies between keys for objects.
const ( // Missing represents a discrepancy where the object is present in // the @old manifest but is not present in the @new manifest. Missing DifferenceType = "missing" // Extra represents a discrepancy where the object is not present in // the @old manifest but is present in the @new manifest. Extra DifferenceType = "extra" // Modified represents a discrepancy where the object is present in // both the @old and @new manifests, but one or more of the keys // have different values (or have not been set in one of the // manifests). Modified DifferenceType = "modified" )
type DirectoryHierarchy ¶
type DirectoryHierarchy struct {
Entries []Entry
}
DirectoryHierarchy is the mapped structure for an mtree directory hierarchy spec
func ParseSpec ¶
func ParseSpec(r io.Reader) (*DirectoryHierarchy, error)
ParseSpec reads a stream of an mtree specification, and returns the DirectoryHierarchy
func Walk ¶
func Walk(root string, exlcudes []ExcludeFunc, keywords []string) (*DirectoryHierarchy, error)
Walk from root directory and assemble the DirectoryHierarchy. excludes provided are used to skip paths. keywords are the set to collect from the walked paths. The recommended default list is DefaultKeywords.
type Entry ¶
type Entry struct {
Parent *Entry // up
Children []*Entry // down
Prev, Next *Entry // left, right
Set *Entry // current `/set` for additional keywords
Pos int // order in the spec
Raw string // file or directory name
Name string // file or directory name
Keywords []string // TODO(vbatts) maybe a keyword typed set of values?
Type EntryType
}
Entry is each component of content in the mtree spec file
func (Entry) AllKeys ¶ added in v0.2.1
AllKeys returns the full set of KeyVals for the given entry, based on the /set keys as well as the entry-local keys. Entry-local keys always take precedence.
func (Entry) Ascend ¶
Ascend gets the parent of an Entry. Serves mainly to maintain readability when traversing up and down an Entry tree
func (Entry) Descend ¶
Descend searches thru an Entry's children to find the Entry associated with `filename`. Directories are stored at the end of an Entry's children so do a traverse backwards. If you descend to a "."
func (Entry) Find ¶
Find is a wrapper around Descend that takes in a whole string path and tries to find that Entry
type EntryType ¶
type EntryType int
EntryType are the formats of lines in an mtree spec file
const ( SignatureType EntryType = iota // first line of the file, like `#mtree v2.0` BlankType // blank lines are ignored CommentType // Lines beginning with `#` are ignored SpecialType // line that has `/` prefix issue a "special" command (currently only /set and /unset) RelativeType // if the first white-space delimited word does not have a '/' in it. Options/keywords are applied. DotDotType // .. - A relative path step. keywords/options are ignored FullType // if the first word on the line has a `/` after the first character, it interpretted as a file pathname with options )
The types of lines to be found in an mtree spec file
type ExcludeFunc ¶
ExcludeFunc is the type of function called on each path walked to determine whether to be excluded from the assembled DirectoryHierarchy. If the func returns true, then the path is not included in the spec.
type InodeDelta ¶ added in v0.2.1
type InodeDelta struct {
// contains filtered or unexported fields
}
InodeDelta Represents a discrepancy in a filesystem object between two DirectoryHierarchy manifests. Discrepancies are caused by entries only present in one manifest [Missing, Extra], keys only present in one of the manifests Modified or a difference between the keys of the same object in both manifests Modified.
func Check ¶
func Check(root string, dh *DirectoryHierarchy, keywords []string) ([]InodeDelta, error)
Check a root directory path against the DirectoryHierarchy, regarding only the available keywords from the list and each entry in the hierarchy. If keywords is nil, the check all present in the DirectoryHierarchy
This is equivalent to creating a new DirectoryHierarchy with Walk(root, nil, keywords) and then doing a Compare(dh, newDh, keywords).
Example ¶
dh, err := Walk(".", nil, append(DefaultKeywords, "sha1"))
if err != nil {
// handle error ...
}
res, err := Check(".", dh, nil)
if err != nil {
// handle error ...
}
if len(res) > 0 {
// handle failed validity ...
}
func Compare ¶ added in v0.2.1
func Compare(oldDh, newDh *DirectoryHierarchy, keys []string) ([]InodeDelta, error)
Compare compares two directory hierarchy manifests, and returns the list of discrepancies between the two. All of the entries in the manifest are considered, with differences being generated for RelativeType and FullType entries. Differences in structure (such as the way /set and /unset are written) are not considered to be discrepancies. The list of differences are all filesystem objects.
keys controls which keys will be compared, but if keys is nil then all possible keys will be compared between the two manifests (allowing for missing entries and the like). A missing or extra key is treated as a Modified type.
NB: The order of the parameters matters (old, new) because Extra and
Missing are considered as different discrepancy types.
func TarCheck ¶
func TarCheck(tarDH, dh *DirectoryHierarchy, keywords []string) ([]InodeDelta, error)
TarCheck is the tar equivalent of checking a file hierarchy spec against a tar stream to determine if files have been changed. This is precisely equivalent to Compare(dh, tarDH, keywords).
func (InodeDelta) Diff ¶ added in v0.2.1
func (i InodeDelta) Diff() []KeyDelta
Diff returns the set of key discrepancies between the two manifests for the specific inode. If the DifferenceType of the inode is not Modified, then Diff returns nil.
func (InodeDelta) MarshalJSON ¶ added in v0.2.1
func (i InodeDelta) MarshalJSON() ([]byte, error)
MarshalJSON creates a JSON-encoded version of InodeDelta.
func (InodeDelta) New ¶ added in v0.2.1
func (i InodeDelta) New() *Entry
New returns the value of the inode Entry in the "new" DirectoryHierarchy (as determined by the ordering of parameters to Compare).
func (InodeDelta) Old ¶ added in v0.2.1
func (i InodeDelta) Old() *Entry
Old returns the value of the inode Entry in the "old" DirectoryHierarchy (as determined by the ordering of parameters to Compare).
func (InodeDelta) Path ¶ added in v0.2.1
func (i InodeDelta) Path() string
Path returns the path to the inode (relative to the root of the DirectoryHierarchy manifests).
func (InodeDelta) String ¶ added in v0.2.1
func (i InodeDelta) String() string
String returns a "pretty" formatting for InodeDelta.
func (InodeDelta) Type ¶ added in v0.2.1
func (i InodeDelta) Type() DifferenceType
Type returns the type of discrepancy encountered when comparing this inode between the two DirectoryHierarchy manifests.
type KeyDelta ¶ added in v0.2.1
type KeyDelta struct {
// contains filtered or unexported fields
}
KeyDelta Represents a discrepancy in a key for a particular filesystem object between two DirectoryHierarchy manifests. Discrepancies are caused by keys only present in one manifest [Missing, Extra] or a difference between the keys of the same object in both manifests Modified. A set of these is returned with InodeDelta.Diff().
func (KeyDelta) MarshalJSON ¶ added in v0.2.1
MarshalJSON creates a JSON-encoded version of KeyDelta.
func (KeyDelta) Name ¶ added in v0.2.1
Name returns the name (the key) of the KeyDeltaVal entry in the DirectoryHierarchy.
func (KeyDelta) New ¶ added in v0.2.1
New returns the value of the KeyDeltaVal entry in the "new" DirectoryHierarchy (as determined by the ordering of parameters to Compare). Returns nil if there was no entry in the "old" DirectoryHierarchy.
func (KeyDelta) Old ¶ added in v0.2.1
Old returns the value of the KeyDeltaVal entry in the "old" DirectoryHierarchy (as determined by the ordering of parameters to Compare). Returns nil if there was no entry in the "old" DirectoryHierarchy.
func (KeyDelta) Type ¶ added in v0.2.1
func (k KeyDelta) Type() DifferenceType
Type returns the type of discrepancy encountered when comparing this key between the two DirectoryHierarchy manifests' relevant inode entry.
type KeyVal ¶
type KeyVal string
KeyVal is a "keyword=value"
func (KeyVal) ChangeValue ¶
ChangeValue changes the value of a KeyVal
func (KeyVal) KeywordSuffix ¶
KeywordSuffix is really only used for xattr, as the keyword is a prefix to the xattr "namespace.key"
type KeyVals ¶
type KeyVals []KeyVal
KeyVals is a list of KeyVal
func MergeSet ¶
MergeSet takes the current setKeyVals, and then applies the entryKeyVals such that the entry's values win. The union is returned.
func NewKeyVals ¶
NewKeyVals constructs a list of KeyVal from the list of strings, like "keyword=value"
type Keyword ¶
type Keyword string
Keyword is the string name of a keyword, with some convenience functions for determining whether it is a default or bsd standard keyword.
type KeywordFunc ¶
KeywordFunc is the type of a function called on each file to be included in a DirectoryHierarchy, that will produce the string output of the keyword to be included for the file entry. Otherwise, empty string. io.Reader `r` is to the file stream for the file payload. While this function takes an io.Reader, the caller needs to reset it to the beginning for each new KeywordFunc
type Streamer ¶
type Streamer interface {
io.ReadCloser
Hierarchy() (*DirectoryHierarchy, error)
}
Streamer creates a file hierarchy out of a tar stream
Example ¶
fh, err := os.Open("./testdata/test.tar")
if err != nil {
// handle error ...
}
str := NewTarStreamer(fh, nil)
if err := extractTar("/tmp/dir", str); err != nil {
// handle error ...
}
dh, err := str.Hierarchy()
if err != nil {
// handle error ...
}
res, err := Check("/tmp/dir/", dh, nil)
if err != nil {
// handle error ...
}
if len(res) > 0 {
// handle validation issue ...
}