mirror of
https://github.com/pgsty/minio.git
synced 2026-07-21 13:10:22 +03:00
Add option in readDir to enable symlink following of dirs (#12668)
This commit is contained in:
@@ -98,11 +98,6 @@ func parseDirEnt(buf []byte) (consumed int, name []byte, typ os.FileMode, err er
|
||||
return consumed, nameBuf[:nameLen], typ, nil
|
||||
}
|
||||
|
||||
// Return all the entries at the directory dirPath.
|
||||
func readDir(dirPath string) (entries []string, err error) {
|
||||
return readDirN(dirPath, -1)
|
||||
}
|
||||
|
||||
// readDirFn applies the fn() function on each entries at dirPath, doesn't recurse into
|
||||
// the directory itself, if the dirPath doesn't exist this function doesn't return
|
||||
// an error.
|
||||
@@ -184,7 +179,7 @@ func readDirFn(dirPath string, fn func(name string, typ os.FileMode) error) erro
|
||||
|
||||
// Return count entries at the directory dirPath and all entries
|
||||
// if count is set to -1
|
||||
func readDirN(dirPath string, count int) (entries []string, err error) {
|
||||
func readDirWithOpts(dirPath string, opts readDirOpts) (entries []string, err error) {
|
||||
f, err := Open(dirPath)
|
||||
if err != nil {
|
||||
return nil, osErrToFileErr(err)
|
||||
@@ -202,6 +197,8 @@ func readDirN(dirPath string, count int) (entries []string, err error) {
|
||||
boff := 0 // starting read position in buf
|
||||
nbuf := 0 // end valid data in buf
|
||||
|
||||
count := opts.count
|
||||
|
||||
for count != 0 {
|
||||
if boff >= nbuf {
|
||||
boff = 0
|
||||
@@ -242,7 +239,7 @@ func readDirN(dirPath string, count int) (entries []string, err error) {
|
||||
}
|
||||
|
||||
// Ignore symlinked directories.
|
||||
if typ&os.ModeSymlink == os.ModeSymlink && fi.IsDir() {
|
||||
if !opts.followDirSymlink && typ&os.ModeSymlink == os.ModeSymlink && fi.IsDir() {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user