1
0
Fork 0
mirror of https://github.com/vbatts/go-mtree.git synced 2024-11-25 17:45:39 +00:00

main: add -bsd-keywords

To support either producing or checking manifests that are compatible
with upstream FreeBSD mtree(8) keywords, this flag will only operate on
upstream keywords. Completely ignoring non-upstream keywords, though
printing out an INFO to stderr for information purposes.

Example:
```bash
INFO: ignoring "xattrs" as it is not an upstream keyword

/set type=file nlink=1 mode=0664 uid=1000 gid=100
. size=4096 type=dir mode=0755 nlink=2 time=1469556206.235575511

[...]
```

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
Vincent Batts 2016-07-26 14:31:39 -04:00 committed by Stephen Chung
parent 8e19ce80ec
commit 7b7d96ca78

View file

@ -23,6 +23,7 @@ var (
flListKeywords = flag.Bool("list-keywords", false, "List the keywords available")
flResultFormat = flag.String("result-format", "bsd", "output the validation results using the given format (bsd, json, path)")
flTar = flag.String("T", "", "use tar archive to create or validate a directory hierarchy spec")
flBsdKeywords = flag.Bool("bsd-keywords", false, "only operate on keywords that are supported by upstream mtree(8)")
flDebug = flag.Bool("debug", false, "output debug info to STDERR")
)
@ -96,29 +97,46 @@ func main() {
return
}
var currentKeywords []string
var (
tmpKeywords []string
currentKeywords []string
)
// -k <keywords>
if *flUseKeywords != "" {
currentKeywords = splitKeywordsArg(*flUseKeywords)
if !inSlice("type", currentKeywords) {
currentKeywords = append([]string{"type"}, currentKeywords...)
tmpKeywords = splitKeywordsArg(*flUseKeywords)
if !inSlice("type", tmpKeywords) {
tmpKeywords = append([]string{"type"}, tmpKeywords...)
}
} else {
if *flTar != "" {
currentKeywords = mtree.DefaultTarKeywords[:]
tmpKeywords = mtree.DefaultTarKeywords[:]
} else {
currentKeywords = mtree.DefaultKeywords[:]
tmpKeywords = mtree.DefaultKeywords[:]
}
}
// -K <keywords>
if *flAddKeywords != "" {
for _, kw := range splitKeywordsArg(*flAddKeywords) {
if !inSlice(kw, currentKeywords) {
currentKeywords = append(currentKeywords, kw)
if !inSlice(kw, tmpKeywords) {
tmpKeywords = append(tmpKeywords, kw)
}
}
}
// -bsd-keywords
if *flBsdKeywords {
for _, k := range tmpKeywords {
if mtree.Keyword(k).Bsd() {
currentKeywords = append(currentKeywords, k)
} else {
fmt.Fprintf(os.Stderr, "INFO: ignoring %q as it is not an upstream keyword\n", k)
}
}
} else {
currentKeywords = tmpKeywords
}
// -f <file>
var dh *mtree.DirectoryHierarchy
if *flFile != "" && !*flCreate {