mirror of
https://github.com/containers/podman.git
synced 2025-10-17 19:24:04 +08:00
cmd/podman: switch to golang native error wrapping
We now use the golang error wrapping format specifier `%w` instead of the deprecated github.com/pkg/errors package. Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
This commit is contained in:
@ -5,6 +5,7 @@ package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
@ -14,7 +15,6 @@ import (
|
||||
"syscall"
|
||||
"text/template"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@ -111,7 +111,7 @@ func install(cmd *cobra.Command, args []string) error {
|
||||
|
||||
file, err := os.OpenFile(fileName, os.O_WRONLY|os.O_CREATE|os.O_EXCL, rw_r_r)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error creating helper plist file")
|
||||
return fmt.Errorf("creating helper plist file: %w", err)
|
||||
}
|
||||
defer file.Close()
|
||||
_, err = buf.WriteTo(file)
|
||||
@ -120,7 +120,7 @@ func install(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
if err = runDetectErr("launchctl", "load", fileName); err != nil {
|
||||
return errors.Wrap(err, "launchctl failed loading service")
|
||||
return fmt.Errorf("launchctl failed loading service: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@ -133,13 +133,13 @@ func restrictRecursive(targetDir string, until string) error {
|
||||
return err
|
||||
}
|
||||
if info.Mode()&fs.ModeSymlink != 0 {
|
||||
return errors.Errorf("symlinks not allowed in helper paths (remove them and rerun): %s", targetDir)
|
||||
return fmt.Errorf("symlinks not allowed in helper paths (remove them and rerun): %s", targetDir)
|
||||
}
|
||||
if err = os.Chown(targetDir, 0, 0); err != nil {
|
||||
return errors.Wrap(err, "could not update ownership of helper path")
|
||||
return fmt.Errorf("could not update ownership of helper path: %w", err)
|
||||
}
|
||||
if err = os.Chmod(targetDir, rwx_rx_rx|fs.ModeSticky); err != nil {
|
||||
return errors.Wrap(err, "could not update permissions of helper path")
|
||||
return fmt.Errorf("could not update permissions of helper path: %w", err)
|
||||
}
|
||||
targetDir = filepath.Dir(targetDir)
|
||||
}
|
||||
@ -162,7 +162,7 @@ func verifyRootDeep(path string) error {
|
||||
|
||||
stat := info.Sys().(*syscall.Stat_t)
|
||||
if stat.Uid != 0 {
|
||||
return errors.Errorf("installation target path must be solely owned by root: %s is not", current)
|
||||
return fmt.Errorf("installation target path must be solely owned by root: %s is not", current)
|
||||
}
|
||||
|
||||
if info.Mode()&fs.ModeSymlink != 0 {
|
||||
@ -206,7 +206,7 @@ func installExecutable(user string) (string, error) {
|
||||
|
||||
targetDir := filepath.Join(installPrefix, "podman", "helper", user)
|
||||
if err := os.MkdirAll(targetDir, rwx_rx_rx); err != nil {
|
||||
return "", errors.Wrap(err, "could not create helper directory structure")
|
||||
return "", fmt.Errorf("could not create helper directory structure: %w", err)
|
||||
}
|
||||
|
||||
// Correct any incorrect perms on previously existing directories and verify no symlinks
|
||||
|
@ -4,6 +4,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
@ -13,7 +14,6 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@ -97,7 +97,7 @@ func getUser() (string, string, string, error) {
|
||||
return "", "", "", fmt.Errorf("invalid uid for user: %s", name)
|
||||
}
|
||||
if id == 0 {
|
||||
return "", "", "", fmt.Errorf("unexpected root user")
|
||||
return "", "", "", errors.New("unexpected root user")
|
||||
}
|
||||
|
||||
return name, uid, home, nil
|
||||
|
@ -9,7 +9,6 @@ import (
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@ -48,13 +47,13 @@ func uninstall(cmd *cobra.Command, args []string) error {
|
||||
|
||||
if err := os.Remove(fileName); err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
return errors.Errorf("could not remove plist file: %s", fileName)
|
||||
return fmt.Errorf("could not remove plist file: %s", fileName)
|
||||
}
|
||||
}
|
||||
|
||||
helperPath := filepath.Join(installPrefix, "podman", "helper", userName)
|
||||
if err := os.RemoveAll(helperPath); err != nil {
|
||||
return errors.Errorf("could not remove helper binary path: %s", helperPath)
|
||||
return fmt.Errorf("could not remove helper binary path: %s", helperPath)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user