mirror of
https://github.com/golang/go
synced 2024-11-27 00:31:23 -07:00
archive/tar: correct value passed to Uname method
For #50102 Change-Id: I28b5579611b07952b6379bc4603daf29a86a3be0 Reviewed-on: https://go-review.googlesource.com/c/go/+/518056 Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Joseph Tsai <joetsai@digital-static.net> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Tianon Gravi (Andrew) <admwiggin@gmail.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: qiulaidongfeng <2645477756@qq.com> Reviewed-by: Joseph Tsai <joetsai@digital-static.net>
This commit is contained in:
parent
ada5f8a46d
commit
d13f7aa0ae
@ -726,7 +726,7 @@ func FileInfoHeader(fi fs.FileInfo, link string) (*Header, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
h.Uname, err = iface.Uname(h.Gid)
|
||||
h.Uname, err = iface.Uname(h.Uid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -849,6 +849,11 @@ func Benchmark(b *testing.B) {
|
||||
|
||||
}
|
||||
|
||||
const (
|
||||
testUid = 10
|
||||
testGid = 20
|
||||
)
|
||||
|
||||
type fileInfoNames struct{}
|
||||
|
||||
func (f *fileInfoNames) Name() string {
|
||||
@ -876,14 +881,29 @@ func (f *fileInfoNames) Sys() any {
|
||||
}
|
||||
|
||||
func (f *fileInfoNames) Uname(uid int) (string, error) {
|
||||
if uid == testUid {
|
||||
return "Uname", nil
|
||||
}
|
||||
return "", nil
|
||||
}
|
||||
|
||||
func (f *fileInfoNames) Gname(gid int) (string, error) {
|
||||
if gid == testGid {
|
||||
return "Gname", nil
|
||||
}
|
||||
return "", nil
|
||||
}
|
||||
|
||||
func TestFileInfoHeaderUseFileInfoNames(t *testing.T) {
|
||||
origLoadUidAndGid := loadUidAndGid
|
||||
defer func() {
|
||||
loadUidAndGid = origLoadUidAndGid
|
||||
}()
|
||||
loadUidAndGid = func(fi fs.FileInfo, uid, gid *int) {
|
||||
*uid = testUid
|
||||
*gid = testGid
|
||||
}
|
||||
|
||||
info := &fileInfoNames{}
|
||||
header, err := FileInfoHeader(info, "")
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user