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

fix: check overlapping paths separately for directories and contents #342

Closed
wants to merge 1 commit into from
Closed
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
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
Loading