From 52e2e9114acf1657aaa033ff7d672e0048695793 Mon Sep 17 00:00:00 2001 From: jbtrystram Date: Mon, 28 Aug 2023 20:12:54 +0200 Subject: [PATCH] [mantle/kola] Fix test loading logic with symlinks Added a separate block to address symlinks loading. It should work with nested symlinks, as it simply recurse calls with the resolved path, but I have not tested it. Fixes #3135 --- mantle/kola/harness.go | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/mantle/kola/harness.go b/mantle/kola/harness.go index d34f27710b..4f89b9c554 100644 --- a/mantle/kola/harness.go +++ b/mantle/kola/harness.go @@ -1307,13 +1307,39 @@ func registerTestDir(dir, testprefix string, children []os.DirEntry) error { return fmt.Errorf("getting info for %q: %w", e.Name(), err) } fpath := filepath.Join(dir, c.Name()) - // follow symlinks; oddly, there's no IsSymlink() + if c.Mode()&os.ModeSymlink != 0 { - c, err = os.Stat(fpath) + // follow symlinks; oddly, there's no IsSymlink() + // This should work with nested symlinks but it have not been tested + dest, err := os.Readlink(fpath) + if err != nil { + return errors.Wrapf(err, "could not resolve symlink: %s", fpath) + } + resolved := filepath.Join(dir, dest) + destinfo, err := os.Stat(resolved) if err != nil { return errors.Wrapf(err, "stat %s", fpath) } + + // If the symlink point to a directory, simply do the recursive call + // with the resolved path + // we don't carry on with the resolved path because the logic below + // construct a file path, which is alrady done when resolving the symlink + if destinfo.IsDir() { + subchildren, err := os.ReadDir(resolved) + if err != nil { + return err + } + subprefix := fmt.Sprintf("%s.%s", testprefix, c.Name()) + if err := registerTestDir(resolved, subprefix, subchildren); err != nil { + return err + } + // otherwise, carry on with the resolved file + } else { + c = destinfo + } } + isreg := c.Mode().IsRegular() if isreg && (c.Mode().Perm()&0001) > 0 { executables = append(executables, filepath.Join(dir, c.Name()))