mirror of
https://github.com/vbatts/go-mtree.git
synced 2024-11-29 11:35:40 +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:
parent
8e19ce80ec
commit
7b7d96ca78
1 changed files with 26 additions and 8 deletions
|
@ -23,6 +23,7 @@ var (
|
||||||
flListKeywords = flag.Bool("list-keywords", false, "List the keywords available")
|
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)")
|
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")
|
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")
|
flDebug = flag.Bool("debug", false, "output debug info to STDERR")
|
||||||
)
|
)
|
||||||
|
@ -96,29 +97,46 @@ func main() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var currentKeywords []string
|
var (
|
||||||
|
tmpKeywords []string
|
||||||
|
currentKeywords []string
|
||||||
|
)
|
||||||
// -k <keywords>
|
// -k <keywords>
|
||||||
if *flUseKeywords != "" {
|
if *flUseKeywords != "" {
|
||||||
currentKeywords = splitKeywordsArg(*flUseKeywords)
|
tmpKeywords = splitKeywordsArg(*flUseKeywords)
|
||||||
if !inSlice("type", currentKeywords) {
|
if !inSlice("type", tmpKeywords) {
|
||||||
currentKeywords = append([]string{"type"}, currentKeywords...)
|
tmpKeywords = append([]string{"type"}, tmpKeywords...)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if *flTar != "" {
|
if *flTar != "" {
|
||||||
currentKeywords = mtree.DefaultTarKeywords[:]
|
tmpKeywords = mtree.DefaultTarKeywords[:]
|
||||||
} else {
|
} else {
|
||||||
currentKeywords = mtree.DefaultKeywords[:]
|
tmpKeywords = mtree.DefaultKeywords[:]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// -K <keywords>
|
// -K <keywords>
|
||||||
if *flAddKeywords != "" {
|
if *flAddKeywords != "" {
|
||||||
for _, kw := range splitKeywordsArg(*flAddKeywords) {
|
for _, kw := range splitKeywordsArg(*flAddKeywords) {
|
||||||
if !inSlice(kw, currentKeywords) {
|
if !inSlice(kw, tmpKeywords) {
|
||||||
currentKeywords = append(currentKeywords, kw)
|
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>
|
// -f <file>
|
||||||
var dh *mtree.DirectoryHierarchy
|
var dh *mtree.DirectoryHierarchy
|
||||||
if *flFile != "" && !*flCreate {
|
if *flFile != "" && !*flCreate {
|
||||||
|
|
Loading…
Reference in a new issue