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