|
|
@ -22,7 +22,6 @@ import ( |
|
|
|
"os" |
|
|
|
"os" |
|
|
|
"path" |
|
|
|
"path" |
|
|
|
"runtime" |
|
|
|
"runtime" |
|
|
|
"strings" |
|
|
|
|
|
|
|
"sync" |
|
|
|
"sync" |
|
|
|
"syscall" |
|
|
|
"syscall" |
|
|
|
"unsafe" |
|
|
|
"unsafe" |
|
|
@ -124,18 +123,12 @@ func readDirN(dirPath string, count int) (entries []string, err error) { |
|
|
|
|
|
|
|
|
|
|
|
d, err := os.Open(dirPath) |
|
|
|
d, err := os.Open(dirPath) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
// File is really not found.
|
|
|
|
if os.IsNotExist(err) || isSysErrNotDir(err) { |
|
|
|
if os.IsNotExist(err) { |
|
|
|
|
|
|
|
return nil, errFileNotFound |
|
|
|
return nil, errFileNotFound |
|
|
|
} |
|
|
|
} |
|
|
|
if os.IsPermission(err) { |
|
|
|
if os.IsPermission(err) { |
|
|
|
return nil, errFileAccessDenied |
|
|
|
return nil, errFileAccessDenied |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// File path cannot be verified since one of the parents is a file.
|
|
|
|
|
|
|
|
if strings.Contains(err.Error(), "not a directory") { |
|
|
|
|
|
|
|
return nil, errFileNotFound |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return nil, err |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
} |
|
|
|
defer d.Close() |
|
|
|
defer d.Close() |
|
|
@ -148,6 +141,9 @@ func readDirN(dirPath string, count int) (entries []string, err error) { |
|
|
|
for !done { |
|
|
|
for !done { |
|
|
|
nbuf, err := syscall.ReadDirent(fd, buf) |
|
|
|
nbuf, err := syscall.ReadDirent(fd, buf) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
if isSysErrNotDir(err) { |
|
|
|
|
|
|
|
return nil, errFileNotFound |
|
|
|
|
|
|
|
} |
|
|
|
return nil, err |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
} |
|
|
|
if nbuf <= 0 { |
|
|
|
if nbuf <= 0 { |
|
|
|