From 919d71c1058b75672cac768ea24db1731dffc930 Mon Sep 17 00:00:00 2001 From: Vincent Batts Date: Tue, 26 Jul 2016 14:31:39 -0400 Subject: [PATCH] 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 --- cmd/gomtree/main.go | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/cmd/gomtree/main.go b/cmd/gomtree/main.go index d520dba..8af7f55 100644 --- a/cmd/gomtree/main.go +++ b/cmd/gomtree/main.go @@ -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 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 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 var dh *mtree.DirectoryHierarchy if *flFile != "" && !*flCreate {