mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +01:00
fix: move defer after error to protect panic case (#1670)
Signed-off-by: Christopher Phillips <christopher.phillips@anchore.com>
This commit is contained in:
parent
e3140063d4
commit
61362c04fa
@ -385,11 +385,11 @@ func (s *Source) SetID() {
|
|||||||
case FileScheme:
|
case FileScheme:
|
||||||
// attempt to use the digest of the contents of the file as the ID
|
// attempt to use the digest of the contents of the file as the ID
|
||||||
file, err := os.Open(s.Metadata.Path)
|
file, err := os.Open(s.Metadata.Path)
|
||||||
defer file.Close()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
d = digest.FromString(s.Metadata.Path).String()
|
d = digest.FromString(s.Metadata.Path).String()
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
defer file.Close()
|
||||||
di, err := digest.FromReader(file)
|
di, err := digest.FromReader(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
d = digest.FromString(s.Metadata.Path).String()
|
d = digest.FromString(s.Metadata.Path).String()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user