inspired by @tonistiigi comment
(https://github.com/docker/docker/pull/8046/files#r19579960)
Signed-off-by: Vincent Batts <vbatts@redhat.com>
| ... | ... |
@@ -185,8 +185,13 @@ func (ta *tarAppender) addTarFile(path, name string) error {
|
| 185 | 185 |
|
| 186 | 186 |
hdr.Name = name |
| 187 | 187 |
|
| 188 |
- stat, ok := fi.Sys().(*syscall.Stat_t) |
|
| 189 |
- if ok {
|
|
| 188 |
+ var ( |
|
| 189 |
+ nlink uint32 |
|
| 190 |
+ inode uint64 |
|
| 191 |
+ ) |
|
| 192 |
+ if stat, ok := fi.Sys().(*syscall.Stat_t); ok {
|
|
| 193 |
+ nlink = uint32(stat.Nlink) |
|
| 194 |
+ inode = uint64(stat.Ino) |
|
| 190 | 195 |
// Currently go does not fill in the major/minors |
| 191 | 196 |
if stat.Mode&syscall.S_IFBLK == syscall.S_IFBLK || |
| 192 | 197 |
stat.Mode&syscall.S_IFCHR == syscall.S_IFCHR {
|
| ... | ... |
@@ -194,19 +199,17 @@ func (ta *tarAppender) addTarFile(path, name string) error {
|
| 194 | 194 |
hdr.Devminor = int64(minor(uint64(stat.Rdev))) |
| 195 | 195 |
} |
| 196 | 196 |
} |
| 197 |
- |
|
| 198 | 197 |
// if it's a regular file and has more than 1 link, |
| 199 | 198 |
// it's hardlinked, so set the type flag accordingly |
| 200 |
- if fi.Mode().IsRegular() && stat.Nlink > 1 {
|
|
| 199 |
+ if fi.Mode().IsRegular() && nlink > 1 {
|
|
| 201 | 200 |
// a link should have a name that it links too |
| 202 | 201 |
// and that linked name should be first in the tar archive |
| 203 |
- ino := uint64(stat.Ino) |
|
| 204 |
- if oldpath, ok := ta.SeenFiles[ino]; ok {
|
|
| 202 |
+ if oldpath, ok := ta.SeenFiles[inode]; ok {
|
|
| 205 | 203 |
hdr.Typeflag = tar.TypeLink |
| 206 | 204 |
hdr.Linkname = oldpath |
| 207 | 205 |
hdr.Size = 0 // This Must be here for the writer math to add up! |
| 208 | 206 |
} else {
|
| 209 |
- ta.SeenFiles[ino] = name |
|
| 207 |
+ ta.SeenFiles[inode] = name |
|
| 210 | 208 |
} |
| 211 | 209 |
} |
| 212 | 210 |
|