Skip to content

Refactor inTotoMaterials to skip directories #113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 11, 2022
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
15 changes: 12 additions & 3 deletions pkg/leeway/provenance.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,16 @@ type provenanceEnvironment struct {
func (p *Package) inTotoMaterials() ([]in_toto.ProvenanceMaterial, error) {
res := make([]in_toto.ProvenanceMaterial, 0, len(p.Sources))
for _, src := range p.Sources {
if stat, err := os.Lstat(src); err != nil {
stat, err := os.Lstat(src);
if err != nil {
return nil, err
} else if !stat.Mode().IsRegular() {
}

if stat.Mode().IsDir() {
continue
}

if !stat.Mode().IsRegular() {
continue
}

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

defer f.Close()

hash := sha256.New()
_, err = io.Copy(hash, f)
if err != nil {
return "", xerrors.Errorf("cannot compute hash of %s: %w", fn, err)
}
f.Close()


return fmt.Sprintf("%x", hash.Sum(nil)), nil
}
Expand Down