github.com/rhatdan/docker@v0.7.7-0.20180119204836-47a0dcbcd20a/pkg/archive/archive_windows.go (about) 1 package archive 2 3 import ( 4 "archive/tar" 5 "fmt" 6 "os" 7 "path/filepath" 8 "strings" 9 10 "github.com/docker/docker/pkg/idtools" 11 "github.com/docker/docker/pkg/longpath" 12 ) 13 14 // fixVolumePathPrefix does platform specific processing to ensure that if 15 // the path being passed in is not in a volume path format, convert it to one. 16 func fixVolumePathPrefix(srcPath string) string { 17 return longpath.AddPrefix(srcPath) 18 } 19 20 // getWalkRoot calculates the root path when performing a TarWithOptions. 21 // We use a separate function as this is platform specific. 22 func getWalkRoot(srcPath string, include string) string { 23 return filepath.Join(srcPath, include) 24 } 25 26 // CanonicalTarNameForPath returns platform-specific filepath 27 // to canonical posix-style path for tar archival. p is relative 28 // path. 29 func CanonicalTarNameForPath(p string) (string, error) { 30 // windows: convert windows style relative path with backslashes 31 // into forward slashes. Since windows does not allow '/' or '\' 32 // in file names, it is mostly safe to replace however we must 33 // check just in case 34 if strings.Contains(p, "/") { 35 return "", fmt.Errorf("Windows path contains forward slash: %s", p) 36 } 37 return strings.Replace(p, string(os.PathSeparator), "/", -1), nil 38 39 } 40 41 // chmodTarEntry is used to adjust the file permissions used in tar header based 42 // on the platform the archival is done. 43 func chmodTarEntry(perm os.FileMode) os.FileMode { 44 //perm &= 0755 // this 0-ed out tar flags (like link, regular file, directory marker etc.) 45 permPart := perm & os.ModePerm 46 noPermPart := perm &^ os.ModePerm 47 // Add the x bit: make everything +x from windows 48 permPart |= 0111 49 permPart &= 0755 50 51 return noPermPart | permPart 52 } 53 54 func setHeaderForSpecialDevice(hdr *tar.Header, name string, stat interface{}) (err error) { 55 // do nothing. no notion of Rdev, Nlink in stat on Windows 56 return 57 } 58 59 func getInodeFromStat(stat interface{}) (inode uint64, err error) { 60 // do nothing. no notion of Inode in stat on Windows 61 return 62 } 63 64 // handleTarTypeBlockCharFifo is an OS-specific helper function used by 65 // createTarFile to handle the following types of header: Block; Char; Fifo 66 func handleTarTypeBlockCharFifo(hdr *tar.Header, path string) error { 67 return nil 68 } 69 70 func handleLChmod(hdr *tar.Header, path string, hdrInfo os.FileInfo) error { 71 return nil 72 } 73 74 func getFileUIDGID(stat interface{}) (idtools.IDPair, error) { 75 // no notion of file ownership mapping yet on Windows 76 return idtools.IDPair{0, 0}, nil 77 }