Skip to content

Commit 8676a0a

Browse files
n
Change-Id: Iaab5d235f7f05d40ec3dee23256c5866d4a99aa4
1 parent c21fc57 commit 8676a0a

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
If the argument to [`tar.FileInfoHeader`](/archive/tar#FileInfoHeader) implements the new [`tar.FileInfoNames`](/archive/tar#FileInfoNames) interface, then the interface methods will be used to set the Uname/Gname of the file header. This allows applications to override the default Uname/Gname resolution.
1+
If the argument to [`FileInfoHeader`](/archive/tar#FileInfoHeader) implements the new [`FileInfoNames`](/archive/tar#FileInfoNames) interface,
2+
then the interface methods will be used to set the Uname/Gname of the file header.
3+
This allows applications to override the system-dependent Uname/Gname lookup.

src/archive/tar/common.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ const (
641641
// to provide the full path name of the file.
642642
//
643643
// If fi implements [FileInfoNames]
644-
// the Gname and Uname of the header are
644+
// Header.Gname and Header.Uname
645645
// provided by the methods of the interface.
646646
func FileInfoHeader(fi fs.FileInfo, link string) (*Header, error) {
647647
if fi == nil {
@@ -734,9 +734,9 @@ func FileInfoHeader(fi fs.FileInfo, link string) (*Header, error) {
734734
return h, nil
735735
}
736736

737-
// FileInfoNames extends [fs.FileInfo]
737+
// FileInfoNames extends [fs.FileInfo].
738738
// Passing an instance of this to [FileInfoHeader] permits the caller
739-
// to control Gname and Uname set.
739+
// to avoid asystem-dependent name lookup by specifying the Uname and Gname directly.
740740
type FileInfoNames interface {
741741
fs.FileInfo
742742
// Uname should give a user name.

src/archive/tar/stat_unix.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ func statUnix(fi fs.FileInfo, h *Header, doNameLookups bool) error {
2828
if !ok {
2929
return nil
3030
}
31+
32+
h.Uid = int(sys.Uid)
33+
h.Gid = int(sys.Gid)
3134
if doNameLookups {
3235
// Best effort at populating Uname and Gname.
3336
// The os/user functions may fail for any number of reasons
@@ -45,9 +48,6 @@ func statUnix(fi fs.FileInfo, h *Header, doNameLookups bool) error {
4548
groupMap.Store(h.Gid, h.Gname)
4649
}
4750
}
48-
49-
h.Uid = int(sys.Uid)
50-
h.Gid = int(sys.Gid)
5151
h.AccessTime = statAtime(sys)
5252
h.ChangeTime = statCtime(sys)
5353

0 commit comments

Comments
 (0)