|
| 1 | +From bc0de86b495ae014b209431ed7cb90fc3d5e4d1f Mon Sep 17 00:00:00 2001 |
| 2 | +From: Kir Kolyshkin <kolyshkin@gmail.com> |
| 3 | +Date: Mon, 9 Apr 2018 15:58:40 -0700 |
| 4 | +Subject: [PATCH] archive/tar: do not populate user/group names |
| 5 | + |
| 6 | +This reverts part of commit 29a18899379c ("archive/tar: populate |
| 7 | +uname/gname/devmajor/devminor in FileInfoHeader"). The reason is |
| 8 | +using os/user functions to resolved uids/gids to names breaks |
| 9 | +the static build for Linux/glibc case (the resulting binary panics |
| 10 | +on NULL pointer dereference). |
| 11 | + |
| 12 | +For much more details, see https://github.com/golang/go/issues/23265 |
| 13 | + |
| 14 | +This is ultimately fixed in Go 1.11 (provided that "osusergo" build tag |
| 15 | +is set (see https://github.com/golang/go/commit/62f0127d81). In the |
| 16 | +meantime, let's use this fork. |
| 17 | + |
| 18 | +Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com> |
| 19 | +--- |
| 20 | + src/archive/tar/stat_unix.go | 26 +++----------------------- |
| 21 | + 1 file changed, 3 insertions(+), 23 deletions(-) |
| 22 | + |
| 23 | +diff --git a/src/archive/tar/stat_unix.go b/src/archive/tar/stat_unix.go |
| 24 | +index 868105f338..9640ed4bab 100644 |
| 25 | +--- a/src/archive/tar/stat_unix.go |
| 26 | ++++ b/src/archive/tar/stat_unix.go |
| 27 | +@@ -8,10 +8,7 @@ package tar |
| 28 | + |
| 29 | + import ( |
| 30 | + "os" |
| 31 | +- "os/user" |
| 32 | + "runtime" |
| 33 | +- "strconv" |
| 34 | +- "sync" |
| 35 | + "syscall" |
| 36 | + ) |
| 37 | + |
| 38 | +@@ -19,10 +16,6 @@ func init() { |
| 39 | + sysStat = statUnix |
| 40 | + } |
| 41 | + |
| 42 | +-// userMap and groupMap caches UID and GID lookups for performance reasons. |
| 43 | +-// The downside is that renaming uname or gname by the OS never takes effect. |
| 44 | +-var userMap, groupMap sync.Map // map[int]string |
| 45 | +- |
| 46 | + func statUnix(fi os.FileInfo, h *Header) error { |
| 47 | + sys, ok := fi.Sys().(*syscall.Stat_t) |
| 48 | + if !ok { |
| 49 | +@@ -31,22 +24,9 @@ func statUnix(fi os.FileInfo, h *Header) error { |
| 50 | + h.Uid = int(sys.Uid) |
| 51 | + h.Gid = int(sys.Gid) |
| 52 | + |
| 53 | +- // Best effort at populating Uname and Gname. |
| 54 | +- // The os/user functions may fail for any number of reasons |
| 55 | +- // (not implemented on that platform, cgo not enabled, etc). |
| 56 | +- if u, ok := userMap.Load(h.Uid); ok { |
| 57 | +- h.Uname = u.(string) |
| 58 | +- } else if u, err := user.LookupId(strconv.Itoa(h.Uid)); err == nil { |
| 59 | +- h.Uname = u.Username |
| 60 | +- userMap.Store(h.Uid, h.Uname) |
| 61 | +- } |
| 62 | +- if g, ok := groupMap.Load(h.Gid); ok { |
| 63 | +- h.Gname = g.(string) |
| 64 | +- } else if g, err := user.LookupGroupId(strconv.Itoa(h.Gid)); err == nil { |
| 65 | +- h.Gname = g.Name |
| 66 | +- groupMap.Store(h.Gid, h.Gname) |
| 67 | +- } |
| 68 | +- |
| 69 | ++ // TODO(bradfitz): populate username & group. os/user |
| 70 | ++ // doesn't cache LookupId lookups, and lacks group |
| 71 | ++ // lookup functions. |
| 72 | + h.AccessTime = statAtime(sys) |
| 73 | + h.ChangeTime = statCtime(sys) |
| 74 | + |
| 75 | + |
| 76 | +base-commit: 4af1337d1e9eb9e7b766c9deb787c78413bb25c4 |
| 77 | +-- |
| 78 | +2.24.1 |
| 79 | + |
0 commit comments