github.com/zhouyu0/docker-note@v0.0.0-20190722021225-b8d3825084db/pkg/system/path_windows.go (about)

     1  package system // import "github.com/docker/docker/pkg/system"
     2  
     3  import "syscall"
     4  
     5  // GetLongPathName converts Windows short pathnames to full pathnames.
     6  // For example C:\Users\ADMIN~1 --> C:\Users\Administrator.
     7  // It is a no-op on non-Windows platforms
     8  func GetLongPathName(path string) (string, error) {
     9  	// See https://groups.google.com/forum/#!topic/golang-dev/1tufzkruoTg
    10  	p := syscall.StringToUTF16(path)
    11  	b := p // GetLongPathName says we can reuse buffer
    12  	n, err := syscall.GetLongPathName(&p[0], &b[0], uint32(len(b)))
    13  	if err != nil {
    14  		return "", err
    15  	}
    16  	if n > uint32(len(b)) {
    17  		b = make([]uint16, n)
    18  		_, err = syscall.GetLongPathName(&p[0], &b[0], uint32(len(b)))
    19  		if err != nil {
    20  			return "", err
    21  		}
    22  	}
    23  	return syscall.UTF16ToString(b), nil
    24  }