From 4e1b4704d972c05916b71230b6f30d75c0271d18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Rod=C3=A1k?= Date: Mon, 8 Jul 2024 13:49:39 +0200 Subject: [PATCH 1/7] Fix errcheck: error return value of `m.CleanupStagedLayer` is not checked MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jan Rodák --- cmd/containers-storage/diff.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cmd/containers-storage/diff.go b/cmd/containers-storage/diff.go index 09f8b61f04..d026c9f58d 100644 --- a/cmd/containers-storage/diff.go +++ b/cmd/containers-storage/diff.go @@ -14,6 +14,7 @@ import ( "github.com/containers/storage/pkg/ioutils" "github.com/containers/storage/pkg/mflag" digest "github.com/opencontainers/go-digest" + "github.com/sirupsen/logrus" ) var ( @@ -192,7 +193,9 @@ func applyDiffUsingStagingDirectory(flags *mflag.FlagSet, action string, m stora DiffOptions: &options, } if _, err := m.ApplyStagedLayer(applyStagedLayerArgs); err != nil { - m.CleanupStagedLayer(out) + if err := m.CleanupStagedLayer(out); err != nil { + logrus.Warnf("cleanup of the staged layer failed: %v", err) + } return 1, err } return 0, nil From e163dd888f84bfbf7f67d604d5e2e60aa5ceedc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Rod=C3=A1k?= Date: Mon, 8 Jul 2024 13:51:33 +0200 Subject: [PATCH 2/7] Fix errcheck: error return value of `label.SetFileLabel` is not checked MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jan Rodák --- drivers/vfs/driver.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/vfs/driver.go b/drivers/vfs/driver.go index 1b9de2dc2a..f60ec17b3f 100644 --- a/drivers/vfs/driver.go +++ b/drivers/vfs/driver.go @@ -193,7 +193,9 @@ func (d *Driver) create(id, parent string, opts *graphdriver.CreateOpts, ro bool } labelOpts := []string{"level:s0"} if _, mountLabel, err := label.InitLabels(labelOpts); err == nil { - label.SetFileLabel(dir, mountLabel) + if err := label.SetFileLabel(dir, mountLabel); err != nil { + logrus.Debugf("Set %s label to %q file ended with error: %v", mountLabel, dir, err) + } } if parent != "" { parentDir, err := d.Get(parent, graphdriver.MountOpts{}) From 6f4a812ea8b01e16fa693dc15caa0c26e4667532 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Rod=C3=A1k?= Date: Mon, 8 Jul 2024 13:54:18 +0200 Subject: [PATCH 3/7] Fix errcheck: error return value of `lockHandle` is not checked MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jan Rodák --- pkg/lockfile/lockfile.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/lockfile/lockfile.go b/pkg/lockfile/lockfile.go index faf995a2d6..25a71ac908 100644 --- a/pkg/lockfile/lockfile.go +++ b/pkg/lockfile/lockfile.go @@ -415,7 +415,9 @@ func (l *LockFile) lock(lType lockType) { // Optimization: only use the (expensive) syscall when // the counter is 0. In this case, we're either the first // reader lock or a writer lock. - lockHandle(l.fd, lType, false) + if err := lockHandle(l.fd, lType, false); err != nil { + panic(err) + } } l.lockType = lType l.locked = true From c2942449c0bf3ca43e6272eccfa584974e300843 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Rod=C3=A1k?= Date: Mon, 8 Jul 2024 14:04:19 +0200 Subject: [PATCH 4/7] Fix errcheck: error return value of `cachedFeatureRecord()` is not checked MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jan Rodák --- drivers/overlay/overlay.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/overlay/overlay.go b/drivers/overlay/overlay.go index 0585228981..3283ec107c 100644 --- a/drivers/overlay/overlay.go +++ b/drivers/overlay/overlay.go @@ -821,7 +821,9 @@ func (d *Driver) useNaiveDiff() bool { logrus.Info(nativeDiffCacheText) useNaiveDiffOnly = true } - cachedFeatureRecord(d.runhome, feature, !useNaiveDiffOnly, nativeDiffCacheText) + if err := cachedFeatureRecord(d.runhome, feature, !useNaiveDiffOnly, nativeDiffCacheText); err != nil { + logrus.Warnf("Recording overlay native-diff support status: %v", err) + } }) return useNaiveDiffOnly } From 02bea59033852a9f1901a6b7e375f0a31ded1290 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Rod=C3=A1k?= Date: Mon, 8 Jul 2024 15:03:42 +0200 Subject: [PATCH 5/7] Fix errcheck: error return value of `unix.Rmdir` is not checked MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jan Rodák --- drivers/overlay/overlay.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/overlay/overlay.go b/drivers/overlay/overlay.go index 3283ec107c..dc72c09a93 100644 --- a/drivers/overlay/overlay.go +++ b/drivers/overlay/overlay.go @@ -2087,7 +2087,9 @@ func (d *Driver) DiffGetter(id string) (_ graphdriver.FileGetCloser, Err error) if Err != nil { for _, f := range composefsMounts { f.Close() - unix.Rmdir(f.Name()) + if err := unix.Rmdir(f.Name()); err != nil && !os.IsNotExist(err) { + logrus.Warnf("Failed to remove %s: %v", f.Name(), err) + } } } }() From cd0e038cf021436c6480ddc0fa272dbf7490723c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Rod=C3=A1k?= Date: Mon, 8 Jul 2024 15:11:40 +0200 Subject: [PATCH 6/7] Fix errcheck: error return value of `w.closeTempFile` is not checked MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jan Rodák --- pkg/ioutils/fswriters.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/ioutils/fswriters.go b/pkg/ioutils/fswriters.go index 2a8c85ad44..fd6addd73b 100644 --- a/pkg/ioutils/fswriters.go +++ b/pkg/ioutils/fswriters.go @@ -150,10 +150,13 @@ func (w *atomicFileWriter) complete(commit bool) (retErr error) { } defer func() { - w.closeTempFile() + err := w.closeTempFile() if retErr != nil || w.writeErr != nil { os.Remove(w.f.Name()) } + if retErr == nil { + retErr = err + } }() if commit { From e6c132bd00be6392dc6eff217f530726339d6f9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Rod=C3=A1k?= Date: Mon, 8 Jul 2024 15:20:18 +0200 Subject: [PATCH 7/7] Fix errcheck: error return value of `io.Copy` is not checked MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jan Rodák --- check.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/check.go b/check.go index cf067468b4..c7a728b191 100644 --- a/check.go +++ b/check.go @@ -304,7 +304,14 @@ func (s *store) Check(options *CheckOptions) (CheckReport, error) { archiveErr = err } // consume any trailer after the EOF marker - io.Copy(io.Discard, diffReader) + if _, err := io.Copy(io.Discard, diffReader); err != nil { + err = fmt.Errorf("layer %s: consume any trailer after the EOF marker: %w", layerID, err) + if isReadWrite { + report.Layers[layerID] = append(report.Layers[layerID], err) + } else { + report.ROLayers[layerID] = append(report.ROLayers[layerID], err) + } + } wg.Done() }(id, reader) wg.Wait()