Skip to content

Commit cfef1b1

Browse files
committed
pkg/system: compile volume-path regex once, and update GoDoc
Ideally, we would construct this lazily, but adding a function and a sync.Once felt like a bit "too much". Also updated the GoDoc for some functions to better describe what they do. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent af10b35 commit cfef1b1

1 file changed

Lines changed: 13 additions & 10 deletions

File tree

pkg/system/filesys_windows.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,22 @@ import (
99
"golang.org/x/sys/windows"
1010
)
1111

12-
const (
13-
// SddlAdministratorsLocalSystem is local administrators plus NT AUTHORITY\System
14-
SddlAdministratorsLocalSystem = "D:P(A;OICI;GA;;;BA)(A;OICI;GA;;;SY)"
15-
)
12+
// SddlAdministratorsLocalSystem is local administrators plus NT AUTHORITY\System.
13+
const SddlAdministratorsLocalSystem = "D:P(A;OICI;GA;;;BA)(A;OICI;GA;;;SY)"
14+
15+
// volumePath is a regular expression to check if a path is a Windows
16+
// volume path (e.g., "\\?\Volume{4c1b02c1-d990-11dc-99ae-806e6f6e6963}".
17+
var volumePath = regexp.MustCompile(`^\\\\\?\\Volume{[a-z0-9-]+}$`)
1618

17-
// MkdirAllWithACL is a wrapper for MkdirAll that creates a directory
18-
// with an appropriate SDDL defined ACL.
19-
func MkdirAllWithACL(path string, perm os.FileMode, sddl string) error {
19+
// MkdirAllWithACL is a custom version of os.MkdirAll modified for use on Windows
20+
// so that it is both volume path aware, and can create a directory with
21+
// an appropriate SDDL defined ACL.
22+
func MkdirAllWithACL(path string, _ os.FileMode, sddl string) error {
2023
return mkdirall(path, true, sddl)
2124
}
2225

23-
// MkdirAll implementation that is volume path aware for Windows. It can be used
24-
// as a drop-in replacement for os.MkdirAll()
26+
// MkdirAll is a custom version of os.MkdirAll that is volume path aware for
27+
// Windows. It can be used as a drop-in replacement for os.MkdirAll.
2528
func MkdirAll(path string, _ os.FileMode) error {
2629
return mkdirall(path, false, "")
2730
}
@@ -30,7 +33,7 @@ func MkdirAll(path string, _ os.FileMode) error {
3033
// so that it is both volume path aware, and can create a directory with
3134
// a DACL.
3235
func mkdirall(path string, applyACL bool, sddl string) error {
33-
if re := regexp.MustCompile(`^\\\\\?\\Volume{[a-z0-9-]+}$`); re.MatchString(path) {
36+
if volumePath.MatchString(path) {
3437
return nil
3538
}
3639

0 commit comments

Comments
 (0)