suppress file already closed errors (#3695)

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
This commit is contained in:
Alex Goodman 2025-02-27 16:52:50 -05:00 committed by GitHub
parent 5e2723187d
commit f6605a3817
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"io"
"io/fs"
"os"
"github.com/anchore/syft/internal/log"
@ -12,6 +13,10 @@ import (
// CloseAndLogError closes the given io.Closer and reports any errors found as a warning in the log
func CloseAndLogError(closer io.Closer, location string) {
if err := closer.Close(); err != nil {
// suppress "file already closed" log messages
if errors.Is(err, fs.ErrClosed) {
return
}
log.Debugf("unable to close file for location=%q: %+v", location, err)
}
}