Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solve errcheck warnings (part 5) #2006

Merged
merged 7 commits into from
Jul 9, 2024
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 @@ -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
}
Expand Down Expand Up @@ -2085,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)
}
}
}
}()
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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we fail the entire operation if this fails? Wouldn’t it break on non-SELinux systems? Maybe a debug log is the best we can do here.

Cc: @rhatdan , history is 73617e5 .

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mountlabel should be "" on a non SELinux system.

SetFileLabel becomes a no-op.

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