github.com/sams1990/dockerrepo@v17.12.1-ce-rc2+incompatible/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  	"github.com/docker/docker/pkg/idtools"
    13  	"github.com/docker/docker/pkg/longpath"
    14  )
    15  
    16  // fixVolumePathPrefix does platform specific processing to ensure that if
    17  // the path being passed in is not in a volume path format, convert it to one.
    18  func fixVolumePathPrefix(srcPath string) string {
    19  	return longpath.AddPrefix(srcPath)
    20  }
    21  
    22  // getWalkRoot calculates the root path when performing a TarWithOptions.
    23  // We use a separate 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 // this 0-ed out tar flags (like link, regular file, directory marker etc.)
    47  	permPart := perm & os.ModePerm
    48  	noPermPart := perm &^ os.ModePerm
    49  	// Add the x bit: make everything +x from windows
    50  	permPart |= 0111
    51  	permPart &= 0755
    52  
    53  	return noPermPart | permPart
    54  }
    55  
    56  func setHeaderForSpecialDevice(hdr *tar.Header, name string, stat interface{}) (err error) {
    57  	// do nothing. no notion of Rdev, Nlink in stat on Windows
    58  	return
    59  }
    60  
    61  func getInodeFromStat(stat interface{}) (inode uint64, err error) {
    62  	// do nothing. no notion of Inode in stat on Windows
    63  	return
    64  }
    65  
    66  // handleTarTypeBlockCharFifo is an OS-specific helper function used by
    67  // createTarFile to handle the following types of header: Block; Char; Fifo
    68  func handleTarTypeBlockCharFifo(hdr *tar.Header, path string) error {
    69  	return nil
    70  }
    71  
    72  func handleLChmod(hdr *tar.Header, path string, hdrInfo os.FileInfo) error {
    73  	return nil
    74  }
    75  
    76  func getFileUIDGID(stat interface{}) (idtools.IDPair, error) {
    77  	// no notion of file ownership mapping yet on Windows
    78  	return idtools.IDPair{0, 0}, nil
    79  }