Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "mantle: use os.ReadDir for lightweight directory reading" #3137

Merged
merged 1 commit into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion mantle/cmd/kola/switchkernel.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package main
import (
"encoding/base64"
"fmt"
"io/ioutil"
"os"
"regexp"
"strings"
Expand Down Expand Up @@ -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
}
Expand Down
25 changes: 10 additions & 15 deletions mantle/kola/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down Expand Up @@ -1194,23 +1189,23 @@ 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
}
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
}
subprefix := fmt.Sprintf("%s.%s", testprefix, c.Name())
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())
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion mantle/util/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package util

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -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
}
Expand Down