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