Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support extension and filename matching for files larger than MaximumFileSize #98

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions core/match.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,19 @@ type MatchFile struct {
}

func NewMatchFile(path string) MatchFile {
maxFileSize := *session.Options.MaximumFileSize * 1024
path = filepath.ToSlash(path)
_, filename := filepath.Split(path)
extension := filepath.Ext(path)
contents, _ := ioutil.ReadFile(path)

var contents []byte
fi, err := os.Stat(path)
if err == nil {
size := fi.Size()
if size < int64(maxFileSize) {
contents, _ = ioutil.ReadFile(path)
}
}

return MatchFile{
Path: path,
Expand Down Expand Up @@ -63,10 +72,9 @@ func (match MatchFile) CanCheckEntropy() bool {

func GetMatchingFiles(dir string) []MatchFile {
fileList := make([]MatchFile, 0)
maxFileSize := *session.Options.MaximumFileSize * 1024

filepath.Walk(dir, func(path string, f os.FileInfo, err error) error {
if err != nil || f.IsDir() || uint(f.Size()) > maxFileSize || IsSkippableFile(path) {
if err != nil || f.IsDir() || IsSkippableFile(path) {
return nil
}
fileList = append(fileList, NewMatchFile(path))
Expand Down