|
@@ -9,19 +9,22 @@ import (
|
|
|
"golang.org/x/sys/windows"
|
|
|
)
|
|
|
|
|
|
-const (
|
|
|
- // SddlAdministratorsLocalSystem is local administrators plus NT AUTHORITY\System
|
|
|
- SddlAdministratorsLocalSystem = "D:P(A;OICI;GA;;;BA)(A;OICI;GA;;;SY)"
|
|
|
-)
|
|
|
+// SddlAdministratorsLocalSystem is local administrators plus NT AUTHORITY\System.
|
|
|
+const SddlAdministratorsLocalSystem = "D:P(A;OICI;GA;;;BA)(A;OICI;GA;;;SY)"
|
|
|
+
|
|
|
+// volumePath is a regular expression to check if a path is a Windows
|
|
|
+// volume path (e.g., "\\?\Volume{4c1b02c1-d990-11dc-99ae-806e6f6e6963}".
|
|
|
+var volumePath = regexp.MustCompile(`^\\\\\?\\Volume{[a-z0-9-]+}$`)
|
|
|
|
|
|
-// MkdirAllWithACL is a wrapper for MkdirAll that creates a directory
|
|
|
-// with an appropriate SDDL defined ACL.
|
|
|
-func MkdirAllWithACL(path string, perm os.FileMode, sddl string) error {
|
|
|
+// MkdirAllWithACL is a custom version of os.MkdirAll modified for use on Windows
|
|
|
+// so that it is both volume path aware, and can create a directory with
|
|
|
+// an appropriate SDDL defined ACL.
|
|
|
+func MkdirAllWithACL(path string, _ os.FileMode, sddl string) error {
|
|
|
return mkdirall(path, true, sddl)
|
|
|
}
|
|
|
|
|
|
-// MkdirAll implementation that is volume path aware for Windows. It can be used
|
|
|
-// as a drop-in replacement for os.MkdirAll()
|
|
|
+// MkdirAll is a custom version of os.MkdirAll that is volume path aware for
|
|
|
+// Windows. It can be used as a drop-in replacement for os.MkdirAll.
|
|
|
func MkdirAll(path string, _ os.FileMode) error {
|
|
|
return mkdirall(path, false, "")
|
|
|
}
|
|
@@ -30,7 +33,7 @@ func MkdirAll(path string, _ os.FileMode) error {
|
|
|
// so that it is both volume path aware, and can create a directory with
|
|
|
// a DACL.
|
|
|
func mkdirall(path string, applyACL bool, sddl string) error {
|
|
|
- if re := regexp.MustCompile(`^\\\\\?\\Volume{[a-z0-9-]+}$`); re.MatchString(path) {
|
|
|
+ if volumePath.MatchString(path) {
|
|
|
return nil
|
|
|
}
|
|
|
|