1
0
Fork 0
mirror of https://github.com/vbatts/go-mtree.git synced 2024-11-22 08:25:38 +00:00

Merge pull request #44 from vbatts/xattrs

fix xattr ERANGE
This commit is contained in:
Vincent Batts 2016-07-26 14:03:16 -04:00 committed by GitHub
commit 664ad32ff6
5 changed files with 34 additions and 4 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 (

View file

@ -29,7 +29,14 @@ func List(path string) ([]string, error) {
if err != nil {
return nil, err
}
return strings.Split(strings.TrimRight(string(dest[:i]), nilByte), nilByte), nil
// If the returned list is empty, return nil instead of []string{""}
str := string(dest[:i])
if str == "" {
return nil, nil
}
return strings.Split(strings.TrimRight(str, nilByte), nilByte), nil
}
const nilByte = "\x00"