From 96c02957e79324a3f67c03ca847bfc0c075c2eb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Ravier?= Date: Tue, 25 Oct 2022 18:03:31 +0200 Subject: [PATCH] Revert "mantle: use `os.ReadDir` for lightweight directory reading" This reverts commit c7fb30253e5ac8983a9647873a2921d86640e74b. --- mantle/cmd/kola/switchkernel.go | 3 ++- mantle/kola/harness.go | 25 ++++++++++--------------- mantle/util/repo.go | 3 ++- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/mantle/cmd/kola/switchkernel.go b/mantle/cmd/kola/switchkernel.go index dc08624453..77f0087dd1 100644 --- a/mantle/cmd/kola/switchkernel.go +++ b/mantle/cmd/kola/switchkernel.go @@ -17,6 +17,7 @@ package main import ( "encoding/base64" "fmt" + "io/ioutil" "os" "regexp" "strings" @@ -150,7 +151,7 @@ func runSwitchKernel(cmd *cobra.Command, args []string) error { func dropRpmFilesAll(m platform.Machine, localPath string) error { fmt.Println("Dropping RT Kernel RPMs...") re := regexp.MustCompile(`^kernel-rt-.*\.rpm$`) - files, err := os.ReadDir(localPath) + files, err := ioutil.ReadDir(localPath) if err != nil { return err } diff --git a/mantle/kola/harness.go b/mantle/kola/harness.go index c567b408cb..87d5c9418b 100644 --- a/mantle/kola/harness.go +++ b/mantle/kola/harness.go @@ -1144,28 +1144,23 @@ func testIsDenyListed(testname string) (bool, error) { } // registerTestDir parses one test directory and registers it as a test -func registerTestDir(dir, testprefix string, children []os.DirEntry) error { +func registerTestDir(dir, testprefix string, children []os.FileInfo) error { var dependencydir string var meta externalTestMeta + var err error userdata := conf.EmptyIgnition() executables := []string{} for _, c := range children { fpath := filepath.Join(dir, c.Name()) - - info, err := c.Info() - if err != nil { - return errors.Wrapf(err, "c.Info %s", c.Name()) - } - // follow symlinks; oddly, there's no IsSymlink() - if info.Mode()&os.ModeSymlink != 0 { - info, err = os.Stat(fpath) + if c.Mode()&os.ModeSymlink != 0 { + c, err = os.Stat(fpath) if err != nil { return errors.Wrapf(err, "stat %s", fpath) } } - isreg := info.Mode().IsRegular() - if isreg && (info.Mode().Perm()&0001) > 0 { + isreg := c.Mode().IsRegular() + if isreg && (c.Mode().Perm()&0001) > 0 { executables = append(executables, filepath.Join(dir, c.Name())) } else if isreg && c.Name() == "config.ign" { v, err := ioutil.ReadFile(filepath.Join(dir, c.Name())) @@ -1194,7 +1189,7 @@ func registerTestDir(dir, testprefix string, children []os.DirEntry) error { } } else if c.IsDir() && c.Name() == kolaExtBinDataName { dependencydir = filepath.Join(dir, c.Name()) - } else if info.Mode()&os.ModeSymlink != 0 && c.Name() == kolaExtBinDataName { + } else if c.Mode()&os.ModeSymlink != 0 && c.Name() == kolaExtBinDataName { target, err := filepath.EvalSymlinks(filepath.Join(dir, c.Name())) if err != nil { return err @@ -1202,7 +1197,7 @@ func registerTestDir(dir, testprefix string, children []os.DirEntry) error { dependencydir = target } else if c.IsDir() { subdir := filepath.Join(dir, c.Name()) - subchildren, err := os.ReadDir(subdir) + subchildren, err := ioutil.ReadDir(subdir) if err != nil { return err } @@ -1210,7 +1205,7 @@ func registerTestDir(dir, testprefix string, children []os.DirEntry) error { if err := registerTestDir(subdir, subprefix, subchildren); err != nil { return err } - } else if isreg && (info.Mode().Perm()&0001) == 0 { + } else if isreg && (c.Mode().Perm()&0001) == 0 { file, err := os.Open(filepath.Join(dir, c.Name())) if err != nil { return errors.Wrapf(err, "opening %s", c.Name()) @@ -1249,7 +1244,7 @@ func registerTestDir(dir, testprefix string, children []os.DirEntry) error { func RegisterExternalTestsWithPrefix(dir, prefix string) error { testsdir := filepath.Join(dir, "tests/kola") - children, err := os.ReadDir(testsdir) + children, err := ioutil.ReadDir(testsdir) if err != nil { if os.IsNotExist(err) { // The directory doesn't exist.. Skip registering tests diff --git a/mantle/util/repo.go b/mantle/util/repo.go index 0dd96568a5..d957a0ba25 100644 --- a/mantle/util/repo.go +++ b/mantle/util/repo.go @@ -16,6 +16,7 @@ package util import ( "fmt" + "io/ioutil" "os" "path/filepath" "strings" @@ -66,7 +67,7 @@ func GetLocalFastBuildQemu() (string, error) { } return "", err } - ents, err := os.ReadDir(fastBuildCosaDir) + ents, err := ioutil.ReadDir(fastBuildCosaDir) if err != nil { return "", err }