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 1) #1998

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
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 @@ -1555,7 +1555,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 @@ -1659,7 +1663,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 @@ -1766,7 +1774,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