github.com/demonoid81/moby@v0.0.0-20200517203328-62dd8e17c460/pkg/system/path_windows.go (about)

     1  package system // import "github.com/demonoid81/moby/pkg/system"
     2  
     3  import "golang.org/x/sys/windows"
     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, err := windows.UTF16FromString(path)
    11  	if err != nil {
    12  		return "", err
    13  	}
    14  	b := p // GetLongPathName says we can reuse buffer
    15  	n, err := windows.GetLongPathName(&p[0], &b[0], uint32(len(b)))
    16  	if err != nil {
    17  		return "", err
    18  	}
    19  	if n > uint32(len(b)) {
    20  		b = make([]uint16, n)
    21  		_, err = windows.GetLongPathName(&p[0], &b[0], uint32(len(b)))
    22  		if err != nil {
    23  			return "", err
    24  		}
    25  	}
    26  	return windows.UTF16ToString(b), nil
    27  }