Skip to content

Commit

Permalink
Merge pull request #1998 from Honny1/fix-errcheck-1
Browse files Browse the repository at this point in the history
Solve `errcheck` warnings (part 1)
  • Loading branch information
openshift-merge-bot[bot] committed Jul 9, 2024
2 parents 9c1271a + 55ccf47 commit e2e98d8
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 12 deletions.
4 changes: 3 additions & 1 deletion drivers/aufs/aufs.go
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,9 @@ func (a *Driver) Cleanup() error {
func (a *Driver) aufsMount(ro []string, rw, target string, options graphdriver.MountOpts) (err error) {
defer func() {
if err != nil {
Unmount(target)
if err1 := Unmount(target); err1 != nil {
logrus.Warnf("Unmount %q: %v", target, err1)
}
}
}()

Expand Down
6 changes: 5 additions & 1 deletion drivers/overlay/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,11 @@ func supportsIdmappedLowerLayers(home string) (bool, error) {
if err := idmap.CreateIDMappedMount(lowerDir, lowerMappedDir, int(pid)); err != nil {
return false, fmt.Errorf("create mapped mount: %w", err)
}
defer unix.Unmount(lowerMappedDir, unix.MNT_DETACH)
defer func() {
if err := unix.Unmount(lowerMappedDir, unix.MNT_DETACH); err != nil {
logrus.Warnf("Unmount %q: %v", lowerMappedDir, err)
}
}()

opts := fmt.Sprintf("lowerdir=%s,upperdir=%s,workdir=%s", lowerMappedDir, upperDir, workDir)
flags := uintptr(0)
Expand Down
18 changes: 15 additions & 3 deletions drivers/overlay/overlay.go
Original file line number Diff line number Diff line change
Expand Up @@ -1557,7 +1557,11 @@ func (d *Driver) get(id string, disableShifting bool, options graphdriver.MountO
composefsMounts := []string{}
defer func() {
for _, m := range composefsMounts {
defer unix.Unmount(m, unix.MNT_DETACH)
defer func(m string) {
if err := unix.Unmount(m, unix.MNT_DETACH); err != nil {
logrus.Warnf("Unmount %q: %v", m, err)
}
}(m)
}
}()

Expand Down Expand Up @@ -1661,7 +1665,11 @@ func (d *Driver) get(id string, disableShifting bool, options graphdriver.MountO
skipIDMappingLayers[composefsMount] = composefsMount
// overlay takes a reference on the mount, so it is safe to unmount
// the mapped idmounts as soon as the final overlay file system is mounted.
defer unix.Unmount(composefsMount, unix.MNT_DETACH)
defer func() {
if err := unix.Unmount(composefsMount, unix.MNT_DETACH); err != nil {
logrus.Warnf("Unmount %q: %v", composefsMount, err)
}
}()
}
absLowers = append(absLowers, composefsMount)
continue
Expand Down Expand Up @@ -1768,7 +1776,11 @@ func (d *Driver) get(id string, disableShifting bool, options graphdriver.MountO

// overlay takes a reference on the mount, so it is safe to unmount
// the mapped idmounts as soon as the final overlay file system is mounted.
defer unix.Unmount(root, unix.MNT_DETACH)
defer func() {
if err := unix.Unmount(root, unix.MNT_DETACH); err != nil {
logrus.Warnf("Unmount %q: %v", root, err)
}
}()
}

// relative path to the layer through the id mapped mount
Expand Down
4 changes: 3 additions & 1 deletion drivers/zfs/zfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,9 @@ func (d *Driver) cloneFilesystem(name, parentName string) error {
}

if err != nil {
snapshot.Destroy(zfs.DestroyDeferDeletion)
if err1 := snapshot.Destroy(zfs.DestroyDeferDeletion); err1 != nil {
logrus.Warnf("Destroy zfs.DestroyDeferDeletion: %v", err1)
}
return err
}
return snapshot.Destroy(zfs.DestroyDeferDeletion)
Expand Down
12 changes: 8 additions & 4 deletions pkg/archive/archive_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,11 @@ func checkFileMode(t *testing.T, path string, perm os.FileMode) {
}

func TestOverlayTarUntar(t *testing.T) {
oldmask, err := system.Umask(0)
oldMask, err := system.Umask(0)
require.NoError(t, err)
defer system.Umask(oldmask)
defer func() {
_, _ = system.Umask(oldMask) // Ignore err. This can only fail with ErrNotSupportedPlatform, in which case we would have failed above.
}()

src := t.TempDir()
setupOverlayTestDir(t, src)
Expand Down Expand Up @@ -131,9 +133,11 @@ func TestOverlayTarUntar(t *testing.T) {
}

func TestOverlayTarAUFSUntar(t *testing.T) {
oldmask, err := system.Umask(0)
oldMask, err := system.Umask(0)
require.NoError(t, err)
defer system.Umask(oldmask)
defer func() {
_, _ = system.Umask(oldMask) // Ignore err. This can only fail with ErrNotSupportedPlatform, in which case we would have failed above.
}()

src := t.TempDir()
setupOverlayTestDir(t, src)
Expand Down
6 changes: 4 additions & 2 deletions pkg/chrootarchive/diff_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ func applyLayer() {
}

// We need to be able to set any perms
oldmask, err := system.Umask(0)
defer system.Umask(oldmask)
oldMask, err := system.Umask(0)
if err != nil {
fatal(err)
}
defer func() {
_, _ = system.Umask(oldMask) // Ignore err. This can only fail with ErrNotSupportedPlatform, in which case we would have failed above.
}()

if err := json.Unmarshal([]byte(os.Getenv("OPT")), &options); err != nil {
fatal(err)
Expand Down

0 comments on commit e2e98d8

Please sign in to comment.