mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-14 18:53:35 +00:00
cleanup: address golangci 'errcheck' issues
Many reports are about closing or removing files. In some cases it is possible to report an error in the logs, in other cases the error can be ignored without potential issues. Test cases have been modified to not remove the temporary files. The temporary directory that is provided by the testing package, is removed once the tests are done. Signed-off-by: Niels de Vos <ndevos@ibm.com>
This commit is contained in:
committed by
mergify[bot]
parent
0a22e3a186
commit
bc8b1e792f
@ -21,6 +21,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
rbderrors "github.com/ceph/ceph-csi/internal/rbd/errors"
|
||||
"github.com/ceph/ceph-csi/internal/util/log"
|
||||
)
|
||||
|
||||
// Sparsify checks the size of the objects in the RBD image and calls
|
||||
@ -28,7 +29,7 @@ import (
|
||||
// of the image.
|
||||
// This function will return ErrImageInUse if the image is in use, since
|
||||
// sparsifying an image on which i/o is in progress is not optimal.
|
||||
func (ri *rbdImage) Sparsify(_ context.Context) error {
|
||||
func (ri *rbdImage) Sparsify(ctx context.Context) error {
|
||||
inUse, err := ri.isInUse()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to check if image is in use: %w", err)
|
||||
@ -42,7 +43,12 @@ func (ri *rbdImage) Sparsify(_ context.Context) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer image.Close()
|
||||
defer func() {
|
||||
cErr := image.Close()
|
||||
if cErr != nil {
|
||||
log.WarningLog(ctx, "resource leak, failed to close image: %v", cErr)
|
||||
}
|
||||
}()
|
||||
|
||||
imageInfo, err := image.Stat()
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user