2014-11-13 20:36:05 +00:00
|
|
|
// +build !windows
|
|
|
|
|
|
|
|
package archive
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2015-03-04 02:40:16 +00:00
|
|
|
"os"
|
2014-11-13 20:36:05 +00:00
|
|
|
"syscall"
|
|
|
|
|
|
|
|
"github.com/docker/docker/vendor/src/code.google.com/p/go/src/pkg/archive/tar"
|
|
|
|
)
|
|
|
|
|
2015-02-17 20:27:07 +00:00
|
|
|
// canonicalTarNameForPath returns platform-specific filepath
|
|
|
|
// to canonical posix-style path for tar archival. p is relative
|
|
|
|
// path.
|
2015-02-25 03:43:29 +00:00
|
|
|
func CanonicalTarNameForPath(p string) (string, error) {
|
2015-02-17 20:27:07 +00:00
|
|
|
return p, nil // already unix-style
|
|
|
|
}
|
|
|
|
|
2015-03-04 02:40:16 +00:00
|
|
|
// chmodTarEntry is used to adjust the file permissions used in tar header based
|
|
|
|
// on the platform the archival is done.
|
|
|
|
|
|
|
|
func chmodTarEntry(perm os.FileMode) os.FileMode {
|
|
|
|
return perm // noop for unix as golang APIs provide perm bits correctly
|
|
|
|
}
|
|
|
|
|
2014-11-13 20:36:05 +00:00
|
|
|
func setHeaderForSpecialDevice(hdr *tar.Header, ta *tarAppender, name string, stat interface{}) (nlink uint32, inode uint64, err error) {
|
|
|
|
s, ok := stat.(*syscall.Stat_t)
|
|
|
|
|
|
|
|
if !ok {
|
|
|
|
err = errors.New("cannot convert stat value to syscall.Stat_t")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
nlink = uint32(s.Nlink)
|
|
|
|
inode = uint64(s.Ino)
|
|
|
|
|
|
|
|
// Currently go does not fil in the major/minors
|
2015-03-25 01:09:25 +00:00
|
|
|
if s.Mode&syscall.S_IFBLK != 0 ||
|
|
|
|
s.Mode&syscall.S_IFCHR != 0 {
|
2014-11-13 20:36:05 +00:00
|
|
|
hdr.Devmajor = int64(major(uint64(s.Rdev)))
|
|
|
|
hdr.Devminor = int64(minor(uint64(s.Rdev)))
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func major(device uint64) uint64 {
|
|
|
|
return (device >> 8) & 0xfff
|
|
|
|
}
|
|
|
|
|
|
|
|
func minor(device uint64) uint64 {
|
|
|
|
return (device & 0xff) | ((device >> 12) & 0xfff00)
|
|
|
|
}
|