archive_unix.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // +build !windows
  2. package archive
  3. import (
  4. "archive/tar"
  5. "errors"
  6. "os"
  7. "syscall"
  8. )
  9. // canonicalTarNameForPath returns platform-specific filepath
  10. // to canonical posix-style path for tar archival. p is relative
  11. // path.
  12. func CanonicalTarNameForPath(p string) (string, error) {
  13. return p, nil // already unix-style
  14. }
  15. // chmodTarEntry is used to adjust the file permissions used in tar header based
  16. // on the platform the archival is done.
  17. func chmodTarEntry(perm os.FileMode) os.FileMode {
  18. return perm // noop for unix as golang APIs provide perm bits correctly
  19. }
  20. func setHeaderForSpecialDevice(hdr *tar.Header, ta *tarAppender, name string, stat interface{}) (nlink uint32, inode uint64, err error) {
  21. s, ok := stat.(*syscall.Stat_t)
  22. if !ok {
  23. err = errors.New("cannot convert stat value to syscall.Stat_t")
  24. return
  25. }
  26. nlink = uint32(s.Nlink)
  27. inode = uint64(s.Ino)
  28. // Currently go does not fil in the major/minors
  29. if s.Mode&syscall.S_IFBLK != 0 ||
  30. s.Mode&syscall.S_IFCHR != 0 {
  31. hdr.Devmajor = int64(major(uint64(s.Rdev)))
  32. hdr.Devminor = int64(minor(uint64(s.Rdev)))
  33. }
  34. return
  35. }
  36. func major(device uint64) uint64 {
  37. return (device >> 8) & 0xfff
  38. }
  39. func minor(device uint64) uint64 {
  40. return (device & 0xff) | ((device >> 12) & 0xfff00)
  41. }