Skip to content

Commit

Permalink
Rebase fixes and windows fix
Browse files Browse the repository at this point in the history
  • Loading branch information
filip-debricked committed Mar 27, 2024
1 parent 6996f61 commit 99ec89b
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 25 deletions.
21 changes: 16 additions & 5 deletions internal/file/exclusion.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package file

import (
"fmt"
"os"
"path/filepath"
"strings"
Expand All @@ -27,7 +28,7 @@ var defaultExclusions = DefaultExclusionList{
func DefaultExclusions() []string {
var exclusions []string
for _, excluded_dir := range defaultExclusions.Directories {
exclusions = append(exclusions, filepath.Join("**", excluded_dir, "**"))
exclusions = append(exclusions, "**/"+excluded_dir+"/**")
}

return exclusions
Expand All @@ -45,16 +46,26 @@ func Exclusions() []string {
}

func Excluded(exclusions []string, inclusions []string, path string) bool {
if strings.Contains(path, "Content_Types") {
path = filepath.ToSlash(path)
fmt.Println(path)
for _, inclusion := range inclusions {
fmt.Println(filepath.ToSlash(inclusion))
}
for _, exclusion := range exclusions {
fmt.Println(filepath.ToSlash(exclusion))
}
}
for _, inclusion := range inclusions {
ex := filepath.Clean(inclusion)
matched, _ := doublestar.PathMatch(ex, path)
path = filepath.ToSlash(path)
matched, _ := doublestar.Match(inclusion, path)
if matched {
return false
}
}
for _, exclusion := range exclusions {
ex := filepath.Clean(exclusion)
matched, _ := doublestar.PathMatch(ex, path)
path = filepath.ToSlash(path)
matched, _ := doublestar.Match(exclusion, path)
if matched {
return true
}
Expand Down
10 changes: 5 additions & 5 deletions internal/file/exclusion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ func TestExclusionsWithEmptyTokenEnvVariable(t *testing.T) {
}(debrickedExclusionEnvVar, oldEnvValue)

gt := []string{
filepath.Join("**", "node_modules", "**"),
filepath.Join("**", "vendor", "**"),
filepath.Join("**", ".git", "**"),
filepath.Join("**", "obj", "**"),
filepath.Join("**", "bower_components", "**"),
"**/" + "node_modules" + "/**",
"**/" + "vendor" + "/**",
"**/" + ".git" + "/**",
"**/" + "obj" + "/**",
"**/" + "bower_components" + "/**",
}
defaultExclusions := Exclusions()
assert.Equal(t, gt, defaultExclusions)
Expand Down
6 changes: 3 additions & 3 deletions internal/file/finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type DebrickedOptions struct {
type IFinder interface {
GetGroups(options DebrickedOptions) (Groups, error)
GetSupportedFormats() ([]*CompiledFormat, error)
GetConfigPath(rootPath string, exclusions []string) string
GetConfigPath(rootPath string, exclusions []string, inclusions []string) string
}

type Finder struct {
Expand All @@ -49,15 +49,15 @@ func NewFinder(c client.IDebClient, fs ioFs.IFileSystem) (*Finder, error) {
return &Finder{c, fs}, nil
}

func (finder *Finder) GetConfigPath(rootPath string, exclusions []string) string {
func (finder *Finder) GetConfigPath(rootPath string, exclusions []string, inclusions []string) string {
var configPath string
err := filepath.Walk(
rootPath,
func(path string, fileInfo os.FileInfo, err error) error {
if err != nil {
return err
}
if !fileInfo.IsDir() && !Excluded(exclusions, path) {
if !fileInfo.IsDir() && !Excluded(exclusions, inclusions, path) {
if filepath.Base(path) == "debricked-config.yaml" {
configPath = path
}
Expand Down
2 changes: 1 addition & 1 deletion internal/file/finder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func TestGetGroupsWithTwoFileMatchesInSameDir(t *testing.T) {

func TestGetDebrickedConfig(t *testing.T) {
path := "testdata"
configPath := finder.GetConfigPath(path, nil)
configPath := finder.GetConfigPath(path, nil, nil)
assert.Equal(t, filepath.Join("testdata", "misc", "debricked-config.yaml"), configPath)
}

Expand Down
2 changes: 1 addition & 1 deletion internal/file/testdata/finder_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (f *FinderMock) GetGroups(_ file.DebrickedOptions) (file.Groups, error) {
return f.groups, f.error
}

func (f *FinderMock) GetConfigPath(_ string, _ []string) string {
func (f *FinderMock) GetConfigPath(_ string, _ []string, _ []string) string {
return ""
}

Expand Down
10 changes: 4 additions & 6 deletions internal/fingerprint/exclusion.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package fingerprint

import "path/filepath"

type DefaultFingerprintExclusionList struct {
Directories []string
Files []string
Expand Down Expand Up @@ -59,16 +57,16 @@ var defaultFingerprintExclusions = DefaultFingerprintExclusionList{
func DefaultExclusionsFingerprint() []string {
var default_exclusions []string
for _, excluded_dir := range defaultFingerprintExclusions.Directories {
default_exclusions = append(default_exclusions, filepath.Join("**", excluded_dir, "**"))
default_exclusions = append(default_exclusions, "**/"+excluded_dir+"/**")
}
for _, excluded_file := range defaultFingerprintExclusions.Files {
default_exclusions = append(default_exclusions, filepath.Join("**", excluded_file))
default_exclusions = append(default_exclusions, "**/**/"+excluded_file)
}
for _, excluded_extension := range defaultFingerprintExclusions.Extensions {
default_exclusions = append(default_exclusions, filepath.Join("**", "*"+excluded_extension))
default_exclusions = append(default_exclusions, "**/*"+excluded_extension)
}
for _, excluded_ending := range defaultFingerprintExclusions.Extensions {
default_exclusions = append(default_exclusions, filepath.Join("**", "*"+excluded_ending))
default_exclusions = append(default_exclusions, "**/*"+excluded_ending)
}

return default_exclusions
Expand Down
19 changes: 18 additions & 1 deletion internal/fingerprint/fingerprint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ func TestInMemFingerprintingCompressedContent(t *testing.T) {
},
{
name: "Nupkg",
path: "testdata/archive/nupkg",
path: filepath.Join("testdata", "archive", "nupkg"),
expected: 21,
suffix: "newtonsoft.json.13.0.3.nupkg",
shouldUnzip: true,
Expand Down Expand Up @@ -491,6 +491,23 @@ func TestInMemFingerprintingCompressedContent(t *testing.T) {
}
}

func TestInMemFingerprintingCompressedContentSpecificFiles(t *testing.T) {
fingerprinter := NewFingerprinter()
fingerprints, err := fingerprinter.FingerprintFiles(
DebrickedOptions{
Path: filepath.Join("testdata", "archive", "nupkg"),
Exclusions: []string{},
Inclusions: []string{},
FingerprintCompressedContent: true,
MinFingerprintContentLength: 45,
},
)
assert.NoError(t, err)
assert.NotNil(t, fingerprints)
assert.NotEmpty(t, fingerprints)
assert.Equal(t, 21, fingerprints.Len())
}

func TestComputeHashForFile(t *testing.T) {
tests := []struct {
name string
Expand Down
6 changes: 3 additions & 3 deletions internal/scan/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func (dScanner *DebrickedScanner) scan(options DebrickedOptions, gitMetaObject g
IntegrationsName: options.IntegrationName,
CallGraphUploadTimeout: options.CallGraphUploadTimeout,
VersionHint: options.VersionHint,
DebrickedConfig: dScanner.getDebrickedConfig(options.Path, options.Exclusions),
DebrickedConfig: dScanner.getDebrickedConfig(options.Path, options.Exclusions, options.Inclusions),
}
result, err := (*dScanner.uploader).Upload(uploaderOptions)
if err != nil {
Expand All @@ -245,8 +245,8 @@ func (dScanner *DebrickedScanner) scan(options DebrickedOptions, gitMetaObject g
return result, nil
}

func (dScanner *DebrickedScanner) getDebrickedConfig(path string, exclusions []string) upload.DebrickedConfig {
configPath := dScanner.finder.GetConfigPath(path, exclusions)
func (dScanner *DebrickedScanner) getDebrickedConfig(path string, exclusions []string, inclusions []string) upload.DebrickedConfig {
configPath := dScanner.finder.GetConfigPath(path, exclusions, inclusions)
if configPath == "" {
return upload.DebrickedConfig{}
}
Expand Down

0 comments on commit 99ec89b

Please sign in to comment.