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
|
@ -34,6 +34,7 @@ var (
|
|||
"gid": gidKeywordFunc, // The file group as a numeric value
|
||||
"nlink": nlinkKeywordFunc, // The number of hard links the file is expected to have
|
||||
"uname": unameKeywordFunc, // The file owner as a symbolic name
|
||||
"gname": gnameKeywordFunc, // The file group as a symbolic name
|
||||
"mode": modeKeywordFunc, // The current file's permissions as a numeric (octal) or symbolic value
|
||||
"cksum": cksumKeywordFunc, // The checksum of the file using the default algorithm specified by the cksum(1) utility
|
||||
"md5": hasherKeywordFunc("md5digest", md5.New), // The MD5 message digest of the file
|
||||
|
|
|
@ -29,6 +29,18 @@ var (
|
|||
}
|
||||
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
|
|
@ -34,6 +34,18 @@ var (
|
|||
}
|
||||
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
|
||||
|
|
|
@ -20,6 +20,12 @@ var (
|
|||
}
|
||||
return emptyKV, 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
|
||||
}
|
||||
return emptyKV, 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
|
||||
|
|
Loading…
Reference in a new issue