From 837e2eea78cc1cf5f93fce9a27612fe8c32b271b Mon Sep 17 00:00:00 2001 From: Matt Carroll Date: Wed, 18 Dec 2019 15:25:41 +0000 Subject: [PATCH 1/3] Make scanDirectory follow symlinks --- config/scanner.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/config/scanner.go b/config/scanner.go index 798aaf5..bbf5e4a 100644 --- a/config/scanner.go +++ b/config/scanner.go @@ -63,6 +63,17 @@ func (s *scanner) scanDirectory(directory string) error { for _, fi := range fi { pathName := path.Clean(directory + "/" + fi.Name()) + if fi.Mode() & os.ModeSymlink == os.ModeSymlink { + linkpath, err := os.Readlink(directory + fi.Name()) + if err != nil { + return err + } + fi, err = os.Lstat(linkpath) + if err != nil { + return err + } + } + // regular file if fi.Mode().IsRegular() { if !s.shouldProcess(pathName) { From a6422bc85ca8b63e8807b2955469fe58efcbe335 Mon Sep 17 00:00:00 2001 From: Matthew Carroll Date: Wed, 18 Dec 2019 07:50:05 -0800 Subject: [PATCH 2/3] Corrected symlink resolution --- config/scanner.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/scanner.go b/config/scanner.go index bbf5e4a..82102e5 100644 --- a/config/scanner.go +++ b/config/scanner.go @@ -64,11 +64,11 @@ func (s *scanner) scanDirectory(directory string) error { pathName := path.Clean(directory + "/" + fi.Name()) if fi.Mode() & os.ModeSymlink == os.ModeSymlink { - linkpath, err := os.Readlink(directory + fi.Name()) + linkpath, err := os.Readlink(directory + "/" + fi.Name()) if err != nil { return err } - fi, err = os.Lstat(linkpath) + fi, err = os.Lstat(directory + "/" + linkpath) if err != nil { return err } From 8c27db405ed93fe9cff807070d6b2f9809fe4dc3 Mon Sep 17 00:00:00 2001 From: Matthew Carroll Date: Wed, 18 Dec 2019 08:21:29 -0800 Subject: [PATCH 3/3] Handle absolute paths properly --- config/scanner.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/config/scanner.go b/config/scanner.go index 82102e5..8955995 100644 --- a/config/scanner.go +++ b/config/scanner.go @@ -68,7 +68,13 @@ func (s *scanner) scanDirectory(directory string) error { if err != nil { return err } - fi, err = os.Lstat(directory + "/" + linkpath) + fullPath := "" + if filepath.IsAbs(linkpath) { + fullPath = linkpath + } else { + fullPath = directory + "/" + linkpath + } + fi, err = os.Lstat(fullPath) if err != nil { return err }