-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfs_localize.go
More file actions
38 lines (33 loc) · 784 Bytes
/
Copy pathfs_localize.go
File metadata and controls
38 lines (33 loc) · 784 Bytes
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
package command
import (
"context"
"strings"
"lesiw.io/fs"
)
var _ fs.LocalizeFS = (*cmdFS)(nil)
func (cfs *cmdFS) Localize(
ctx context.Context, name string,
) (result string, err error) {
if err = cfs.init(ctx); err != nil {
return "", err
}
return localize(ctx, cfs.kind, name)
}
func localize(
_ context.Context, kind cfsKind, name string,
) (string, error) {
switch kind {
case kindGNU, kindBSD:
// Unix paths are already in the correct format.
return name, nil
case kindWindows, kindDOS:
// Early exit: path already looks localized (contains backslash).
if strings.Contains(name, "\\") {
return name, nil
}
// Convert forward slashes to backslashes.
return strings.ReplaceAll(name, "/", "\\"), nil
default:
return "", errUnsupportedOS
}
}