diff --git a/lib/file/file_windows.go b/lib/file/file_windows.go index f617c28e7..c2ba100f4 100644 --- a/lib/file/file_windows.go +++ b/lib/file/file_windows.go @@ -8,6 +8,7 @@ import ( "os" "path/filepath" "regexp" + "strings" "syscall" "golang.org/x/sys/windows/registry" @@ -34,8 +35,8 @@ func OpenFile(path string, mode int, perm os.FileMode) (*os.File, error) { // For windows the max path length is 260 characters // if the LongPathsEnabled is not set // https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation - if !IsLongPathsEnabled() && len(path) >= 260 { - return nil, &os.PathError{Path: path, Op: "open", Err: errors.New("path length higher than 260")} + if !strings.HasPrefix(path, `\\?\`) && !IsLongPathsEnabled() && len(path) >= 260 { + return nil, &os.PathError{Path: path, Op: "open", Err: errors.New("path length 260 or higher")} } pathp, err := syscall.UTF16PtrFromString(path) diff --git a/lib/file/mkdir_windows.go b/lib/file/mkdir_windows.go index 0ef6c16d4..0e338e790 100644 --- a/lib/file/mkdir_windows.go +++ b/lib/file/mkdir_windows.go @@ -7,6 +7,7 @@ import ( "errors" "os" "path/filepath" + "strings" "syscall" ) @@ -21,8 +22,8 @@ func MkdirAll(path string, perm os.FileMode) error { // For windows the max path length is 260 characters // if the LongPathsEnabled is not set // https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation - if !IsLongPathsEnabled() && len(path) >= 260 { - return &os.PathError{Path: path, Op: "open", Err: errors.New("path length higher than 260")} + if !strings.HasPrefix(path, `\\?\`) && !IsLongPathsEnabled() && len(path) >= 260 { + return &os.PathError{Path: path, Op: "open", Err: errors.New("path length 260 or higher")} } // Fast path: if we can tell whether path is a directory or file, stop with success or error.