Skip to content

Commit

Permalink
Merge branch 'buildpacks:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
dilipgb authored Sep 11, 2023
2 parents 1c03754 + aeb177c commit 200d0a0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
2 changes: 2 additions & 0 deletions cmd/lifecycle/restorer.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ func (r *restoreCmd) DefineFlags() {
if r.PlatformAPI.AtLeast("0.12") {
cli.FlagUseDaemon(&r.UseDaemon)
cli.FlagGeneratedDir(&r.GeneratedDir)
cli.FlagUseLayout(&r.UseLayout)
cli.FlagLayoutDir(&r.LayoutDir)
}
if r.PlatformAPI.AtLeast("0.10") {
cli.FlagBuildImage(&r.BuildImageRef)
Expand Down
12 changes: 8 additions & 4 deletions image/layout_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"path/filepath"
"strings"

"github.com/buildpacks/imgutil"
"github.com/buildpacks/imgutil/layout"
Expand Down Expand Up @@ -33,11 +34,14 @@ func (h *LayoutHandler) Kind() string {
}

func (h *LayoutHandler) parseRef(imageRef string) (string, error) {
path, err := layout.ParseRefToPath(imageRef)
if err != nil {
return "", err
if !strings.HasPrefix(imageRef, h.layoutDir) {
path, err := layout.ParseRefToPath(imageRef)
if err != nil {
return "", err
}
return filepath.Join(h.layoutDir, path), nil
}
return filepath.Join(h.layoutDir, path), nil
return imageRef, nil
}

// helpers
Expand Down
12 changes: 12 additions & 0 deletions image/layout_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,18 @@ func testLayoutImageHandler(t *testing.T, when spec.G, it spec.S) {
h.AssertNotNil(t, err)
})
})

when("image reference is a layout path", func() {
it.Before(func() {
imageRef = filepath.Join(layoutDir, "index.docker.io", "cnbs", "sample-stack-run", "jammy")
})

it("it returns the same path value", func() {
image, err := imageHandler.InitImage(imageRef)
h.AssertNil(t, err)
h.AssertEq(t, image.Name(), imageRef)
})
})
})
})
}
Expand Down

0 comments on commit 200d0a0

Please sign in to comment.