Skip to content

Commit

Permalink
pkg/api: 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 19, 2024
1 parent 5656ad4 commit bd00c6f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion pkg/api/handlers/compat/containers_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions pkg/api/handlers/compat/images_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/api/handlers/libpod/swagger_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit bd00c6f

Please sign in to comment.