Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

lib/file: fix MkdirAll after go1.21.4 stdlib update

Nick Craig-Woodacf1e2df84a3
diff --git a/lib/file/mkdir_windows.go b/lib/file/mkdir_windows.go
index 73a82ac62..929587fd8 100644
--- a/lib/file/mkdir_windows.go
+++ b/lib/file/mkdir_windows.go
@@ -53,7 +53,7 @@ func MkdirAll(path string, perm os.FileMode) error {
j--
}
if j > 1 {
- if path[:j-1] != `\\?\UNC` {
+ if path[:j-1] != `\\?\UNC` && path[:j-1] != `\\?` {
// Create parent.
err = MkdirAll(path[:j-1], perm)
if err != nil {
diff --git a/lib/file/mkdir_windows_test.go b/lib/file/mkdir_windows_test.go
index 2750e2dc3..a969f2d7f 100644
--- a/lib/file/mkdir_windows_test.go
+++ b/lib/file/mkdir_windows_test.go
@@ -89,7 +89,7 @@ func checkMkdirAll(t *testing.T, path string, valid bool, errormsgs ...string) {
ok = true
}
}
- assert.True(t, ok, err.Error())
+ assert.True(t, ok, fmt.Sprintf("Error message '%v' didn't match any of %v", err, errormsgs))
}
}
@@ -114,7 +114,7 @@ func TestMkdirAllOnDrive(t *testing.T) {
checkMkdirAll(t, drive, true, "")
checkMkdirAll(t, drive+`\`, true, "")
- checkMkdirAll(t, `\\?\`+drive, true, "")
+ // checkMkdirAll(t, `\\?\`+drive, true, "") - this isn't actually a Valid Windows path - this test used to work under go1.21.3 but fails under go1.21.4
checkMkdirAll(t, `\\?\`+drive+`\`, true, "")
checkMkdirAllSubdirs(t, path, true, "")
checkMkdirAllSubdirs(t, `\\?\`+path, true, "")
@@ -129,10 +129,11 @@ func TestMkdirAllOnDrive(t *testing.T) {
// "mkdir \\?\A:\: The system cannot find the path specified."
func TestMkdirAllOnUnusedDrive(t *testing.T) {
path := unusedDrive(t)
- errormsg := fmt.Sprintf("mkdir %s\\: The system cannot find the path specified.", path)
+ errormsg := fmt.Sprintf(`mkdir %s\: The system cannot find the path specified.`, path)
checkMkdirAllSubdirs(t, path, false, errormsg)
- errormsg = fmt.Sprintf("mkdir \\\\?\\%s\\: The system cannot find the path specified.", path)
- checkMkdirAllSubdirs(t, `\\?\`+path, false, errormsg)
+ errormsg1 := fmt.Sprintf(`mkdir \\?\%s\: The system cannot find the path specified.`, path) // pre go1.21.4
+ errormsg2 := fmt.Sprintf(`mkdir \\?\%s: The system cannot find the file specified.`, path) // go1.21.4 and after
+ checkMkdirAllSubdirs(t, `\\?\`+path, false, errormsg1, errormsg2)
}
// Testing paths on unknown network host