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