Skip to content

Commit

Permalink
Add support for indexing root filesystem (anchore#442)
Browse files Browse the repository at this point in the history
* change directory resolver to ignore system runtime paths + drive by index

Signed-off-by: Alex Goodman <[email protected]>

* add event/etui support for filesystem indexing (for dir resolver)

Signed-off-by: Alex Goodman <[email protected]>

* add warnings for path indexing problems

Signed-off-by: Alex Goodman <[email protected]>

* add directory resolver index tests

Signed-off-by: Alex Goodman <[email protected]>

* improve testing around directory resolver

Signed-off-by: Alex Goodman <[email protected]>

* renamed p var to path when not conflicting with import

Signed-off-by: Alex Goodman <[email protected]>

* pull docker image in CLI dir scan timeout test

Signed-off-by: Alex Goodman <[email protected]>

* ensure file not exist errors do not stop directory resolver indexing

Signed-off-by: Alex Goodman <[email protected]>
  • Loading branch information
wagoodman authored Jun 29, 2021
1 parent d3a0449 commit 8009f73
Show file tree
Hide file tree
Showing 25 changed files with 783 additions and 134 deletions.
7 changes: 7 additions & 0 deletions internal/string_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,10 @@ func HasAnyOfPrefixes(input string, prefixes ...string) bool {

return false
}

func TruncateMiddleEllipsis(input string, maxLen int) string {
if len(input) <= maxLen {
return input
}
return input[:maxLen/2] + "..." + input[len(input)-(maxLen/2):]
}
41 changes: 41 additions & 0 deletions internal/string_helpers_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package internal

import (
"strconv"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -63,3 +64,43 @@ func TestHasAnyOfPrefixes(t *testing.T) {
})
}
}

func TestTruncateMiddleEllipsis(t *testing.T) {
tests := []struct {
input string
len int
expected string
}{
{
input: "nobody expects the spanish inquisition",
len: 39,
expected: "nobody expects the spanish inquisition",
},
{
input: "nobody expects the spanish inquisition",
len: 30,
expected: "nobody expects ...ish inquisition",
},
{
input: "nobody expects the spanish inquisition",
len: 38,
expected: "nobody expects the spanish inquisition",
},
{
input: "",
len: 30,
expected: "",
},
{
input: "",
len: 0,
expected: "",
},
}

for _, test := range tests {
t.Run(test.input+":"+strconv.Itoa(test.len), func(t *testing.T) {
assert.Equal(t, test.expected, TruncateMiddleEllipsis(test.input, test.len))
})
}
}
3 changes: 3 additions & 0 deletions syft/event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ const (
// FileDigestsCatalogerStarted is a partybus event that occurs when the file digests cataloging has begun
FileDigestsCatalogerStarted partybus.EventType = "syft-file-digests-cataloger-started-event"

// FileIndexingStarted is a partybus event that occurs when the directory resolver begins indexing a filesystem
FileIndexingStarted partybus.EventType = "syft-file-indexing-started-event"

// PresenterReady is a partybus event that occurs when an analysis result is ready for final presentation
PresenterReady partybus.EventType = "syft-presenter-ready-event"

Expand Down
18 changes: 18 additions & 0 deletions syft/event/parsers/parsers.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,24 @@ func ParseFileDigestsCatalogingStarted(e partybus.Event) (progress.StagedProgres
return prog, nil
}

func ParseFileIndexingStarted(e partybus.Event) (string, progress.StagedProgressable, error) {
if err := checkEventType(e.Type, event.FileIndexingStarted); err != nil {
return "", nil, err
}

path, ok := e.Source.(string)
if !ok {
return "", nil, newPayloadErr(e.Type, "Source", e.Source)
}

prog, ok := e.Value.(progress.StagedProgressable)
if !ok {
return "", nil, newPayloadErr(e.Type, "Value", e.Value)
}

return path, prog, nil
}

func ParsePresenterReady(e partybus.Event) (presenter.Presenter, error) {
if err := checkEventType(e.Type, event.PresenterReady); err != nil {
return nil, err
Expand Down
Loading

0 comments on commit 8009f73

Please sign in to comment.