Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fb0857f

Browse files
authored
Add support for indexing root filesystem (anchore#442)
* 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]>
1 parent 962e822 commit fb0857f

25 files changed

+783
-134
lines changed

internal/string_helpers.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,10 @@ func HasAnyOfPrefixes(input string, prefixes ...string) bool {
1212

1313
return false
1414
}
15+
16+
func TruncateMiddleEllipsis(input string, maxLen int) string {
17+
if len(input) <= maxLen {
18+
return input
19+
}
20+
return input[:maxLen/2] + "..." + input[len(input)-(maxLen/2):]
21+
}

internal/string_helpers_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package internal
22

33
import (
4+
"strconv"
45
"testing"
56

67
"github.com/stretchr/testify/assert"
@@ -63,3 +64,43 @@ func TestHasAnyOfPrefixes(t *testing.T) {
6364
})
6465
}
6566
}
67+
68+
func TestTruncateMiddleEllipsis(t *testing.T) {
69+
tests := []struct {
70+
input string
71+
len int
72+
expected string
73+
}{
74+
{
75+
input: "nobody expects the spanish inquisition",
76+
len: 39,
77+
expected: "nobody expects the spanish inquisition",
78+
},
79+
{
80+
input: "nobody expects the spanish inquisition",
81+
len: 30,
82+
expected: "nobody expects ...ish inquisition",
83+
},
84+
{
85+
input: "nobody expects the spanish inquisition",
86+
len: 38,
87+
expected: "nobody expects the spanish inquisition",
88+
},
89+
{
90+
input: "",
91+
len: 30,
92+
expected: "",
93+
},
94+
{
95+
input: "",
96+
len: 0,
97+
expected: "",
98+
},
99+
}
100+
101+
for _, test := range tests {
102+
t.Run(test.input+":"+strconv.Itoa(test.len), func(t *testing.T) {
103+
assert.Equal(t, test.expected, TruncateMiddleEllipsis(test.input, test.len))
104+
})
105+
}
106+
}

syft/event/event.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ const (
2323
// FileDigestsCatalogerStarted is a partybus event that occurs when the file digests cataloging has begun
2424
FileDigestsCatalogerStarted partybus.EventType = "syft-file-digests-cataloger-started-event"
2525

26+
// FileIndexingStarted is a partybus event that occurs when the directory resolver begins indexing a filesystem
27+
FileIndexingStarted partybus.EventType = "syft-file-indexing-started-event"
28+
2629
// PresenterReady is a partybus event that occurs when an analysis result is ready for final presentation
2730
PresenterReady partybus.EventType = "syft-presenter-ready-event"
2831

syft/event/parsers/parsers.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,24 @@ func ParseFileDigestsCatalogingStarted(e partybus.Event) (progress.StagedProgres
9494
return prog, nil
9595
}
9696

97+
func ParseFileIndexingStarted(e partybus.Event) (string, progress.StagedProgressable, error) {
98+
if err := checkEventType(e.Type, event.FileIndexingStarted); err != nil {
99+
return "", nil, err
100+
}
101+
102+
path, ok := e.Source.(string)
103+
if !ok {
104+
return "", nil, newPayloadErr(e.Type, "Source", e.Source)
105+
}
106+
107+
prog, ok := e.Value.(progress.StagedProgressable)
108+
if !ok {
109+
return "", nil, newPayloadErr(e.Type, "Value", e.Value)
110+
}
111+
112+
return path, prog, nil
113+
}
114+
97115
func ParsePresenterReady(e partybus.Event) (presenter.Presenter, error) {
98116
if err := checkEventType(e.Type, event.PresenterReady); err != nil {
99117
return nil, err

0 commit comments

Comments
 (0)