Skip to content

Commit eb150df

Browse files
committed
Refactor inTotoMaterials to skip directories
1 parent b2e0dc4 commit eb150df

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

pkg/leeway/provenance.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,13 @@ func (p *Package) inTotoMaterials() ([]in_toto.ProvenanceMaterial, error) {
297297
for _, src := range p.Sources {
298298
if stat, err := os.Lstat(src); err != nil {
299299
return nil, err
300-
} else if !stat.Mode().IsRegular() {
300+
}
301+
302+
if stat.Mode().IsDir() {
303+
continue
304+
}
305+
306+
if !stat.Mode().IsRegular() {
301307
continue
302308
}
303309

@@ -326,12 +332,14 @@ func sha256Hash(fn string) (res string, err error) {
326332
return "", xerrors.Errorf("cannot compute hash of %s: %w", fn, err)
327333
}
328334

335+
defer f.Close()
336+
329337
hash := sha256.New()
330338
_, err = io.Copy(hash, f)
331339
if err != nil {
332340
return "", xerrors.Errorf("cannot compute hash of %s: %w", fn, err)
333341
}
334-
f.Close()
342+
335343

336344
return fmt.Sprintf("%x", hash.Sum(nil)), nil
337345
}

0 commit comments

Comments
 (0)