github.com/Prakhar-Agarwal-byte/moby@v0.0.0-20231027092010-a14e3e8ab87e/integration-cli/utils_windows_test.go (about)

     1  package main
     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  }