Skip to content

Commit 26d7d91

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

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

pkg/leeway/provenance.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,16 @@ type provenanceEnvironment struct {
295295
func (p *Package) inTotoMaterials() ([]in_toto.ProvenanceMaterial, error) {
296296
res := make([]in_toto.ProvenanceMaterial, 0, len(p.Sources))
297297
for _, src := range p.Sources {
298-
if stat, err := os.Lstat(src); err != nil {
298+
stat, err := os.Lstat(src);
299+
if err != nil {
299300
return nil, err
300-
} else if !stat.Mode().IsRegular() {
301+
}
302+
303+
if stat.Mode().IsDir() {
304+
continue
305+
}
306+
307+
if !stat.Mode().IsRegular() {
301308
continue
302309
}
303310

@@ -326,12 +333,14 @@ func sha256Hash(fn string) (res string, err error) {
326333
return "", xerrors.Errorf("cannot compute hash of %s: %w", fn, err)
327334
}
328335

336+
defer f.Close()
337+
329338
hash := sha256.New()
330339
_, err = io.Copy(hash, f)
331340
if err != nil {
332341
return "", xerrors.Errorf("cannot compute hash of %s: %w", fn, err)
333342
}
334-
f.Close()
343+
335344

336345
return fmt.Sprintf("%x", hash.Sum(nil)), nil
337346
}

0 commit comments

Comments
 (0)