mirror of
https://github.com/rclone/rclone.git
synced 2024-11-25 01:44:41 +01:00
lib/file: check if path has nounc while checking max path for windows
This commit is contained in:
parent
3b697538f5
commit
1dc85e5fca
@ -8,6 +8,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"golang.org/x/sys/windows/registry"
|
"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
|
// For windows the max path length is 260 characters
|
||||||
// if the LongPathsEnabled is not set
|
// if the LongPathsEnabled is not set
|
||||||
// https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation
|
// https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation
|
||||||
if !IsLongPathsEnabled() && len(path) >= 260 {
|
if !strings.HasPrefix(path, `\\?\`) && !IsLongPathsEnabled() && len(path) >= 260 {
|
||||||
return nil, &os.PathError{Path: path, Op: "open", Err: errors.New("path length higher than 260")}
|
return nil, &os.PathError{Path: path, Op: "open", Err: errors.New("path length 260 or higher")}
|
||||||
}
|
}
|
||||||
|
|
||||||
pathp, err := syscall.UTF16PtrFromString(path)
|
pathp, err := syscall.UTF16PtrFromString(path)
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -21,8 +22,8 @@ func MkdirAll(path string, perm os.FileMode) error {
|
|||||||
// For windows the max path length is 260 characters
|
// For windows the max path length is 260 characters
|
||||||
// if the LongPathsEnabled is not set
|
// if the LongPathsEnabled is not set
|
||||||
// https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation
|
// https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation
|
||||||
if !IsLongPathsEnabled() && len(path) >= 260 {
|
if !strings.HasPrefix(path, `\\?\`) && !IsLongPathsEnabled() && len(path) >= 260 {
|
||||||
return &os.PathError{Path: path, Op: "open", Err: errors.New("path length higher than 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.
|
// Fast path: if we can tell whether path is a directory or file, stop with success or error.
|
||||||
|
Loading…
Reference in New Issue
Block a user