github.com/a4a881d4/docker@v1.9.0-rc2/pkg/longpath/longpath.go (about)

     1  // longpath introduces some constants and helper functions for handling long paths
     2  // in Windows, which are expected to be prepended with `\\?\` and followed by either
     3  // a drive letter, a UNC server\share, or a volume identifier.
     4  
     5  package longpath
     6  
     7  import (
     8  	"strings"
     9  )
    10  
    11  // Prefix is the longpath prefix for Windows file paths.
    12  const Prefix = `\\?\`
    13  
    14  // AddPrefix will add the Windows long path prefix to the path provided if
    15  // it does not already have it.
    16  func AddPrefix(path string) string {
    17  	if !strings.HasPrefix(path, Prefix) {
    18  		if strings.HasPrefix(path, `\\`) {
    19  			// This is a UNC path, so we need to add 'UNC' to the path as well.
    20  			path = Prefix + `UNC` + path[1:]
    21  		} else {
    22  			path = Prefix + path
    23  		}
    24  	}
    25  	return path
    26  }