From d33abcdf102218b04edb6b5176b459eaf10e3b31 Mon Sep 17 00:00:00 2001 From: Daniel J Walsh Date: Mon, 12 Aug 2024 10:26:13 -0400 Subject: [PATCH] Fix race condition when listing /dev Also replace os.IsNotExist(err) with errors.Is(err, fs.ErrNotExist) Fixes: https://github.com/containers/podman/issues/23582 Signed-off-by: Daniel J Walsh --- pkg/util/utils.go | 2 +- pkg/util/utils_linux.go | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/util/utils.go b/pkg/util/utils.go index 602d120549..b225005712 100644 --- a/pkg/util/utils.go +++ b/pkg/util/utils.go @@ -84,7 +84,7 @@ func ParseDockerignore(containerfiles []string, root string) ([]string, string, // does not attempts to re-resolve it ignoreFile = path ignore, dockerIgnoreErr = os.ReadFile(path) - if os.IsNotExist(dockerIgnoreErr) { + if errors.Is(dockerIgnoreErr, fs.ErrNotExist) { // In this case either ignorefile was not found // or it is a symlink to unexpected file in such // case manually set ignorefile to `/dev/null` so diff --git a/pkg/util/utils_linux.go b/pkg/util/utils_linux.go index 85d819b9b2..9130d1f404 100644 --- a/pkg/util/utils_linux.go +++ b/pkg/util/utils_linux.go @@ -191,6 +191,9 @@ func getDevices(path string) ([]spec.LinuxDevice, error) { default: sub, err := getDevices(filepath.Join(path, f.Name())) if err != nil { + if errors.Is(err, fs.ErrNotExist) { + continue + } return nil, err } if sub != nil { @@ -209,7 +212,7 @@ func getDevices(path string) ([]spec.LinuxDevice, error) { if err == errNotADevice { continue } - if os.IsNotExist(err) { + if errors.Is(err, fs.ErrNotExist) { continue } return nil, err