diff --git a/pkg/api/handlers/compat/containers_create.go b/pkg/api/handlers/compat/containers_create.go index d6ef33dac6..cef33d37dd 100644 --- a/pkg/api/handlers/compat/containers_create.go +++ b/pkg/api/handlers/compat/containers_create.go @@ -27,6 +27,7 @@ import ( "github.com/containers/podman/v5/pkg/specgen" "github.com/containers/podman/v5/pkg/specgenutil" "github.com/containers/storage" + "github.com/containers/storage/pkg/fileutils" "github.com/docker/docker/api/types/mount" ) @@ -527,7 +528,7 @@ func cliOpts(cc handlers.CreateContainerConfig, rtc *config.Config) (*entities.C continue } // If volume already exists, there is nothing to do - if _, err := os.Stat(vol); err == nil { + if err := fileutils.Exists(vol); err == nil { continue } if err := os.MkdirAll(vol, 0o755); err != nil { diff --git a/pkg/api/handlers/compat/images_build.go b/pkg/api/handlers/compat/images_build.go index 8fd2dd6668..207686c05c 100644 --- a/pkg/api/handlers/compat/images_build.go +++ b/pkg/api/handlers/compat/images_build.go @@ -27,6 +27,7 @@ import ( "github.com/containers/podman/v5/pkg/rootless" "github.com/containers/podman/v5/pkg/util" "github.com/containers/storage/pkg/archive" + "github.com/containers/storage/pkg/fileutils" "github.com/docker/docker/pkg/jsonmessage" "github.com/opencontainers/runtime-spec/specs-go" "github.com/sirupsen/logrus" @@ -248,9 +249,9 @@ func BuildImage(w http.ResponseWriter, r *http.Request) { containerFiles = []string{filepath.Join(contextDirectory, "Dockerfile")} if utils.IsLibpodRequest(r) { containerFiles = []string{filepath.Join(contextDirectory, "Containerfile")} - if _, err = os.Stat(containerFiles[0]); err != nil { + if err = fileutils.Exists(containerFiles[0]); err != nil { containerFiles = []string{filepath.Join(contextDirectory, "Dockerfile")} - if _, err1 := os.Stat(containerFiles[0]); err1 != nil { + if err1 := fileutils.Exists(containerFiles[0]); err1 != nil { utils.BadRequest(w, "dockerfile", query.Dockerfile, err) return } diff --git a/pkg/api/handlers/libpod/swagger_spec.go b/pkg/api/handlers/libpod/swagger_spec.go index 3686c8c9fc..3ba2cb4d35 100644 --- a/pkg/api/handlers/libpod/swagger_spec.go +++ b/pkg/api/handlers/libpod/swagger_spec.go @@ -7,6 +7,7 @@ import ( "os" "github.com/containers/podman/v5/pkg/api/handlers/utils" + "github.com/containers/storage/pkg/fileutils" ) // DefaultPodmanSwaggerSpec provides the default path to the podman swagger spec file @@ -17,7 +18,7 @@ func ServeSwagger(w http.ResponseWriter, r *http.Request) { if p, found := os.LookupEnv("PODMAN_SWAGGER_SPEC"); found { path = p } - if _, err := os.Stat(path); err != nil { + if err := fileutils.Exists(path); err != nil { if errors.Is(err, os.ErrNotExist) { utils.InternalServerError(w, fmt.Errorf("swagger spec %q does not exist", path)) return