Skip to content
Merged
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
24 changes: 12 additions & 12 deletions syft/source/filesource/file_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down
Loading