github.com/cdoern/storage@v1.12.13/pkg/archive/changes_unix.go (about)

     1  // +build !windows
     2  
     3  package archive
     4  
     5  import (
     6  	"os"
     7  	"syscall"
     8  
     9  	"github.com/containers/storage/pkg/idtools"
    10  	"github.com/containers/storage/pkg/system"
    11  	"golang.org/x/sys/unix"
    12  )
    13  
    14  func statDifferent(oldStat *system.StatT, oldInfo *FileInfo, newStat *system.StatT, newInfo *FileInfo) bool {
    15  	// Don't look at size for dirs, its not a good measure of change
    16  	oldUid, oldGid := oldStat.UID(), oldStat.GID()
    17  	uid, gid := newStat.UID(), newStat.GID()
    18  	if cuid, cgid, err := newInfo.idMappings.ToContainer(idtools.IDPair{UID: int(uid), GID: int(gid)}); err == nil {
    19  		uid = uint32(cuid)
    20  		gid = uint32(cgid)
    21  		if oldcuid, oldcgid, err := oldInfo.idMappings.ToContainer(idtools.IDPair{UID: int(oldUid), GID: int(oldGid)}); err == nil {
    22  			oldUid = uint32(oldcuid)
    23  			oldGid = uint32(oldcgid)
    24  		}
    25  	}
    26  	ownerChanged := uid != oldUid || gid != oldGid
    27  	if oldStat.Mode() != newStat.Mode() ||
    28  		ownerChanged ||
    29  		oldStat.Rdev() != newStat.Rdev() ||
    30  		// Don't look at size for dirs, its not a good measure of change
    31  		(oldStat.Mode()&unix.S_IFDIR != unix.S_IFDIR &&
    32  			(!sameFsTimeSpec(oldStat.Mtim(), newStat.Mtim()) || (oldStat.Size() != newStat.Size()))) {
    33  		return true
    34  	}
    35  	return false
    36  }
    37  
    38  func (info *FileInfo) isDir() bool {
    39  	return info.parent == nil || info.stat.Mode()&unix.S_IFDIR != 0
    40  }
    41  
    42  func getIno(fi os.FileInfo) uint64 {
    43  	return fi.Sys().(*syscall.Stat_t).Ino
    44  }
    45  
    46  func hasHardlinks(fi os.FileInfo) bool {
    47  	return fi.Sys().(*syscall.Stat_t).Nlink > 1
    48  }