Skip to content

Commit

Permalink
Fix race condition when listing /dev
Browse files Browse the repository at this point in the history
Also replace os.IsNotExist(err) with errors.Is(err, fs.ErrNotExist)

Fixes: containers#23582

Signed-off-by: Daniel J Walsh <[email protected]>
  • Loading branch information
rhatdan committed Aug 12, 2024
1 parent 708d6c5 commit d33abcd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/util/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion pkg/util/utils_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down

0 comments on commit d33abcd

Please sign in to comment.