fix: Bring support for symlink on regular files on NAS (#11383)

fixes #11203
This commit is contained in:
Harshavardhana
2021-02-20 00:30:12 -08:00
committed by GitHub
parent 85d2187c20
commit 8cad407e0b
5 changed files with 155 additions and 23 deletions
+36 -3
View File
@@ -56,6 +56,24 @@ func readDirFn(dirPath string, filter func(name string, typ os.FileMode) error)
return osErrToFileErr(err)
}
for _, fi := range fis {
if fi.Mode()&os.ModeSymlink == os.ModeSymlink {
fi, err = os.Stat(pathJoin(dirPath, fi.Name()))
if err != nil {
// It got deleted in the meantime, not found
// or returns too many symlinks ignore this
// file/directory.
if osIsNotExist(err) || isSysErrPathNotFound(err) ||
isSysErrTooManySymlinks(err) {
continue
}
return err
}
// Ignore symlinked directories.
if fi.IsDir() {
continue
}
}
if err = filter(fi.Name(), fi.Mode()); err == errDoneForNow {
// filtering requested to return by caller.
return nil
@@ -97,11 +115,26 @@ func readDirN(dirPath string, count int) (entries []string, err error) {
}
}
for _, fi := range fis {
// Not need to follow symlink.
if fi.Mode()&os.ModeSymlink == os.ModeSymlink {
continue
fi, err = os.Stat(pathJoin(dirPath, fi.Name()))
if err != nil {
// It got deleted in the meantime, not found
// or returns too many symlinks ignore this
// file/directory.
if osIsNotExist(err) || isSysErrPathNotFound(err) ||
isSysErrTooManySymlinks(err) {
continue
}
return err
}
// Ignore symlinked directories.
if fi.IsDir() {
continue
}
}
if fi.Mode().IsDir() {
if fi.IsDir() {
// Append SlashSeparator instead of "\" so that sorting is achieved as expected.
entries = append(entries, fi.Name()+SlashSeparator)
} else if fi.Mode().IsRegular() {