changes_unix.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // +build !windows
  2. package archive // import "github.com/docker/docker/pkg/archive"
  3. import (
  4. "os"
  5. "syscall"
  6. "github.com/docker/docker/pkg/system"
  7. "golang.org/x/sys/unix"
  8. )
  9. func statDifferent(oldStat *system.StatT, newStat *system.StatT) bool {
  10. // Don't look at size for dirs, its not a good measure of change
  11. if oldStat.Mode() != newStat.Mode() ||
  12. oldStat.UID() != newStat.UID() ||
  13. oldStat.GID() != newStat.GID() ||
  14. oldStat.Rdev() != newStat.Rdev() ||
  15. // Don't look at size or modification time for dirs, its not a good
  16. // measure of change. See https://github.com/moby/moby/issues/9874
  17. // for a description of the issue with modification time, and
  18. // https://github.com/moby/moby/pull/11422 for the change.
  19. // (Note that in the Windows implementation of this function,
  20. // modification time IS taken as a change). See
  21. // https://github.com/moby/moby/pull/37982 for more information.
  22. (oldStat.Mode()&unix.S_IFDIR != unix.S_IFDIR &&
  23. (!sameFsTimeSpec(oldStat.Mtim(), newStat.Mtim()) || (oldStat.Size() != newStat.Size()))) {
  24. return true
  25. }
  26. return false
  27. }
  28. func (info *FileInfo) isDir() bool {
  29. return info.parent == nil || info.stat.Mode()&unix.S_IFDIR != 0
  30. }
  31. func getIno(fi os.FileInfo) uint64 {
  32. return fi.Sys().(*syscall.Stat_t).Ino
  33. }
  34. func hasHardlinks(fi os.FileInfo) bool {
  35. return fi.Sys().(*syscall.Stat_t).Nlink > 1
  36. }