12 "github.com/fsouza/go-dockerclient/external/github.com/docker/docker/pkg/system"
15 // fixVolumePathPrefix does platform specific processing to ensure that if
16 // the path being passed in is not in a volume path format, convert it to one.
17 func fixVolumePathPrefix(srcPath string) string {
21 // getWalkRoot calculates the root path when performing a TarWithOptions.
22 // We use a separate function as this is platform specific. On Linux, we
23 // can't use filepath.Join(srcPath,include) because this will clean away
24 // a trailing "." or "/" which may be important.
25 func getWalkRoot(srcPath string, include string) string {
26 return srcPath + string(filepath.Separator) + include
29 // CanonicalTarNameForPath returns platform-specific filepath
30 // to canonical posix-style path for tar archival. p is relative
32 func CanonicalTarNameForPath(p string) (string, error) {
33 return p, nil // already unix-style
36 // chmodTarEntry is used to adjust the file permissions used in tar header based
37 // on the platform the archival is done.
39 func chmodTarEntry(perm os.FileMode) os.FileMode {
40 return perm // noop for unix as golang APIs provide perm bits correctly
43 func setHeaderForSpecialDevice(hdr *tar.Header, ta *tarAppender, name string, stat interface{}) (inode uint64, err error) {
44 s, ok := stat.(*syscall.Stat_t)
47 err = errors.New("cannot convert stat value to syscall.Stat_t")
53 // Currently go does not fill in the major/minors
54 if s.Mode&syscall.S_IFBLK != 0 ||
55 s.Mode&syscall.S_IFCHR != 0 {
56 hdr.Devmajor = int64(major(uint64(s.Rdev)))
57 hdr.Devminor = int64(minor(uint64(s.Rdev)))
63 func getFileUIDGID(stat interface{}) (int, int, error) {
64 s, ok := stat.(*syscall.Stat_t)
67 return -1, -1, errors.New("cannot convert stat value to syscall.Stat_t")
69 return int(s.Uid), int(s.Gid), nil
72 func major(device uint64) uint64 {
73 return (device >> 8) & 0xfff
76 func minor(device uint64) uint64 {
77 return (device & 0xff) | ((device >> 12) & 0xfff00)
80 // handleTarTypeBlockCharFifo is an OS-specific helper function used by
81 // createTarFile to handle the following types of header: Block; Char; Fifo
82 func handleTarTypeBlockCharFifo(hdr *tar.Header, path string) error {
83 mode := uint32(hdr.Mode & 07777)
86 mode |= syscall.S_IFBLK
88 mode |= syscall.S_IFCHR
90 mode |= syscall.S_IFIFO
93 if err := system.Mknod(path, mode, int(system.Mkdev(hdr.Devmajor, hdr.Devminor))); err != nil {
99 func handleLChmod(hdr *tar.Header, path string, hdrInfo os.FileInfo) error {
100 if hdr.Typeflag == tar.TypeLink {
101 if fi, err := os.Lstat(hdr.Linkname); err == nil && (fi.Mode()&os.ModeSymlink == 0) {
102 if err := os.Chmod(path, hdrInfo.Mode()); err != nil {
106 } else if hdr.Typeflag != tar.TypeSymlink {
107 if err := os.Chmod(path, hdrInfo.Mode()); err != nil {