github.com/rclone/rclone@v1.66.1-0.20240517100346-7b89735ae726/lib/file/unc_windows.go (about) 1 //go:build windows 2 3 package file 4 5 import ( 6 "regexp" 7 "strings" 8 ) 9 10 // Pattern to match a windows absolute path: "c:\" and similar 11 var isAbsWinDrive = regexp.MustCompile(`^[a-zA-Z]\:\\`) 12 13 // UNCPath converts an absolute Windows path to a UNC long path. 14 // 15 // It does nothing on non windows platforms 16 func UNCPath(l string) string { 17 // If prefix is "\\", we already have a UNC path or server. 18 if strings.HasPrefix(l, `\\`) { 19 // If already long path, just keep it 20 if strings.HasPrefix(l, `\\?\`) { 21 return l 22 } 23 24 // Trim "\\" from path and add UNC prefix. 25 return `\\?\UNC\` + strings.TrimPrefix(l, `\\`) 26 } 27 if isAbsWinDrive.MatchString(l) { 28 return `\\?\` + l 29 } 30 return l 31 }