Skip to content

Commit

Permalink
sbom: move too-late os.Chdir call earlier
Browse files Browse the repository at this point in the history
This fixes errors such as:

2024/09/11 08:41:50 Error: build directory
"/home/michael/gokrazy/router7/builddir/github.com/stapelberg/prober7/cmd/probe"
does not exist in
"/home/michael/gokrazy/router7/builddir/github.com/gokrazy/serial-busybox"
  • Loading branch information
stapelberg committed Sep 11, 2024
1 parent a59c9ad commit feda2a3
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions internal/packer/sbom.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,7 @@ func GenerateSBOM(cfg *config.Struct) ([]byte, SBOMWithHash, error) {
}
}

files := append([]*FileInfo{}, extraFiles[pkg]...)
if len(files) == 0 {
continue
}

// Restore the working directory before possibly 'continue'ing.
if err := os.Chdir(config.InstancePath()); err != nil {
if os.IsNotExist(err) {
// best-effort compatibility for old setups
Expand All @@ -156,6 +152,11 @@ func GenerateSBOM(cfg *config.Struct) ([]byte, SBOMWithHash, error) {
}
}

files := append([]*FileInfo{}, extraFiles[pkg]...)
if len(files) == 0 {
continue
}

for len(files) > 0 {
fi := files[0]
files = files[1:]
Expand Down

0 comments on commit feda2a3

Please sign in to comment.