Skip to content

Commit

Permalink
fix: check overlapping paths separately for directories and contents
Browse files Browse the repository at this point in the history
Signed-off-by: German Lashevich <[email protected]>
  • Loading branch information
Zebradil committed Dec 24, 2023
1 parent 217399e commit 0a6abbd
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions pkg/vendir/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (
"reflect"
"strings"

"carvel.dev/vendir/pkg/vendir/version"
semver "github.com/hashicorp/go-version"
"sigs.k8s.io/yaml"

"carvel.dev/vendir/pkg/vendir/version"
)

const (
Expand Down Expand Up @@ -259,20 +260,34 @@ func (c Config) Lock(lockConfig LockConfig) error {
}

func (c Config) checkOverlappingPaths() error {
checkPaths := func(paths []string) error {
for i, path := range paths {
for i2, path2 := range paths {
if i != i2 && strings.HasPrefix(path2+string(filepath.Separator), path+string(filepath.Separator)) {
return fmt.Errorf("Expected to not manage overlapping paths: '%s' and '%s'", path2, path)
}
}
}
return nil
}

paths := []string{}
for _, dir := range c.Directories {
paths = append(paths, dir.Path)
}

if err := checkPaths(paths); err != nil {
return err
}

for _, dir := range c.Directories {
for _, con := range dir.Contents {
paths = append(paths, filepath.Join(dir.Path, con.Path))
paths = []string{}
for _, cont := range dir.Contents {
paths = append(paths, filepath.Join(dir.Path, cont.Path))
}
}

for i, path := range paths {
for i2, path2 := range paths {
if i != i2 && strings.HasPrefix(path2+string(filepath.Separator), path+string(filepath.Separator)) {
return fmt.Errorf("Expected to not "+
"manage overlapping paths: '%s' and '%s'", path2, path)
}
if err := checkPaths(paths); err != nil {
return err
}
}

Expand Down

0 comments on commit 0a6abbd

Please sign in to comment.