github.com/olljanat/moby@v1.13.1/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/longpath"
    13  )
    14  
    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 {
    18  	return longpath.AddPrefix(srcPath)
    19  }
    20  
    21  // getWalkRoot calculates the root path when performing a TarWithOptions.
    22  // We use a separate function as this is platform specific.
    23  func getWalkRoot(srcPath string, include string) string {
    24  	return filepath.Join(srcPath, include)
    25  }
    26  
    27  // CanonicalTarNameForPath returns platform-specific filepath
    28  // to canonical posix-style path for tar archival. p is relative
    29  // path.
    30  func CanonicalTarNameForPath(p string) (string, error) {
    31  	// windows: convert windows style relative path with backslashes
    32  	// into forward slashes. Since windows does not allow '/' or '\'
    33  	// in file names, it is mostly safe to replace however we must
    34  	// check just in case
    35  	if strings.Contains(p, "/") {
    36  		return "", fmt.Errorf("Windows path contains forward slash: %s", p)
    37  	}
    38  	return strings.Replace(p, string(os.PathSeparator), "/", -1), nil
    39  
    40  }
    41  
    42  // chmodTarEntry is used to adjust the file permissions used in tar header based
    43  // on the platform the archival is done.
    44  func chmodTarEntry(perm os.FileMode) os.FileMode {
    45  	perm &= 0755
    46  	// Add the x bit: make everything +x from windows
    47  	perm |= 0111
    48  
    49  	return perm
    50  }
    51  
    52  func setHeaderForSpecialDevice(hdr *tar.Header, ta *tarAppender, name string, stat interface{}) (inode uint64, err error) {
    53  	// do nothing. no notion of Rdev, Inode, Nlink in stat on Windows
    54  	return
    55  }
    56  
    57  // handleTarTypeBlockCharFifo is an OS-specific helper function used by
    58  // createTarFile to handle the following types of header: Block; Char; Fifo
    59  func handleTarTypeBlockCharFifo(hdr *tar.Header, path string) error {
    60  	return nil
    61  }
    62  
    63  func handleLChmod(hdr *tar.Header, path string, hdrInfo os.FileInfo) error {
    64  	return nil
    65  }
    66  
    67  func getFileUIDGID(stat interface{}) (int, int, error) {
    68  	// no notion of file ownership mapping yet on Windows
    69  	return 0, 0, nil
    70  }