Skip to content

Commit

Permalink
internal: 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 441bdc9 commit 8bdd6a6
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
3 changes: 2 additions & 1 deletion internal/mkcw/attest.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"strings"

"github.com/containers/buildah/internal/mkcw/types"
"github.com/containers/storage/pkg/fileutils"
"github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -224,7 +225,7 @@ func GenerateMeasurement(workloadConfig WorkloadConfig, firmwareLibrary string)
}
}
for _, candidate := range pathsToCheck {
if _, err := os.Lstat(candidate); err == nil {
if err := fileutils.Lexists(candidate); err == nil {
var stdout, stderr bytes.Buffer
logrus.Debugf("krunfw_measurement -c %s -m %s %s", cpuString, memoryString, candidate)
cmd := exec.Command("krunfw_measurement", "-c", cpuString, "-m", memoryString, candidate)
Expand Down
4 changes: 2 additions & 2 deletions internal/parse/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package parse

import (
"fmt"
"os"
"path/filepath"
"strings"

"github.com/containers/common/pkg/parse"
"github.com/containers/storage/pkg/fileutils"
specs "github.com/opencontainers/runtime-spec/specs-go"
)

Expand All @@ -15,7 +15,7 @@ func ValidateVolumeMountHostDir(hostDir string) error {
if !filepath.IsAbs(hostDir) {
return fmt.Errorf("invalid host path, must be an absolute path %q", hostDir)
}
if _, err := os.Stat(hostDir); err != nil {
if err := fileutils.Exists(hostDir); err != nil {
return err
}
return nil
Expand Down
3 changes: 2 additions & 1 deletion internal/source/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/containers/image/v5/types"
"github.com/containers/storage/pkg/archive"
"github.com/containers/storage/pkg/fileutils"
specV1 "github.com/opencontainers/image-spec/specs-go/v1"
)

Expand Down Expand Up @@ -44,7 +45,7 @@ func (o *AddOptions) annotations() (map[string]string, error) {
// tar ball. Add attempts to auto-tar and auto-compress only if necessary.
func Add(ctx context.Context, sourcePath string, artifactPath string, options AddOptions) error {
// Let's first make sure `sourcePath` exists and that we can access it.
if _, err := os.Stat(sourcePath); err != nil {
if err := fileutils.Exists(sourcePath); err != nil {
return err
}

Expand Down
4 changes: 2 additions & 2 deletions internal/source/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package source
import (
"context"
"fmt"
"os"
"time"

"github.com/containers/storage/pkg/fileutils"
spec "github.com/opencontainers/image-spec/specs-go"
specV1 "github.com/opencontainers/image-spec/specs-go/v1"
)
Expand All @@ -32,7 +32,7 @@ func (o *CreateOptions) createdTime() *time.Time {
// Create creates an empty source image at the specified `sourcePath`. Note
// that `sourcePath` must not exist.
func Create(ctx context.Context, sourcePath string, options CreateOptions) error {
if _, err := os.Stat(sourcePath); err == nil {
if err := fileutils.Exists(sourcePath); err == nil {
return fmt.Errorf("creating source image: %q already exists", sourcePath)
}

Expand Down
3 changes: 2 additions & 1 deletion internal/source/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/containers/image/v5/signature"
"github.com/containers/image/v5/transports/alltransports"
"github.com/containers/image/v5/types"
"github.com/containers/storage/pkg/fileutils"
)

// PullOptions includes data to alter certain knobs when pulling a source
Expand All @@ -27,7 +28,7 @@ type PullOptions struct {

// Pull `imageInput` from a container registry to `sourcePath`.
func Pull(ctx context.Context, imageInput string, sourcePath string, options PullOptions) error {
if _, err := os.Stat(sourcePath); err == nil {
if err := fileutils.Exists(sourcePath); err == nil {
return fmt.Errorf("%q already exists", sourcePath)
}

Expand Down

0 comments on commit 8bdd6a6

Please sign in to comment.