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 2) #1999

Merged
merged 4 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions drivers/aufs/aufs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -764,13 +764,19 @@ func BenchmarkConcurrentAccess(b *testing.B) {
for i := 0; i < b.N; i++ {
innerGroup.Add(1)
go func() {
d.Get(id, graphdriver.MountOpts{})
d.Put(id)
if _, err := d.Get(id, graphdriver.MountOpts{}); err != nil {
b.Log(err)
}
if err := d.Put(id); err != nil {
b.Log(err)
}
innerGroup.Done()
}()
}
innerGroup.Wait()
d.Remove(id)
if err := d.Remove(id); err != nil {
b.Log(err)
}
}(id)
}

Expand Down
6 changes: 5 additions & 1 deletion drivers/btrfs/btrfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ func TestBtrfsSubvolDelete(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer d.Put("test")
defer func() {
if err := d.Put("test"); err != nil {
t.Fatal(err)
}
}()

if err := subvolCreate(dir, "subvoltest"); err != nil {
t.Fatal(err)
Expand Down
6 changes: 5 additions & 1 deletion drivers/graphtest/graphbench_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,11 @@ func DriverBenchDeepLayerRead(b *testing.B, layerCount int, drivername string, d
if err != nil {
b.Fatal(err)
}
defer driver.Put(topLayer)
defer func() {
if err := driver.Put(topLayer); err != nil {
b.Fatal(err)
}
}()

b.ResetTimer()
for i := 0; i < b.N; i++ {
Expand Down
6 changes: 4 additions & 2 deletions drivers/graphtest/graphtest_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ func DriverTestCreateEmpty(t testing.TB, drivername string, driverOptions ...str
require.NoError(t, err)
assert.Len(t, fis, 0)

driver.Put("empty")
err = driver.Put("empty")
require.NoError(t, err)
}

// DriverTestCreateBase create a base driver and verify.
Expand Down Expand Up @@ -162,7 +163,8 @@ func DriverTestCreateSnap(t testing.TB, drivername string, driverOptions ...stri
assert.NoError(t, err)
err = os.Chmod(root, modifiedPerms)
require.NoError(t, err)
driver.Put("Snap2")
err = driver.Put("Snap2")
require.NoError(t, err)

err = driver.Create("SecondSnap", "Snap2", nil)
require.NoError(t, err)
Expand Down
67 changes: 56 additions & 11 deletions drivers/graphtest/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
graphdriver "github.com/containers/storage/drivers"
"github.com/containers/storage/pkg/archive"
"github.com/containers/storage/pkg/stringid"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/require"
)

Expand All @@ -38,7 +39,11 @@ func addFiles(drv graphdriver.Driver, layer string, seed int64) error {
if err != nil {
return err
}
defer drv.Put(layer)
defer func() {
if err := drv.Put(layer); err != nil {
logrus.Warn(err)
}
}()

if err := os.WriteFile(path.Join(root, "file-a"), randomContent(64, seed), 0o755); err != nil {
return err
Expand All @@ -58,7 +63,11 @@ func checkFile(drv graphdriver.Driver, layer, filename string, content []byte) e
if err != nil {
return err
}
defer drv.Put(layer)
defer func() {
if err := drv.Put(layer); err != nil {
logrus.Warn(err)
}
}()

fileContent, err := os.ReadFile(path.Join(root, filename))
if err != nil {
Expand All @@ -77,7 +86,11 @@ func addFile(drv graphdriver.Driver, layer, filename string, content []byte) err
if err != nil {
return err
}
defer drv.Put(layer)
defer func() {
if err := drv.Put(layer); err != nil {
logrus.Warn(err)
}
}()

return os.WriteFile(path.Join(root, filename), content, 0o755)
}
Expand All @@ -87,7 +100,11 @@ func addDirectory(drv graphdriver.Driver, layer, dir string) error {
if err != nil {
return err
}
defer drv.Put(layer)
defer func() {
if err := drv.Put(layer); err != nil {
logrus.Warn(err)
}
}()

return os.MkdirAll(path.Join(root, dir), 0o755)
}
Expand All @@ -97,7 +114,11 @@ func removeAll(drv graphdriver.Driver, layer string, names ...string) error {
if err != nil {
return err
}
defer drv.Put(layer)
defer func() {
if err := drv.Put(layer); err != nil {
logrus.Warn(err)
}
}()

for _, filename := range names {
if err := os.RemoveAll(path.Join(root, filename)); err != nil {
Expand All @@ -112,7 +133,11 @@ func checkFileRemoved(drv graphdriver.Driver, layer, filename string) error {
if err != nil {
return err
}
defer drv.Put(layer)
defer func() {
if err := drv.Put(layer); err != nil {
logrus.Warn(err)
}
}()

if _, err := os.Stat(path.Join(root, filename)); err == nil {
return fmt.Errorf("file still exists: %s", path.Join(root, filename))
Expand All @@ -128,7 +153,11 @@ func addManyFiles(drv graphdriver.Driver, layer string, count int, seed int64) e
if err != nil {
return err
}
defer drv.Put(layer)
defer func() {
if err := drv.Put(layer); err != nil {
logrus.Warn(err)
}
}()

for i := 0; i < count; i += 100 {
dir := path.Join(root, fmt.Sprintf("directory-%d", i))
Expand All @@ -151,7 +180,11 @@ func changeManyFiles(drv graphdriver.Driver, layer string, count int, seed int64
if err != nil {
return nil, err
}
defer drv.Put(layer)
defer func() {
if err := drv.Put(layer); err != nil {
logrus.Warn(err)
}
}()

changes := []archive.Change{}
for i := 0; i < count; i += 100 {
Expand Down Expand Up @@ -211,7 +244,11 @@ func checkManyFiles(drv graphdriver.Driver, layer string, count int, seed int64)
if err != nil {
return err
}
defer drv.Put(layer)
defer func() {
if err := drv.Put(layer); err != nil {
logrus.Warn(err)
}
}()

for i := 0; i < count; i += 100 {
dir := path.Join(root, fmt.Sprintf("directory-%d", i))
Expand Down Expand Up @@ -265,7 +302,11 @@ func addLayerFiles(drv graphdriver.Driver, layer, parent string, i int) error {
if err != nil {
return err
}
defer drv.Put(layer)
defer func() {
if err := drv.Put(layer); err != nil {
logrus.Warn(err)
}
}()

if err := os.WriteFile(path.Join(root, "top-id"), []byte(layer), 0o755); err != nil {
return err
Expand Down Expand Up @@ -307,7 +348,11 @@ func checkManyLayers(drv graphdriver.Driver, layer string, count int) error {
if err != nil {
return err
}
defer drv.Put(layer)
defer func() {
if err := drv.Put(layer); err != nil {
logrus.Warn(err)
}
}()

layerIDBytes, err := os.ReadFile(path.Join(root, "top-id"))
if err != nil {
Expand Down
10 changes: 8 additions & 2 deletions drivers/graphtest/testutil_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ func createBase(t testing.TB, driver graphdriver.Driver, name string) {

dir, err := driver.Get(name, graphdriver.MountOpts{})
require.NoError(t, err)
defer driver.Put(name)
defer func() {
err = driver.Put(name)
require.NoError(t, err)
}()

subdir := path.Join(dir, "a subdir")
require.NoError(t, os.Mkdir(subdir, defaultSubdirPerms|os.ModeSticky))
Expand All @@ -57,7 +60,10 @@ func createBase(t testing.TB, driver graphdriver.Driver, name string) {
func verifyBase(t testing.TB, driver graphdriver.Driver, name string, defaultPerm os.FileMode) {
dir, err := driver.Get(name, graphdriver.MountOpts{})
require.NoError(t, err)
defer driver.Put(name)
defer func() {
err = driver.Put(name)
require.NoError(t, err)
}()

verifyFile(t, dir, defaultPerm|os.ModeDir, 0, 0)

Expand Down
8 changes: 6 additions & 2 deletions pkg/chunked/cache_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ var (
func (c *layer) release() {
runtime.SetFinalizer(c, nil)
if c.mmapBuffer != nil {
unix.Munmap(c.mmapBuffer)
if err := unix.Munmap(c.mmapBuffer); err != nil {
logrus.Warnf("Error Munmap: layer %q: %v", c.id, err)
}
}
}

Expand Down Expand Up @@ -192,7 +194,9 @@ func (c *layersCache) loadLayerCache(layerID string) (_ *layer, errRet error) {
}
defer func() {
if errRet != nil && mmapBuffer != nil {
unix.Munmap(mmapBuffer)
if err := unix.Munmap(mmapBuffer); err != nil {
logrus.Warnf("Error Munmap: layer %q: %v", layerID, err)
}
}
}()
cacheFile, err := readCacheFileFromMemory(buffer)
Expand Down