pkg/api: use fileutils.(Le|E)xists

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
Giuseppe Scrivano 2024-04-10 17:59:51 +02:00
parent 5656ad40b1
commit bd00c6fef9
No known key found for this signature in database
GPG Key ID: 67E38F7A8BA21772
3 changed files with 7 additions and 4 deletions

View File

@ -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 {

View File

@ -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
}

View File

@ -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