mirror of
https://github.com/containers/podman.git
synced 2025-05-17 23:26:08 +08:00
cmd: use fileutils.(Le|E)xists
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
@ -14,6 +14,7 @@ import (
|
||||
"syscall"
|
||||
"text/template"
|
||||
|
||||
"github.com/containers/storage/pkg/fileutils"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@ -91,7 +92,7 @@ func install(cmd *cobra.Command, args []string) error {
|
||||
labelName := fmt.Sprintf("com.github.containers.podman.helper-%s.plist", userName)
|
||||
fileName := filepath.Join("/Library", "LaunchDaemons", labelName)
|
||||
|
||||
if _, err := os.Stat(fileName); err == nil || !os.IsNotExist(err) {
|
||||
if err := fileutils.Exists(fileName); err == nil || !errors.Is(err, fs.ErrNotExist) {
|
||||
fmt.Fprintln(os.Stderr, "helper is already installed, skipping the install, uninstall first if you want to reinstall")
|
||||
return nil
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/containers/storage/pkg/fileutils"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@ -58,7 +59,7 @@ func uninstall(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
// Get the file information of dockerSock
|
||||
if _, err := os.Lstat(dockerSock); err != nil {
|
||||
if err := fileutils.Lexists(dockerSock); err != nil {
|
||||
// If the error is due to the file not existing, return nil
|
||||
if errors.Is(err, fs.ErrNotExist) {
|
||||
return nil
|
||||
|
@ -14,6 +14,7 @@ import (
|
||||
"github.com/containers/podman/v5/cmd/podman/validate"
|
||||
"github.com/containers/podman/v5/pkg/domain/entities"
|
||||
"github.com/containers/podman/v5/pkg/util"
|
||||
"github.com/containers/storage/pkg/fileutils"
|
||||
"github.com/spf13/cobra"
|
||||
"golang.org/x/term"
|
||||
)
|
||||
@ -85,7 +86,7 @@ func load(cmd *cobra.Command, args []string) error {
|
||||
loadOpts.Input = tmpfile
|
||||
}
|
||||
|
||||
if _, err := os.Stat(loadOpts.Input); err != nil {
|
||||
if err := fileutils.Exists(loadOpts.Input); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
|
@ -2,13 +2,13 @@ package images
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
|
||||
"github.com/containers/common/pkg/auth"
|
||||
"github.com/containers/common/pkg/completion"
|
||||
"github.com/containers/podman/v5/cmd/podman/common"
|
||||
"github.com/containers/podman/v5/cmd/podman/registry"
|
||||
"github.com/containers/podman/v5/pkg/domain/entities"
|
||||
"github.com/containers/storage/pkg/fileutils"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@ -68,7 +68,7 @@ func sign(cmd *cobra.Command, args []string) error {
|
||||
var sigStoreDir string
|
||||
if len(signOptions.Directory) > 0 {
|
||||
sigStoreDir = signOptions.Directory
|
||||
if _, err := os.Stat(sigStoreDir); err != nil {
|
||||
if err := fileutils.Exists(sigStoreDir); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import (
|
||||
"github.com/containers/podman/v5/cmd/podman/registry"
|
||||
"github.com/containers/podman/v5/cmd/podman/utils"
|
||||
"github.com/containers/podman/v5/pkg/domain/entities"
|
||||
"github.com/containers/storage/pkg/fileutils"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@ -105,7 +106,7 @@ func generateKube(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
if cmd.Flags().Changed("filename") {
|
||||
if _, err := os.Stat(generateFile); err == nil {
|
||||
if err := fileutils.Exists(generateFile); err == nil {
|
||||
return fmt.Errorf("cannot write to %q; file exists", generateFile)
|
||||
}
|
||||
if err := os.WriteFile(generateFile, content, 0644); err != nil {
|
||||
|
@ -11,6 +11,7 @@ import (
|
||||
"github.com/containers/podman/v5/pkg/domain/entities"
|
||||
"github.com/containers/podman/v5/pkg/rootless"
|
||||
"github.com/containers/podman/v5/pkg/util"
|
||||
"github.com/containers/storage/pkg/fileutils"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/pflag"
|
||||
)
|
||||
@ -145,7 +146,7 @@ func setXdgDirs() error {
|
||||
|
||||
if _, found := os.LookupEnv("DBUS_SESSION_BUS_ADDRESS"); !found {
|
||||
sessionAddr := filepath.Join(os.Getenv("XDG_RUNTIME_DIR"), "bus")
|
||||
if _, err := os.Stat(sessionAddr); err == nil {
|
||||
if err := fileutils.Exists(sessionAddr); err == nil {
|
||||
sessionAddr, err = filepath.EvalSymlinks(sessionAddr)
|
||||
if err != nil {
|
||||
return err
|
||||
|
Reference in New Issue
Block a user