aboutsummaryrefslogtreecommitdiff
path: root/libpod/container_internal_linux.go
diff options
context:
space:
mode:
authorKir Kolyshkin <kolyshkin@gmail.com>2020-10-05 12:33:53 -0700
committerKir Kolyshkin <kolyshkin@gmail.com>2020-10-05 15:30:37 -0700
commit4878dff3e2c89382699c29c10dc5036367275575 (patch)
tree5215fd4238ac12dc81af595d1ee3b174430769c5 /libpod/container_internal_linux.go
parent1b16fcfd14b9e761849e53ac2b83c964ad8ac5a9 (diff)
downloadpodman-4878dff3e2c89382699c29c10dc5036367275575.tar.gz
podman-4878dff3e2c89382699c29c10dc5036367275575.tar.bz2
podman-4878dff3e2c89382699c29c10dc5036367275575.zip
Remove excessive error wrapping
In case os.Open[File], os.Mkdir[All], ioutil.ReadFile and the like fails, the error message already contains the file name and the operation that fails, so there is no need to wrap the error with something like "open %s failed". While at it - replace a few places with os.Open, ioutil.ReadAll with ioutil.ReadFile. - replace errors.Wrapf with errors.Wrap for cases where there are no %-style arguments. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Diffstat (limited to 'libpod/container_internal_linux.go')
-rw-r--r--libpod/container_internal_linux.go20
1 files changed, 7 insertions, 13 deletions
diff --git a/libpod/container_internal_linux.go b/libpod/container_internal_linux.go
index 514cdaee1..2f107446f 100644
--- a/libpod/container_internal_linux.go
+++ b/libpod/container_internal_linux.go
@@ -835,13 +835,13 @@ func (c *Container) checkpointRestoreLabelLog(fileName string) error {
logFile, err := os.OpenFile(dumpLog, os.O_CREATE, 0600)
if err != nil {
- return errors.Wrapf(err, "failed to create CRIU log file %q", dumpLog)
+ return errors.Wrap(err, "failed to create CRIU log file")
}
if err := logFile.Close(); err != nil {
- logrus.Errorf("unable to close log file: %q", err)
+ logrus.Error(err)
}
if err = label.SetFileLabel(dumpLog, c.MountLabel()); err != nil {
- return errors.Wrapf(err, "failed to label CRIU log file %q", dumpLog)
+ return err
}
return nil
}
@@ -919,7 +919,7 @@ func (c *Container) checkpoint(ctx context.Context, options ContainerCheckpointO
func (c *Container) importCheckpoint(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 errors.Wrap(err, "Failed to open checkpoint archive for import")
}
defer archiveFile.Close()
@@ -1116,7 +1116,7 @@ func (c *Container) restore(ctx context.Context, options ContainerCheckpointOpti
// Only do this if a rootfs-diff.tar actually exists
rootfsDiffFile, err := os.Open(rootfsDiffPath)
if err != nil {
- return errors.Wrapf(err, "Failed to open root file-system diff file %s", rootfsDiffPath)
+ return errors.Wrap(err, "Failed to open root file-system diff file")
}
defer rootfsDiffFile.Close()
if err := c.runtime.ApplyDiffTarStream(c.ID(), rootfsDiffFile); err != nil {
@@ -1125,16 +1125,10 @@ func (c *Container) restore(ctx context.Context, options ContainerCheckpointOpti
}
deletedFilesPath := filepath.Join(c.bundlePath(), "deleted.files")
if _, err := os.Stat(deletedFilesPath); err == nil {
- deletedFilesFile, err := os.Open(deletedFilesPath)
- if err != nil {
- return errors.Wrapf(err, "Failed to open deleted files file %s", deletedFilesPath)
- }
- defer deletedFilesFile.Close()
-
var deletedFiles []string
- deletedFilesJSON, err := ioutil.ReadAll(deletedFilesFile)
+ deletedFilesJSON, err := ioutil.ReadFile(deletedFilesPath)
if err != nil {
- return errors.Wrapf(err, "Failed to read deleted files file %s", deletedFilesPath)
+ return errors.Wrapf(err, "Failed to read deleted files file")
}
if err := json.Unmarshal(deletedFilesJSON, &deletedFiles); err != nil {
return errors.Wrapf(err, "Failed to read deleted files file %s", deletedFilesPath)