Merge pull request #8863 from vbatts/vbatts-archive_stat
./pkg/archive: clean up Stat_t assertion
This commit is contained in:
commit
98e403702a
1 changed files with 10 additions and 7 deletions
|
@ -185,8 +185,13 @@ func (ta *tarAppender) addTarFile(path, name string) error {
|
||||||
|
|
||||||
hdr.Name = name
|
hdr.Name = name
|
||||||
|
|
||||||
stat, ok := fi.Sys().(*syscall.Stat_t)
|
var (
|
||||||
if ok {
|
nlink uint32
|
||||||
|
inode uint64
|
||||||
|
)
|
||||||
|
if stat, ok := fi.Sys().(*syscall.Stat_t); ok {
|
||||||
|
nlink = uint32(stat.Nlink)
|
||||||
|
inode = uint64(stat.Ino)
|
||||||
// Currently go does not fill in the major/minors
|
// Currently go does not fill in the major/minors
|
||||||
if stat.Mode&syscall.S_IFBLK == syscall.S_IFBLK ||
|
if stat.Mode&syscall.S_IFBLK == syscall.S_IFBLK ||
|
||||||
stat.Mode&syscall.S_IFCHR == syscall.S_IFCHR {
|
stat.Mode&syscall.S_IFCHR == syscall.S_IFCHR {
|
||||||
|
@ -194,19 +199,17 @@ func (ta *tarAppender) addTarFile(path, name string) error {
|
||||||
hdr.Devminor = int64(minor(uint64(stat.Rdev)))
|
hdr.Devminor = int64(minor(uint64(stat.Rdev)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if it's a regular file and has more than 1 link,
|
// if it's a regular file and has more than 1 link,
|
||||||
// it's hardlinked, so set the type flag accordingly
|
// it's hardlinked, so set the type flag accordingly
|
||||||
if fi.Mode().IsRegular() && stat.Nlink > 1 {
|
if fi.Mode().IsRegular() && nlink > 1 {
|
||||||
// a link should have a name that it links too
|
// a link should have a name that it links too
|
||||||
// and that linked name should be first in the tar archive
|
// and that linked name should be first in the tar archive
|
||||||
ino := uint64(stat.Ino)
|
if oldpath, ok := ta.SeenFiles[inode]; ok {
|
||||||
if oldpath, ok := ta.SeenFiles[ino]; ok {
|
|
||||||
hdr.Typeflag = tar.TypeLink
|
hdr.Typeflag = tar.TypeLink
|
||||||
hdr.Linkname = oldpath
|
hdr.Linkname = oldpath
|
||||||
hdr.Size = 0 // This Must be here for the writer math to add up!
|
hdr.Size = 0 // This Must be here for the writer math to add up!
|
||||||
} else {
|
} else {
|
||||||
ta.SeenFiles[ino] = name
|
ta.SeenFiles[inode] = name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue