forked from twpayne/go-vfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
windows.go
42 lines (35 loc) · 1.1 KB
/
windows.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// +build windows
package vfs
import (
"path/filepath"
"strings"
"syscall"
"golang.org/x/sys/windows"
)
// HostOSFS is the host-specific OSFS.
var HostOSFS = WindowsOSFS{}
var ignoreErrnoInContains = map[syscall.Errno]struct{}{
syscall.ELOOP: {},
syscall.EMLINK: {},
syscall.ENAMETOOLONG: {},
syscall.ENOENT: {},
syscall.EOVERFLOW: {},
windows.ERROR_CANT_RESOLVE_FILENAME: {},
}
// relativizePath, on Windows, strips any leading volume name from path and
// replaces backslashes with slashes.
func relativizePath(path string) string {
if volumeName := filepath.VolumeName(path); volumeName != "" {
path = path[len(volumeName):]
}
return filepath.ToSlash(path)
}
// trimPrefix, on Windows, trims prefix from path and returns an absolute path.
// prefix must be a /-separated path.
func trimPrefix(path, prefix string) (string, error) {
trimmedPath, err := filepath.Abs(strings.TrimPrefix(filepath.ToSlash(path), prefix))
if err != nil {
return "", err
}
return filepath.ToSlash(trimmedPath), nil
}