mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +01:00
fix: propagate unarchive error of file source (#3845)
Signed-off-by: Kudryavcev Nikolay <kydry.nikolau@gmail.com>
This commit is contained in:
parent
d47a6c3a6d
commit
e13c9e7813
@ -59,7 +59,10 @@ func New(cfg Config) (source.Source, error) {
|
|||||||
return nil, fmt.Errorf("given path is a directory: %q", cfg.Path)
|
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
|
var digests []file.Digest
|
||||||
if len(cfg.DigestAlgorithms) > 0 {
|
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).
|
// 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
|
// Users can disable unpacking archives, allowing individual cataloguers to extract them instead (where
|
||||||
// supported)
|
// 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 cleanupFn = func() error { return nil }
|
||||||
var analysisPath = path
|
var analysisPath = path
|
||||||
|
|
||||||
if skipExtractArchive {
|
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
|
// 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
|
// NOTE: this currently does not display any messages if an overwrite happens
|
||||||
tar.OverwriteExisting = true
|
tar.OverwriteExisting = true
|
||||||
}
|
}
|
||||||
unarchivedPath, tmpCleanup, err := unarchiveToTmp(path, unarchiver)
|
|
||||||
|
analysisPath, cleanupFn, err = unarchiveToTmp(path, unarchiver)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("file could not be unarchived: %+v", err)
|
return "", nil, fmt.Errorf("unable to unarchive source file: %w", err)
|
||||||
} else {
|
|
||||||
log.Debugf("source path is an archive")
|
|
||||||
analysisPath = unarchivedPath
|
|
||||||
}
|
|
||||||
if tmpCleanup != nil {
|
|
||||||
cleanupFn = tmpCleanup
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Debugf("source path is an archive")
|
||||||
}
|
}
|
||||||
|
|
||||||
return analysisPath, cleanupFn
|
return analysisPath, cleanupFn, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func digestOfFileContents(path string) string {
|
func digestOfFileContents(path string) string {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user