keywords: they deserve their own file

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
Vincent Batts 2016-03-16 16:09:10 -04:00
parent 455edf6d21
commit b3198b462b
4 changed files with 139 additions and 134 deletions

33
keywords_linux.go Normal file
View file

@ -0,0 +1,33 @@
// +build linux
package mtree
import (
"fmt"
"os"
"os/user"
"syscall"
)
var (
unameKeywordFunc = func(path string, info os.FileInfo) (string, error) {
stat := info.Sys().(*syscall.Stat_t)
u, err := user.LookupId(fmt.Sprintf("%d", stat.Uid))
if err != nil {
return "", err
}
return fmt.Sprintf("uname=%s", u.Username), nil
}
uidKeywordFunc = func(path string, info os.FileInfo) (string, error) {
stat := info.Sys().(*syscall.Stat_t)
return fmt.Sprintf("uid=%d", stat.Uid), nil
}
gidKeywordFunc = func(path string, info os.FileInfo) (string, error) {
stat := info.Sys().(*syscall.Stat_t)
return fmt.Sprintf("gid=%d", stat.Gid), nil
}
nlinkKeywordFunc = func(path string, info os.FileInfo) (string, error) {
stat := info.Sys().(*syscall.Stat_t)
return fmt.Sprintf("nlink=%d", stat.Nlink), nil
}
)