mirror of
https://github.com/vbatts/go-mtree.git
synced 2025-07-27 00:30:27 +00:00
keyword: add missing gname
keyword functions
Fixes: #128 Reported-by: Lennart Poettering <lennart@poettering.net> Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
parent
469590a575
commit
68651d77d6
4 changed files with 31 additions and 0 deletions
69
keywordfuncs_bsd.go
Normal file
69
keywordfuncs_bsd.go
Normal file
|
@ -0,0 +1,69 @@
|
|||
// +build darwin freebsd netbsd openbsd
|
||||
|
||||
package mtree
|
||||
|
||||
import (
|
||||
"archive/tar"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"os/user"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
var (
|
||||
flagsKeywordFunc = func(path string, info os.FileInfo, r io.Reader) (KeyVal, error) {
|
||||
// ideally this will pull in from here https://www.freebsd.org/cgi/man.cgi?query=chflags&sektion=2
|
||||
return emptyKV, nil
|
||||
}
|
||||
|
||||
unameKeywordFunc = func(path string, info os.FileInfo, r io.Reader) (KeyVal, error) {
|
||||
if hdr, ok := info.Sys().(*tar.Header); ok {
|
||||
return KeyVal(fmt.Sprintf("uname=%s", hdr.Uname)), nil
|
||||
}
|
||||
|
||||
stat := info.Sys().(*syscall.Stat_t)
|
||||
u, err := user.LookupId(fmt.Sprintf("%d", stat.Uid))
|
||||
if err != nil {
|
||||
return emptyKV, err
|
||||
}
|
||||
return KeyVal(fmt.Sprintf("uname=%s", u.Username)), nil
|
||||
}
|
||||
gnameKeywordFunc = func(path string, info os.FileInfo, r io.Reader) (KeyVal, error) {
|
||||
if hdr, ok := info.Sys().(*tar.Header); ok {
|
||||
return KeyVal(fmt.Sprintf("gname=%s", hdr.Gname)), nil
|
||||
}
|
||||
|
||||
stat := info.Sys().(*syscall.Stat_t)
|
||||
g, err := user.LookupGroupId(fmt.Sprintf("%d", stat.Gid))
|
||||
if err != nil {
|
||||
return emptyKV, err
|
||||
}
|
||||
return KeyVal(fmt.Sprintf("gname=%s", g.Name)), nil
|
||||
}
|
||||
uidKeywordFunc = func(path string, info os.FileInfo, r io.Reader) (KeyVal, error) {
|
||||
if hdr, ok := info.Sys().(*tar.Header); ok {
|
||||
return KeyVal(fmt.Sprintf("uid=%d", hdr.Uid)), nil
|
||||
}
|
||||
stat := info.Sys().(*syscall.Stat_t)
|
||||
return KeyVal(fmt.Sprintf("uid=%d", stat.Uid)), nil
|
||||
}
|
||||
gidKeywordFunc = func(path string, info os.FileInfo, r io.Reader) (KeyVal, error) {
|
||||
if hdr, ok := info.Sys().(*tar.Header); ok {
|
||||
return KeyVal(fmt.Sprintf("gid=%d", hdr.Gid)), nil
|
||||
}
|
||||
if stat, ok := info.Sys().(*syscall.Stat_t); ok {
|
||||
return KeyVal(fmt.Sprintf("gid=%d", stat.Gid)), nil
|
||||
}
|
||||
return emptyKV, nil
|
||||
}
|
||||
nlinkKeywordFunc = func(path string, info os.FileInfo, r io.Reader) (KeyVal, error) {
|
||||
if stat, ok := info.Sys().(*syscall.Stat_t); ok {
|
||||
return KeyVal(fmt.Sprintf("nlink=%d", stat.Nlink)), nil
|
||||
}
|
||||
return emptyKV, nil
|
||||
}
|
||||
xattrKeywordFunc = func(path string, info os.FileInfo, r io.Reader) (KeyVal, error) {
|
||||
return emptyKV, nil
|
||||
}
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue