keywords: added experimental "xattr" keyword

Initially only on linux platform, but could accommodate BSDs as well.
The keyword is rather a prefix of the key. So xattr keyword will have a
prefix of "xattr." followed by a suffix of its namespace and name.
The value stored in the manifest is the SHA1 digest of the extended
attribute's data.

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
Vincent Batts 2016-03-17 13:54:59 -04:00
parent 2d3aea8623
commit 211687bcc4
5 changed files with 34 additions and 2 deletions

View file

@ -3,10 +3,14 @@
package mtree
import (
"crypto/sha1"
"fmt"
"os"
"os/user"
"strings"
"syscall"
"./xattr"
)
var (
@ -30,4 +34,20 @@ var (
stat := info.Sys().(*syscall.Stat_t)
return fmt.Sprintf("nlink=%d", stat.Nlink), nil
}
xattrKeywordFunc = func(path string, info os.FileInfo) (string, error) {
xlist, err := xattr.List(path)
if err != nil {
return "", err
}
klist := make([]string, len(xlist))
for i := range xlist {
data, err := xattr.Get(path, xlist[i])
if err != nil {
return "", err
}
println(string(data))
klist[i] = fmt.Sprintf("xattr.%s=%x", xlist[i], sha1.Sum(data))
}
return strings.Join(klist, " "), nil
}
)