2016-10-31 17:25:11 +00:00
|
|
|
// +build darwin freebsd netbsd openbsd
|
|
|
|
|
|
|
|
package mtree
|
|
|
|
|
|
|
|
import (
|
2016-10-31 14:10:42 +00:00
|
|
|
"archive/tar"
|
|
|
|
"fmt"
|
2016-10-31 17:25:11 +00:00
|
|
|
"io"
|
|
|
|
"os"
|
2016-10-31 14:10:42 +00:00
|
|
|
"os/user"
|
|
|
|
"syscall"
|
2016-10-31 17:25:11 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2017-06-15 18:54:58 +00:00
|
|
|
flagsKeywordFunc = func(path string, info os.FileInfo, r io.Reader) ([]KeyVal, error) {
|
2016-10-31 17:25:11 +00:00
|
|
|
// ideally this will pull in from here https://www.freebsd.org/cgi/man.cgi?query=chflags&sektion=2
|
2017-06-15 18:54:58 +00:00
|
|
|
return nil, nil
|
2016-10-31 17:25:11 +00:00
|
|
|
}
|
2016-10-31 14:10:42 +00:00
|
|
|
|
2017-06-15 18:54:58 +00:00
|
|
|
unameKeywordFunc = func(path string, info os.FileInfo, r io.Reader) ([]KeyVal, error) {
|
2016-10-31 14:10:42 +00:00
|
|
|
if hdr, ok := info.Sys().(*tar.Header); ok {
|
2017-06-15 18:54:58 +00:00
|
|
|
return []KeyVal{KeyVal(fmt.Sprintf("uname=%s", hdr.Uname))}, nil
|
2016-10-31 14:10:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
stat := info.Sys().(*syscall.Stat_t)
|
|
|
|
u, err := user.LookupId(fmt.Sprintf("%d", stat.Uid))
|
|
|
|
if err != nil {
|
2017-06-15 18:54:58 +00:00
|
|
|
return nil, err
|
2016-10-31 14:10:42 +00:00
|
|
|
}
|
2017-06-15 18:54:58 +00:00
|
|
|
return []KeyVal{KeyVal(fmt.Sprintf("uname=%s", u.Username))}, nil
|
2016-10-31 14:10:42 +00:00
|
|
|
}
|
2017-06-15 18:54:58 +00:00
|
|
|
gnameKeywordFunc = func(path string, info os.FileInfo, r io.Reader) ([]KeyVal, error) {
|
2017-06-15 15:59:27 +00:00
|
|
|
if hdr, ok := info.Sys().(*tar.Header); ok {
|
2017-06-15 18:54:58 +00:00
|
|
|
return []KeyVal{KeyVal(fmt.Sprintf("gname=%s", hdr.Gname))}, nil
|
2017-06-15 15:59:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
stat := info.Sys().(*syscall.Stat_t)
|
2017-06-15 17:07:52 +00:00
|
|
|
g, err := lookupGroupID(fmt.Sprintf("%d", stat.Gid))
|
2017-06-15 15:59:27 +00:00
|
|
|
if err != nil {
|
2017-06-15 18:54:58 +00:00
|
|
|
return nil, err
|
2017-06-15 15:59:27 +00:00
|
|
|
}
|
2017-06-15 18:54:58 +00:00
|
|
|
return []KeyVal{KeyVal(fmt.Sprintf("gname=%s", g.Name))}, nil
|
2017-06-15 15:59:27 +00:00
|
|
|
}
|
2017-06-15 18:54:58 +00:00
|
|
|
uidKeywordFunc = func(path string, info os.FileInfo, r io.Reader) ([]KeyVal, error) {
|
2016-10-31 14:10:42 +00:00
|
|
|
if hdr, ok := info.Sys().(*tar.Header); ok {
|
2017-06-15 18:54:58 +00:00
|
|
|
return []KeyVal{KeyVal(fmt.Sprintf("uid=%d", hdr.Uid))}, nil
|
2016-10-31 14:10:42 +00:00
|
|
|
}
|
|
|
|
stat := info.Sys().(*syscall.Stat_t)
|
2017-06-15 18:54:58 +00:00
|
|
|
return []KeyVal{KeyVal(fmt.Sprintf("uid=%d", stat.Uid))}, nil
|
2016-10-31 14:10:42 +00:00
|
|
|
}
|
2017-06-15 18:54:58 +00:00
|
|
|
gidKeywordFunc = func(path string, info os.FileInfo, r io.Reader) ([]KeyVal, error) {
|
2016-10-31 14:10:42 +00:00
|
|
|
if hdr, ok := info.Sys().(*tar.Header); ok {
|
2017-06-15 18:54:58 +00:00
|
|
|
return []KeyVal{KeyVal(fmt.Sprintf("gid=%d", hdr.Gid))}, nil
|
2016-10-31 14:10:42 +00:00
|
|
|
}
|
|
|
|
if stat, ok := info.Sys().(*syscall.Stat_t); ok {
|
2017-06-15 18:54:58 +00:00
|
|
|
return []KeyVal{KeyVal(fmt.Sprintf("gid=%d", stat.Gid))}, nil
|
2016-10-31 14:10:42 +00:00
|
|
|
}
|
2017-06-15 18:54:58 +00:00
|
|
|
return nil, nil
|
2016-10-31 14:10:42 +00:00
|
|
|
}
|
2017-06-15 18:54:58 +00:00
|
|
|
nlinkKeywordFunc = func(path string, info os.FileInfo, r io.Reader) ([]KeyVal, error) {
|
2016-10-31 14:10:42 +00:00
|
|
|
if stat, ok := info.Sys().(*syscall.Stat_t); ok {
|
2017-06-15 18:54:58 +00:00
|
|
|
return []KeyVal{KeyVal(fmt.Sprintf("nlink=%d", stat.Nlink))}, nil
|
2016-10-31 14:10:42 +00:00
|
|
|
}
|
2017-06-15 18:54:58 +00:00
|
|
|
return nil, nil
|
2016-10-31 14:10:42 +00:00
|
|
|
}
|
2017-06-15 18:54:58 +00:00
|
|
|
xattrKeywordFunc = func(path string, info os.FileInfo, r io.Reader) ([]KeyVal, error) {
|
|
|
|
return nil, nil
|
2016-10-31 14:10:42 +00:00
|
|
|
}
|
2016-10-31 17:25:11 +00:00
|
|
|
)
|