diff_unix.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // +build !windows
  2. /*
  3. Copyright The containerd Authors.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. */
  14. package fs
  15. import (
  16. "bytes"
  17. "os"
  18. "syscall"
  19. "github.com/containerd/continuity/sysx"
  20. "github.com/pkg/errors"
  21. )
  22. // detectDirDiff returns diff dir options if a directory could
  23. // be found in the mount info for upper which is the direct
  24. // diff with the provided lower directory
  25. func detectDirDiff(upper, lower string) *diffDirOptions {
  26. // TODO: get mount options for upper
  27. // TODO: detect AUFS
  28. // TODO: detect overlay
  29. return nil
  30. }
  31. // compareSysStat returns whether the stats are equivalent,
  32. // whether the files are considered the same file, and
  33. // an error
  34. func compareSysStat(s1, s2 interface{}) (bool, error) {
  35. ls1, ok := s1.(*syscall.Stat_t)
  36. if !ok {
  37. return false, nil
  38. }
  39. ls2, ok := s2.(*syscall.Stat_t)
  40. if !ok {
  41. return false, nil
  42. }
  43. return ls1.Mode == ls2.Mode && ls1.Uid == ls2.Uid && ls1.Gid == ls2.Gid && ls1.Rdev == ls2.Rdev, nil
  44. }
  45. func compareCapabilities(p1, p2 string) (bool, error) {
  46. c1, err := sysx.LGetxattr(p1, "security.capability")
  47. if err != nil && err != sysx.ENODATA {
  48. return false, errors.Wrapf(err, "failed to get xattr for %s", p1)
  49. }
  50. c2, err := sysx.LGetxattr(p2, "security.capability")
  51. if err != nil && err != sysx.ENODATA {
  52. return false, errors.Wrapf(err, "failed to get xattr for %s", p2)
  53. }
  54. return bytes.Equal(c1, c2), nil
  55. }
  56. func isLinked(f os.FileInfo) bool {
  57. s, ok := f.Sys().(*syscall.Stat_t)
  58. if !ok {
  59. return false
  60. }
  61. return !f.IsDir() && s.Nlink > 1
  62. }