Skip to content

Commit

Permalink
pkg/parse: use fileutils.(Le|E)xists
Browse files Browse the repository at this point in the history
Signed-off-by: Giuseppe Scrivano <[email protected]>
  • Loading branch information
giuseppe committed Apr 12, 2024
1 parent 7053383 commit 441bdc9
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions pkg/parse/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package parse
import (
"errors"
"fmt"
"io/fs"
"net"
"os"
"path/filepath"
Expand All @@ -26,6 +27,7 @@ import (
"github.com/containers/common/pkg/parse"
"github.com/containers/image/v5/docker/reference"
"github.com/containers/image/v5/types"
"github.com/containers/storage/pkg/fileutils"
"github.com/containers/storage/pkg/idtools"
"github.com/containers/storage/pkg/unshare"
storageTypes "github.com/containers/storage/types"
Expand Down Expand Up @@ -252,14 +254,14 @@ func parseSecurityOpts(securityOpts []string, commonOpts *define.CommonBuildOpti
}

if commonOpts.SeccompProfilePath == "" {
if _, err := os.Stat(SeccompOverridePath); err == nil {
if err := fileutils.Exists(SeccompOverridePath); err == nil {
commonOpts.SeccompProfilePath = SeccompOverridePath
} else {
if !errors.Is(err, os.ErrNotExist) {
if !errors.Is(err, fs.ErrNotExist) {
return err
}
if _, err := os.Stat(SeccompDefaultPath); err != nil {
if !errors.Is(err, os.ErrNotExist) {
if err := fileutils.Exists(SeccompDefaultPath); err != nil {
if !errors.Is(err, fs.ErrNotExist) {
return err
}
} else {
Expand Down Expand Up @@ -982,7 +984,7 @@ func IDMappingOptionsFromFlagSet(flags *pflag.FlagSet, persistentFlags *pflag.Fl
usernsOption.Host = true
default:
how = strings.TrimPrefix(how, "ns:")
if _, err := os.Stat(how); err != nil {
if err := fileutils.Exists(how); err != nil {
return nil, nil, fmt.Errorf("checking %s namespace: %w", string(specs.UserNamespace), err)
}
logrus.Debugf("setting %q namespace to %q", string(specs.UserNamespace), how)
Expand Down Expand Up @@ -1077,7 +1079,7 @@ func NamespaceOptionsFromFlagSet(flags *pflag.FlagSet, findFlagFunc func(name st
how = strings.TrimPrefix(how, "ns:")
// if not a path we assume it is a comma separated network list, see setupNamespaces() in run_linux.go
if filepath.IsAbs(how) || what != string(specs.NetworkNamespace) {
if _, err := os.Stat(how); err != nil {
if err := fileutils.Exists(how); err != nil {
return nil, define.NetworkDefault, fmt.Errorf("checking %s namespace: %w", what, err)
}
}
Expand Down Expand Up @@ -1243,7 +1245,7 @@ func Secrets(secrets []string) (map[string]define.Secret, error) {
if err != nil {
return nil, fmt.Errorf("could not parse secrets: %w", err)
}
_, err = os.Stat(fullPath)
err = fileutils.Exists(fullPath)
if err != nil {
return nil, fmt.Errorf("could not parse secrets: %w", err)
}
Expand Down Expand Up @@ -1293,10 +1295,10 @@ func ContainerIgnoreFile(contextDir, path string, containerFiles []string) ([]st
containerfile = filepath.Join(contextDir, containerfile)
}
containerfileIgnore := ""
if _, err := os.Stat(containerfile + ".containerignore"); err == nil {
if err := fileutils.Exists(containerfile + ".containerignore"); err == nil {
containerfileIgnore = containerfile + ".containerignore"
}
if _, err := os.Stat(containerfile + ".dockerignore"); err == nil {
if err := fileutils.Exists(containerfile + ".dockerignore"); err == nil {
containerfileIgnore = containerfile + ".dockerignore"
}
if containerfileIgnore != "" {
Expand Down

0 comments on commit 441bdc9

Please sign in to comment.