mirror of
https://github.com/anchore/syft.git
synced 2026-11-02 23:46:35 +01:00
ignore irregular files while indexing directory (#616)
* stop hidding command from help doc Signed-off-by: Jonas Galvão Xavier <jonas.agx@gmail.com> * do not index irregular files Signed-off-by: Jonas Galvão Xavier <jonas.agx@gmail.com> * fix fixture dir and err name Signed-off-by: Jonas Galvão Xavier <jonas.agx@gmail.com> * improve the description of irregular files Signed-off-by: Jonas Galvão Xavier <jonas.agx@gmail.com> * explicitly check indexed file name Signed-off-by: Jonas Galvão Xavier <jonas.agx@gmail.com>
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
package source
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strings"
|
||||
"syscall"
|
||||
"testing"
|
||||
|
||||
"github.com/scylladb/go-set/strset"
|
||||
@@ -459,3 +462,29 @@ func Test_directoryResolver_FilesByMIMEType(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_ignoreIrregularFiles(t *testing.T) {
|
||||
// NOTE: craeting a pipe/fifo file on demand since git doesn't let me
|
||||
// commit one. The directory resolver should ignore it (and any other
|
||||
// file that is neither regular, a symlink or directory) when indexing a directory
|
||||
dir := "./test-fixtures/irregular-files"
|
||||
f := "f.fifo"
|
||||
|
||||
err := syscall.Mknod(filepath.Join(dir, f), syscall.S_IFIFO|0666, 0)
|
||||
assert.NoError(t, err)
|
||||
defer func() {
|
||||
err := os.Remove(filepath.Join(dir, f))
|
||||
assert.NoError(t, err)
|
||||
}()
|
||||
|
||||
fileRefs, err := ioutil.ReadDir(dir)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, fileRefs, 2) // two files (f.fifo and readme)
|
||||
|
||||
resolver, err := newDirectoryResolver(dir)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Len(t, resolver.fileTree.AllFiles(), 1)
|
||||
rp := resolver.fileTree.AllFiles()[0].RealPath
|
||||
assert.True(t, strings.Contains(string(rp), filepath.Join(dir, "readme")))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user