Skip to content

Commit

Permalink
Merge pull request #2006 from Honny1/fix-errcheck-5
Browse files Browse the repository at this point in the history
Solve `errcheck` warnings (part 5)
  • Loading branch information
openshift-merge-bot[bot] authored Jul 9, 2024
2 parents ba0e86e + e6c132b commit 876118a
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 7 deletions.
9 changes: 8 additions & 1 deletion check.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 4 additions & 1 deletion cmd/containers-storage/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions drivers/overlay/overlay.go
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,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
}
Expand Down Expand Up @@ -2087,7 +2089,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)
}
}
}
}()
Expand Down
4 changes: 3 additions & 1 deletion drivers/vfs/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
Expand Down
5 changes: 4 additions & 1 deletion pkg/ioutils/fswriters.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion pkg/lockfile/lockfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 876118a

Please sign in to comment.