Skip to content

Commit 5000b51

Browse files
committed
Revert "archive/tar: add FileInfoNames interface"
This reverts CL 514235. Also reverts CL 518056 which is a followup fix. Reason for revert: Proposal #50102 defined an interface that is too specific to UNIX-y systems and also didn't make much sense. The proposal is un-accepted, and we'll revisit in Go 1.23. Fixes (via backport) #65245. Updates #50102. Change-Id: I41ba0ee286c1d893e6564a337e5d76418d19435d Reviewed-on: https://go-review.googlesource.com/c/go/+/558295 Reviewed-by: Dmitri Shuralyov <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]>
1 parent 749ebaa commit 5000b51

File tree

4 files changed

+0
-119
lines changed

4 files changed

+0
-119
lines changed

api/go1.22.txt

-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
11
pkg archive/tar, method (*Writer) AddFS(fs.FS) error #58000
2-
pkg archive/tar, type FileInfoNames interface { Gname, IsDir, ModTime, Mode, Name, Size, Sys, Uname } #50102
3-
pkg archive/tar, type FileInfoNames interface, Gname(int) (string, error) #50102
4-
pkg archive/tar, type FileInfoNames interface, IsDir() bool #50102
5-
pkg archive/tar, type FileInfoNames interface, ModTime() time.Time #50102
6-
pkg archive/tar, type FileInfoNames interface, Mode() fs.FileMode #50102
7-
pkg archive/tar, type FileInfoNames interface, Name() string #50102
8-
pkg archive/tar, type FileInfoNames interface, Size() int64 #50102
9-
pkg archive/tar, type FileInfoNames interface, Sys() interface{} #50102
10-
pkg archive/tar, type FileInfoNames interface, Uname(int) (string, error) #50102
112
pkg archive/zip, method (*Writer) AddFS(fs.FS) error #54898
123
pkg cmp, func Or[$0 comparable](...$0) $0 #60204
134
pkg crypto/x509, func OIDFromInts([]uint64) (OID, error) #60665

src/archive/tar/common.go

-32
Original file line numberDiff line numberDiff line change
@@ -614,8 +614,6 @@ func (fi headerFileInfo) String() string {
614614
// sysStat, if non-nil, populates h from system-dependent fields of fi.
615615
var sysStat func(fi fs.FileInfo, h *Header) error
616616

617-
var loadUidAndGid func(fi fs.FileInfo, uid, gid *int)
618-
619617
const (
620618
// Mode constants from the USTAR spec:
621619
// See http://pubs.opengroup.org/onlinepubs/9699919799/utilities/pax.html#tag_20_92_13_06
@@ -641,10 +639,6 @@ const (
641639
// Since fs.FileInfo's Name method only returns the base name of
642640
// the file it describes, it may be necessary to modify Header.Name
643641
// to provide the full path name of the file.
644-
//
645-
// If fi implements [FileInfoNames]
646-
// the Gname and Uname of the header are
647-
// provided by the methods of the interface.
648642
func FileInfoHeader(fi fs.FileInfo, link string) (*Header, error) {
649643
if fi == nil {
650644
return nil, errors.New("archive/tar: FileInfo is nil")
@@ -717,38 +711,12 @@ func FileInfoHeader(fi fs.FileInfo, link string) (*Header, error) {
717711
}
718712
}
719713
}
720-
if iface, ok := fi.(FileInfoNames); ok {
721-
var err error
722-
if loadUidAndGid != nil {
723-
loadUidAndGid(fi, &h.Uid, &h.Gid)
724-
}
725-
h.Gname, err = iface.Gname(h.Gid)
726-
if err != nil {
727-
return nil, err
728-
}
729-
h.Uname, err = iface.Uname(h.Uid)
730-
if err != nil {
731-
return nil, err
732-
}
733-
return h, nil
734-
}
735714
if sysStat != nil {
736715
return h, sysStat(fi, h)
737716
}
738717
return h, nil
739718
}
740719

741-
// FileInfoNames extends [FileInfo] to translate UID/GID to names.
742-
// Passing an instance of this to [FileInfoHeader] permits the caller
743-
// to control UID/GID resolution.
744-
type FileInfoNames interface {
745-
fs.FileInfo
746-
// Uname should translate a UID into a user name.
747-
Uname(uid int) (string, error)
748-
// Gname should translate a GID into a group name.
749-
Gname(gid int) (string, error)
750-
}
751-
752720
// isHeaderOnlyType checks if the given type flag is of the type that has no
753721
// data section even if a size is specified.
754722
func isHeaderOnlyType(flag byte) bool {

src/archive/tar/stat_unix.go

-10
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717

1818
func init() {
1919
sysStat = statUnix
20-
loadUidAndGid = loadUidAndGidFunc
2120
}
2221

2322
// userMap and groupMap caches UID and GID lookups for performance reasons.
@@ -100,12 +99,3 @@ func statUnix(fi fs.FileInfo, h *Header) error {
10099
}
101100
return nil
102101
}
103-
104-
func loadUidAndGidFunc(fi fs.FileInfo, uid, gid *int) {
105-
sys, ok := fi.Sys().(*syscall.Stat_t)
106-
if !ok {
107-
return
108-
}
109-
*uid = int(sys.Uid)
110-
*gid = int(sys.Gid)
111-
}

src/archive/tar/tar_test.go

-68
Original file line numberDiff line numberDiff line change
@@ -848,71 +848,3 @@ func Benchmark(b *testing.B) {
848848
})
849849

850850
}
851-
852-
const (
853-
testUid = 10
854-
testGid = 20
855-
)
856-
857-
type fileInfoNames struct{}
858-
859-
func (f *fileInfoNames) Name() string {
860-
return "tmp"
861-
}
862-
863-
func (f *fileInfoNames) Size() int64 {
864-
return 0
865-
}
866-
867-
func (f *fileInfoNames) Mode() fs.FileMode {
868-
return 0777
869-
}
870-
871-
func (f *fileInfoNames) ModTime() time.Time {
872-
return time.Time{}
873-
}
874-
875-
func (f *fileInfoNames) IsDir() bool {
876-
return false
877-
}
878-
879-
func (f *fileInfoNames) Sys() any {
880-
return nil
881-
}
882-
883-
func (f *fileInfoNames) Uname(uid int) (string, error) {
884-
if uid == testUid {
885-
return "Uname", nil
886-
}
887-
return "", nil
888-
}
889-
890-
func (f *fileInfoNames) Gname(gid int) (string, error) {
891-
if gid == testGid {
892-
return "Gname", nil
893-
}
894-
return "", nil
895-
}
896-
897-
func TestFileInfoHeaderUseFileInfoNames(t *testing.T) {
898-
origLoadUidAndGid := loadUidAndGid
899-
defer func() {
900-
loadUidAndGid = origLoadUidAndGid
901-
}()
902-
loadUidAndGid = func(fi fs.FileInfo, uid, gid *int) {
903-
*uid = testUid
904-
*gid = testGid
905-
}
906-
907-
info := &fileInfoNames{}
908-
header, err := FileInfoHeader(info, "")
909-
if err != nil {
910-
t.Fatal(err)
911-
}
912-
if header.Uname != "Uname" {
913-
t.Fatalf("header.Uname: got %v, want %v", header.Uname, "Uname")
914-
}
915-
if header.Gname != "Gname" {
916-
t.Fatalf("header.Gname: got %v, want %v", header.Gname, "Gname")
917-
}
918-
}

0 commit comments

Comments
 (0)