diff_unix.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // +build !windows
  2. package fs
  3. import (
  4. "bytes"
  5. "os"
  6. "syscall"
  7. "github.com/containerd/continuity/sysx"
  8. "github.com/pkg/errors"
  9. )
  10. // detectDirDiff returns diff dir options if a directory could
  11. // be found in the mount info for upper which is the direct
  12. // diff with the provided lower directory
  13. func detectDirDiff(upper, lower string) *diffDirOptions {
  14. // TODO: get mount options for upper
  15. // TODO: detect AUFS
  16. // TODO: detect overlay
  17. return nil
  18. }
  19. // compareSysStat returns whether the stats are equivalent,
  20. // whether the files are considered the same file, and
  21. // an error
  22. func compareSysStat(s1, s2 interface{}) (bool, error) {
  23. ls1, ok := s1.(*syscall.Stat_t)
  24. if !ok {
  25. return false, nil
  26. }
  27. ls2, ok := s2.(*syscall.Stat_t)
  28. if !ok {
  29. return false, nil
  30. }
  31. return ls1.Mode == ls2.Mode && ls1.Uid == ls2.Uid && ls1.Gid == ls2.Gid && ls1.Rdev == ls2.Rdev, nil
  32. }
  33. func compareCapabilities(p1, p2 string) (bool, error) {
  34. c1, err := sysx.LGetxattr(p1, "security.capability")
  35. if err != nil && err != sysx.ENODATA {
  36. return false, errors.Wrapf(err, "failed to get xattr for %s", p1)
  37. }
  38. c2, err := sysx.LGetxattr(p2, "security.capability")
  39. if err != nil && err != sysx.ENODATA {
  40. return false, errors.Wrapf(err, "failed to get xattr for %s", p2)
  41. }
  42. return bytes.Equal(c1, c2), nil
  43. }
  44. func isLinked(f os.FileInfo) bool {
  45. s, ok := f.Sys().(*syscall.Stat_t)
  46. if !ok {
  47. return false
  48. }
  49. return !f.IsDir() && s.Nlink > 1
  50. }