Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion pkg/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ func (b *Build) BuildPackage(ctx context.Context) error {
return fmt.Errorf("mkdir -p %s: %w", b.WorkspaceDir, err)
}

fs := os.DirFS(b.SourceDir)
fs := apkofs.DirFS(b.SourceDir)
if fs != nil {
log.Infof("populating workspace %s from %s", b.WorkspaceDir, b.SourceDir)
if err := b.populateWorkspace(ctx, fs); err != nil {
Expand Down
18 changes: 5 additions & 13 deletions pkg/build/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,19 +209,11 @@ func (t *Test) PopulateWorkspace(ctx context.Context, src fs.FS) error {

log.Infof("populating workspace %s from %s", t.WorkspaceDir, t.SourceDir)

fi, err := os.Stat(t.SourceDir)
switch {
case err != nil && !os.IsNotExist(err):
return fmt.Errorf("stating dir %s: %w", t.SourceDir, err)
case err != nil && os.IsNotExist(err):
if err := os.MkdirAll(t.SourceDir, 0o700); err != nil {
return fmt.Errorf("creating dir %s: %w", t.SourceDir, err)
}
case !fi.IsDir():
return fmt.Errorf("not a directory: %s", t.SourceDir)
}
fsys := apkofs.DirFS(t.SourceDir, apkofs.WithCreateDir())

fsys := os.DirFS(t.SourceDir)
if fsys == nil {
return fmt.Errorf("unable to create/use directory %s", t.SourceDir)
}

return fs.WalkDir(fsys, ".", func(path string, d fs.DirEntry, err error) error {
if err != nil {
Expand Down Expand Up @@ -304,7 +296,7 @@ func (t *Test) TestPackage(ctx context.Context) error {
return fmt.Errorf("mkdir -p %s: %w", t.WorkspaceDir, err)
}

if err := t.PopulateWorkspace(ctx, os.DirFS(t.SourceDir)); err != nil {
if err := t.PopulateWorkspace(ctx, apkofs.DirFS(t.SourceDir)); err != nil {
return fmt.Errorf("unable to populate workspace: %w", err)
}
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/cli/license_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/spf13/cobra"

apkofs "chainguard.dev/apko/pkg/apk/fs"
"chainguard.dev/melange/pkg/config"
"chainguard.dev/melange/pkg/license"
"chainguard.dev/melange/pkg/renovate"
Expand Down Expand Up @@ -68,7 +69,7 @@ func licenseCheck() *cobra.Command {
if err != nil {
return fmt.Errorf("failed to get absolute path for source directory: %w", err)
}
sourceFS := os.DirFS(sourceDir)
sourceFS := apkofs.DirFS(sourceDir)
detectedLicenses, diffs, err := license.LicenseCheck(ctx, cfg, sourceFS)
if err != nil {
return err
Expand Down
11 changes: 6 additions & 5 deletions pkg/license/license_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"strings"
"testing"

apkofs "chainguard.dev/apko/pkg/apk/fs"
"chainguard.dev/melange/pkg/config"
"github.com/chainguard-dev/clog"
)
Expand Down Expand Up @@ -58,7 +59,7 @@ func TestFindLicenseFiles(t *testing.T) {
fp.Close()
}

tmpFS := os.DirFS(tmpDir)
tmpFS := apkofs.DirFS(tmpDir)

// Call function under test
licenseFiles, err := FindLicenseFiles(tmpFS)
Expand Down Expand Up @@ -134,7 +135,7 @@ func TestFindLicenseFiles(t *testing.T) {
fp.Close()
}

tmpFS = os.DirFS(tmpDir)
tmpFS = apkofs.DirFS(tmpDir)

// Call function under test
licenseFiles, err = FindLicenseFiles(tmpFS)
Expand Down Expand Up @@ -164,7 +165,7 @@ func TestIdentify(t *testing.T) {
}

testDataDir := "testdata"
dataFS := os.DirFS(testDataDir)
dataFS := apkofs.DirFS(testDataDir)
err = fs.WalkDir(dataFS, ".", func(path string, info fs.DirEntry, err error) error {
if err != nil {
t.Errorf("Error walking through testdata directory: %v", err)
Expand Down Expand Up @@ -216,7 +217,7 @@ func TestLicenseCheck(t *testing.T) {
}

testDataDir := "testdata"
dataFS := os.DirFS(testDataDir)
dataFS := apkofs.DirFS(testDataDir)

// Create a buffer to capture log output
var logBuf strings.Builder
Expand Down Expand Up @@ -292,7 +293,7 @@ func TestLicenseCheck_withOverrides(t *testing.T) {
}

testDataDir := "testdata"
dataFS := os.DirFS(testDataDir)
dataFS := apkofs.DirFS(testDataDir)

// Call function under test
_, diffs, err := LicenseCheck(context.Background(), cfg, dataFS)
Expand Down
3 changes: 2 additions & 1 deletion pkg/linter/linter.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"slices"
"strings"

apkofs "chainguard.dev/apko/pkg/apk/fs"
"github.com/chainguard-dev/clog"
"github.com/dustin/go-humanize"
"golang.org/x/exp/maps"
Expand Down Expand Up @@ -683,7 +684,7 @@ func LintBuild(ctx context.Context, cfg *config.Configuration, packageName strin
}

log := clog.FromContext(ctx)
fsys := os.DirFS(path)
fsys := apkofs.DirFS(path)

if err := lintPackageFS(ctx, cfg, packageName, fsys, warn); err != nil {
log.Warn(err.Error())
Expand Down
Loading