1
0
Fork 0
mirror of https://github.com/vbatts/go-mtree.git synced 2024-11-26 01:55:39 +00:00

debug: add an mtree.Debugf and -debug flag

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
Vincent Batts 2016-07-20 13:28:08 -04:00 committed by Stephen Chung
parent 2f80b2c54e
commit a596aefc43
4 changed files with 26 additions and 3 deletions

View file

@ -23,6 +23,8 @@ 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")
flDebug = flag.Bool("debug", false, "output debug info to STDERR")
)
var formats = map[string]func(*mtree.Result) string{
@ -57,6 +59,10 @@ var formats = map[string]func(*mtree.Result) string{
func main() {
flag.Parse()
if *flDebug {
os.Setenv("DEBUG", "1")
}
// so that defers cleanly exec
var isErr bool
defer func() {

18
debug.go Normal file
View file

@ -0,0 +1,18 @@
package mtree
import (
"fmt"
"os"
"time"
)
// DebugOutput is the where DEBUG output is written
var DebugOutput = os.Stderr
// Debugf does formatted output to DebugOutput, only if DEBUG environment variable is set
func Debugf(format string, a ...interface{}) (n int, err error) {
if os.Getenv("DEBUG") != "" {
return fmt.Fprintf(DebugOutput, "[%d] [DEBUG] %s\n", time.Now().UnixNano(), fmt.Sprintf(format, a...))
}
return 0, nil
}

View file

@ -185,7 +185,8 @@ var (
// The pattern for this keyword key is prefixed by "xattr." followed by the extended attribute "namespace.key".
// The keyword value is the SHA1 digest of the extended attribute's value.
// In this way, the order of the keys does not matter, and the contents of the value is not revealed.
"xattr": xattrKeywordFunc,
"xattr": xattrKeywordFunc,
"xattrs": xattrKeywordFunc,
}
)

View file

@ -1,5 +1,3 @@
// +build linux
package mtree
import (