diff --git a/.github/workflows/makefile.yml b/.github/workflows/makefile.yml index f23c9d0..f33efb4 100644 --- a/.github/workflows/makefile.yml +++ b/.github/workflows/makefile.yml @@ -14,13 +14,7 @@ jobs: - name: Build Static run: make ociv - name: upload binary - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: ociv path: ociv - lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Lint Go Code - run: make lint diff --git a/Makefile b/Makefile index a7b78ee..fc04ed1 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,8 @@ GOLINTER_VERSION := v1.54.2 GOLINTER := $(TOOLSDIR)/bin/golangci-lint -ociv: *.go lint +ociv: *.go + go env CGO_ENABLED=0 go build ${LDFLAGS} ${GOTAGS} -o ociv ./... $(GOLINTER): diff --git a/ociutils.go b/ociutils.go index a13e71f..be19677 100644 --- a/ociutils.go +++ b/ociutils.go @@ -138,17 +138,26 @@ func (lr layerRef) summary(filter string) string { return cachedSummary } - filterArg := "" - if filter != "" { - filterArg = " | grep " + filter + fileListFilename := fmt.Sprintf("/tmp/%s-filelist", lr.hash) + if _, err := os.Stat(fileListFilename); os.IsNotExist(err) { + cmdstr := "tar tzvf " + lr.blobfilepath + if strings.Contains(lr.mediaType, "squashfs") { + cmdstr = "unsquashfs -llc " + lr.blobfilepath + } + cmd := exec.Command("sh", "-c", cmdstr+" > "+fileListFilename) + err := cmd.Run() + if err != nil { + log.Printf("error: %v", err) + return fmt.Sprintf(" error: %v", err) + } } - cmdstr := "tar tzvf " + lr.blobfilepath + filterArg - if strings.Contains(lr.mediaType, "squashfs") { - cmdstr = "echo TODO: gunzip -c " + lr.blobfilepath + " |unsquashfs -llc " - //TODO: can't unsquash via pipe, need to gunzip to tempfile and delete + filterArg := "cat " + if filter != "" { + filterArg = " grep " + filter } - cmd := exec.Command("sh", "-c", cmdstr) + cmd := exec.Command("sh", "-c", filterArg+" "+fileListFilename) + var out strings.Builder var stderr strings.Builder cmd.Stdout = &out @@ -157,7 +166,8 @@ func (lr layerRef) summary(filter string) string { if err != nil { log.Printf("error: %v", err) } - summaryString := fmt.Sprintf("%q\n%q\n%s\n%s", lr.displayString, cmdstr, out.String(), stderr.String()) + + summaryString := fmt.Sprintf("file listing of blob %q (%s)\n\n%s\n%s", lr.displayString, lr.mediaType, out.String(), stderr.String()) LayerSummaryCache[layerfilterkey] = summaryString return summaryString }