/vendor/github.com/tonistiigi/fsutil/diskwriter_unix.go

https://github.com/GoogleContainerTools/kaniko · Go · 52 lines · 39 code · 10 blank · 3 comment · 17 complexity · 690765fa6490ec37b0039c32b15a5600 MD5 · raw file

  1. // +build !windows
  2. package fsutil
  3. import (
  4. "os"
  5. "syscall"
  6. "github.com/containerd/continuity/sysx"
  7. "github.com/pkg/errors"
  8. "github.com/tonistiigi/fsutil/types"
  9. )
  10. func rewriteMetadata(p string, stat *types.Stat) error {
  11. for key, value := range stat.Xattrs {
  12. sysx.Setxattr(p, key, value, 0)
  13. }
  14. if err := os.Lchown(p, int(stat.Uid), int(stat.Gid)); err != nil {
  15. return errors.Wrapf(err, "failed to lchown %s", p)
  16. }
  17. if os.FileMode(stat.Mode)&os.ModeSymlink == 0 {
  18. if err := os.Chmod(p, os.FileMode(stat.Mode)); err != nil {
  19. return errors.Wrapf(err, "failed to chown %s", p)
  20. }
  21. }
  22. if err := chtimes(p, stat.ModTime); err != nil {
  23. return errors.Wrapf(err, "failed to chtimes %s", p)
  24. }
  25. return nil
  26. }
  27. // handleTarTypeBlockCharFifo is an OS-specific helper function used by
  28. // createTarFile to handle the following types of header: Block; Char; Fifo
  29. func handleTarTypeBlockCharFifo(path string, stat *types.Stat) error {
  30. mode := uint32(stat.Mode & 07777)
  31. if os.FileMode(stat.Mode)&os.ModeCharDevice != 0 {
  32. mode |= syscall.S_IFCHR
  33. } else if os.FileMode(stat.Mode)&os.ModeNamedPipe != 0 {
  34. mode |= syscall.S_IFIFO
  35. } else {
  36. mode |= syscall.S_IFBLK
  37. }
  38. if err := syscall.Mknod(path, mode, int(mkdev(stat.Devmajor, stat.Devminor))); err != nil {
  39. return err
  40. }
  41. return nil
  42. }