-d: exclude non-directories

Adding flag, and supporting functionality for exluding entries that are
non-directories

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
Vincent Batts 2016-11-17 22:43:02 -05:00
parent 353436a031
commit c0a5cb25ec
Signed by: vbatts
GPG key ID: 10937E57733F1362
7 changed files with 117 additions and 15 deletions

View file

@ -16,11 +16,12 @@ import (
var (
// Flags common with mtree(8)
flCreate = flag.Bool("c", false, "create a directory hierarchy spec")
flFile = flag.String("f", "", "directory hierarchy spec to validate")
flPath = flag.String("p", "", "root path that the hierarchy spec is relative to")
flAddKeywords = flag.String("K", "", "Add the specified (delimited by comma or space) keywords to the current set of keywords")
flUseKeywords = flag.String("k", "", "Use the specified (delimited by comma or space) keywords as the current set of keywords")
flCreate = flag.Bool("c", false, "create a directory hierarchy spec")
flFile = flag.String("f", "", "directory hierarchy spec to validate")
flPath = flag.String("p", "", "root path that the hierarchy spec is relative to")
flAddKeywords = flag.String("K", "", "Add the specified (delimited by comma or space) keywords to the current set of keywords")
flUseKeywords = flag.String("k", "", "Use the specified (delimited by comma or space) keywords as the current set of keywords")
flDirectoryOnly = flag.Bool("d", false, "Ignore everything except directory type files")
// Flags unique to gomtree
flListKeywords = flag.Bool("list-keywords", false, "List the keywords available")
@ -201,6 +202,12 @@ func app() error {
rootPath = *flPath
}
excludes := []mtree.ExcludeFunc{}
// -d
if *flDirectoryOnly {
excludes = append(excludes, mtree.ExcludeNonDirectories)
}
// -T <tar file>
if *flTar != "" {
var input io.Reader
@ -214,7 +221,7 @@ func app() error {
defer fh.Close()
input = fh
}
ts := mtree.NewTarStreamer(input, currentKeywords)
ts := mtree.NewTarStreamer(input, excludes, currentKeywords)
if _, err := io.Copy(ioutil.Discard, ts); err != nil && err != io.EOF {
return err
@ -229,7 +236,7 @@ func app() error {
}
} else {
// with a root directory
stateDh, err = mtree.Walk(rootPath, nil, currentKeywords)
stateDh, err = mtree.Walk(rootPath, excludes, currentKeywords)
if err != nil {
return err
}