diff options
author | Sascha Grunert <sgrunert@redhat.com> | 2022-07-06 09:48:36 +0200 |
---|---|---|
committer | Sascha Grunert <sgrunert@redhat.com> | 2022-07-08 08:54:47 +0200 |
commit | a46f798831df06c472b288db7b34de8536a7ea5a (patch) | |
tree | c370fb0fc23b461691906e308b179a50e583228b /pkg/checkpoint/crutils | |
parent | 862cc42ddc11ff56b41be128182b748b0843dff3 (diff) | |
download | podman-a46f798831df06c472b288db7b34de8536a7ea5a.tar.gz podman-a46f798831df06c472b288db7b34de8536a7ea5a.tar.bz2 podman-a46f798831df06c472b288db7b34de8536a7ea5a.zip |
pkg: 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.
[NO NEW TESTS NEEDED]
Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
Diffstat (limited to 'pkg/checkpoint/crutils')
-rw-r--r-- | pkg/checkpoint/crutils/checkpoint_restore_utils.go | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/pkg/checkpoint/crutils/checkpoint_restore_utils.go b/pkg/checkpoint/crutils/checkpoint_restore_utils.go index 76c868cee..1437a09df 100644 --- a/pkg/checkpoint/crutils/checkpoint_restore_utils.go +++ b/pkg/checkpoint/crutils/checkpoint_restore_utils.go @@ -2,6 +2,8 @@ package crutils import ( "bytes" + "errors" + "fmt" "io" "io/ioutil" "os" @@ -12,7 +14,6 @@ import ( "github.com/checkpoint-restore/go-criu/v5/stats" "github.com/containers/storage/pkg/archive" "github.com/opencontainers/selinux/go-selinux/label" - "github.com/pkg/errors" ) // This file mainly exist to make the checkpoint/restore functions @@ -23,7 +24,7 @@ import ( func CRImportCheckpointWithoutConfig(destination, input string) error { archiveFile, err := os.Open(input) if err != nil { - return errors.Wrapf(err, "Failed to open checkpoint archive %s for import", input) + return fmt.Errorf("failed to open checkpoint archive %s for import: %w", input, err) } defer archiveFile.Close() @@ -35,7 +36,7 @@ func CRImportCheckpointWithoutConfig(destination, input string) error { }, } if err = archive.Untar(archiveFile, destination, options); err != nil { - return errors.Wrapf(err, "Unpacking of checkpoint archive %s failed", input) + return fmt.Errorf("unpacking of checkpoint archive %s failed: %w", input, err) } return nil @@ -47,7 +48,7 @@ func CRImportCheckpointWithoutConfig(destination, input string) error { func CRImportCheckpointConfigOnly(destination, input string) error { archiveFile, err := os.Open(input) if err != nil { - return errors.Wrapf(err, "Failed to open checkpoint archive %s for import", input) + return fmt.Errorf("failed to open checkpoint archive %s for import: %w", input, err) } defer archiveFile.Close() @@ -65,7 +66,7 @@ func CRImportCheckpointConfigOnly(destination, input string) error { }, } if err = archive.Untar(archiveFile, destination, options); err != nil { - return errors.Wrapf(err, "Unpacking of checkpoint archive %s failed", input) + return fmt.Errorf("unpacking of checkpoint archive %s failed: %w", input, err) } return nil @@ -81,14 +82,14 @@ func CRRemoveDeletedFiles(id, baseDirectory, containerRootDirectory string) erro } if err != nil { - return errors.Wrapf(err, "failed to read deleted files file") + return fmt.Errorf("failed to read deleted files file: %w", err) } for _, deleteFile := range deletedFiles { // Using RemoveAll as deletedFiles, which is generated from 'podman diff' // lists completely deleted directories as a single entry: 'D /root'. if err := os.RemoveAll(filepath.Join(containerRootDirectory, deleteFile)); err != nil { - return errors.Wrapf(err, "failed to delete files from container %s during restore", id) + return fmt.Errorf("failed to delete files from container %s during restore: %w", id, err) } } @@ -105,12 +106,12 @@ func CRApplyRootFsDiffTar(baseDirectory, containerRootDirectory string) error { if errors.Is(err, os.ErrNotExist) { return nil } - return errors.Wrap(err, "failed to open root file-system diff file") + return fmt.Errorf("failed to open root file-system diff file: %w", err) } defer rootfsDiffFile.Close() if err := archive.Untar(rootfsDiffFile, containerRootDirectory, nil); err != nil { - return errors.Wrapf(err, "failed to apply root file-system diff file %s", rootfsDiffPath) + return fmt.Errorf("failed to apply root file-system diff file %s: %w", rootfsDiffPath, err) } return nil @@ -158,11 +159,11 @@ func CRCreateRootFsDiffTar(changes *[]archive.Change, mountPoint, destination st IncludeFiles: rootfsIncludeFiles, }) if err != nil { - return includeFiles, errors.Wrapf(err, "error exporting root file-system diff to %q", rootfsDiffPath) + return includeFiles, fmt.Errorf("error exporting root file-system diff to %q: %w", rootfsDiffPath, err) } rootfsDiffFile, err := os.Create(rootfsDiffPath) if err != nil { - return includeFiles, errors.Wrapf(err, "error creating root file-system diff file %q", rootfsDiffPath) + return includeFiles, fmt.Errorf("error creating root file-system diff file %q: %w", rootfsDiffPath, err) } defer rootfsDiffFile.Close() if _, err = io.Copy(rootfsDiffFile, rootfsTar); err != nil { @@ -195,11 +196,11 @@ func CRCreateFileWithLabel(directory, fileName, fileLabel string) error { logFile, err := os.OpenFile(logFileName, os.O_CREATE, 0o600) if err != nil { - return errors.Wrapf(err, "failed to create file %q", logFileName) + return fmt.Errorf("failed to create file %q: %w", logFileName, err) } defer logFile.Close() if err = label.SetFileLabel(logFileName, fileLabel); err != nil { - return errors.Wrapf(err, "failed to label file %q", logFileName) + return fmt.Errorf("failed to label file %q: %w", logFileName, err) } return nil |