fix: propagate unarchive error of file source (#3845)

Signed-off-by: Kudryavcev Nikolay <kydry.nikolau@gmail.com>
This commit is contained in:
Kudryavcev Nikolay 2025-05-05 18:37:47 +03:00 committed by GitHub
parent d47a6c3a6d
commit e13c9e7813
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -59,7 +59,10 @@ func New(cfg Config) (source.Source, error) {
return nil, fmt.Errorf("given path is a directory: %q", cfg.Path)
}
analysisPath, cleanupFn := fileAnalysisPath(cfg.Path, cfg.SkipExtractArchive)
analysisPath, cleanupFn, err := fileAnalysisPath(cfg.Path, cfg.SkipExtractArchive)
if err != nil {
return nil, fmt.Errorf("unable to extract file analysis path=%q: %w", cfg.Path, err)
}
var digests []file.Digest
if len(cfg.DigestAlgorithms) > 0 {
@ -209,12 +212,12 @@ func (s *fileSource) Close() error {
// contents have been made available. A cleanup function is provided for any temp files created (if any).
// Users can disable unpacking archives, allowing individual cataloguers to extract them instead (where
// supported)
func fileAnalysisPath(path string, skipExtractArchive bool) (string, func() error) {
func fileAnalysisPath(path string, skipExtractArchive bool) (string, func() error, error) {
var cleanupFn = func() error { return nil }
var analysisPath = path
if skipExtractArchive {
return analysisPath, cleanupFn
return analysisPath, cleanupFn, nil
}
// if the given file is an archive (as indicated by the file extension and not MIME type) then unarchive it and
@ -228,19 +231,16 @@ func fileAnalysisPath(path string, skipExtractArchive bool) (string, func() erro
// NOTE: this currently does not display any messages if an overwrite happens
tar.OverwriteExisting = true
}
unarchivedPath, tmpCleanup, err := unarchiveToTmp(path, unarchiver)
analysisPath, cleanupFn, err = unarchiveToTmp(path, unarchiver)
if err != nil {
log.Warnf("file could not be unarchived: %+v", err)
} else {
log.Debugf("source path is an archive")
analysisPath = unarchivedPath
}
if tmpCleanup != nil {
cleanupFn = tmpCleanup
return "", nil, fmt.Errorf("unable to unarchive source file: %w", err)
}
log.Debugf("source path is an archive")
}
return analysisPath, cleanupFn
return analysisPath, cleanupFn, nil
}
func digestOfFileContents(path string) string {