Skip to content

Commit

Permalink
when fetching a blob, mock oci server handler now walks specified sta…
Browse files Browse the repository at this point in the history
…ck's directory rather than iterate through immediate children.

Signed-off-by: Michael Valdron <mvaldron@redhat.com>
  • Loading branch information
michael-valdron committed Jul 29, 2022
1 parent a415a06 commit 4e4749a
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions index/server/pkg/server/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"io"
"io/fs"
"io/ioutil"
"log"
"net/http"
Expand Down Expand Up @@ -177,29 +178,37 @@ func digestFile(filepath string) (string, error) {
func serveBlob(c *gin.Context) {
name, dgst := c.Param("name"), c.Param("digest")
stackRoot := filepath.Join(stacksPath, name)
stackRootList, err := ioutil.ReadDir(stackRoot)
if err != nil {
log.Fatal(err)
}
var (
blobPath string
found bool
err error
)

found = false
for _, stackFile := range stackRootList {
fpath := filepath.Join(stackRoot, stackFile.Name())
fdgst, err := digestFile(fpath)
err = filepath.WalkDir(stackRoot, func(path string, d fs.DirEntry, err error) error {
var fdgst string

if err != nil {
log.Fatal(err)
return err
}

if found || d.IsDir() {
return nil
}

fdgst, err = digestFile(path)
if err != nil {
return err
} else if reflect.DeepEqual(dgst, fdgst) {
blobPath = fpath
blobPath = path
found = true
break
}
}

if !found {
return nil
})
if err != nil {
log.Fatal(err)
} else if !found {
notFoundBlob(c)
return
}
Expand Down

0 comments on commit 4e4749a

Please sign in to comment.