Skip to content

Commit

Permalink
last version of the conflict resolution algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
letFunny committed Aug 20, 2024
1 parent 8fa3b3d commit b06fdd1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 36 deletions.
59 changes: 24 additions & 35 deletions internal/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,55 +163,44 @@ func (r *Release) validate() error {
// The above also means that generated content (e.g. text files, directories
// with make:true) will always conflict with extracted content, because we
// cannot validate that they are the same without downloading the package.
type sliceAndInfo struct {
slice *Slice
info PathInfo
}
allPaths := make(map[string]sliceAndInfo)
paths := make(map[string]*Slice)
for _, pkg := range r.Packages {
for _, new := range pkg.Slices {
keys = append(keys, SliceKey{pkg.Name, new.Name})
for newPath, newInfo := range new.Contents {
if p, ok := allPaths[newPath]; ok {
old := p.slice
// Check if the same path is listed twice.
if old, ok := paths[newPath]; ok {
oldInfo := old.Contents[newPath]
if !newInfo.SameContent(&oldInfo) || (newInfo.Kind == CopyPath || newInfo.Kind == GlobPath) && new.Package != old.Package {
if old.Package > new.Package || old.Package == new.Package && old.Name > new.Name {
old, new = new, old
}
return fmt.Errorf("slices %s and %s conflict on %s", old, new, newPath)
}
} else {
allPaths[newPath] = sliceAndInfo{
slice: new,
info: newInfo,
}
}
}
}
}
for newPath, new := range allPaths {
for oldPath, old := range allPaths {
if oldPath == newPath {
// Same path means same entry by construction.
continue
}
// We are only using the outer loop values so that we do not check
// for conflicts twice.
if new.info.Kind != GlobPath && new.info.Kind != GeneratePath {
continue
}
if new.info.Kind == GlobPath && (old.info.Kind == GlobPath || old.info.Kind == CopyPath) {
if new.slice.Package == old.slice.Package {
continue
}
}
if strdist.GlobPath(newPath, oldPath) {
if (old.slice.Package > new.slice.Package) || (old.slice.Package == new.slice.Package && old.slice.Name > new.slice.Name) {
old, new = new, old
oldPath, newPath = newPath, oldPath
// Check for glob and generate conflicts.
for oldPath, old := range paths {
oldInfo := old.Contents[oldPath]
if !(newInfo.Kind == GlobPath || newInfo.Kind == GeneratePath ||
oldInfo.Kind == GlobPath || oldInfo.Kind == GeneratePath) {
continue
}
if (newInfo.Kind == GlobPath || newInfo.Kind == CopyPath) &&
(oldInfo.Kind == GlobPath || oldInfo.Kind == CopyPath) {
if new.Package == old.Package {
continue
}
}
if strdist.GlobPath(newPath, oldPath) {
if (old.Package > new.Package) || (old.Package == new.Package && old.Name > new.Name) {
old, new = new, old
oldPath, newPath = newPath, oldPath
}
return fmt.Errorf("slices %s and %s conflict on %s and %s", old, new, oldPath, newPath)
}
}
return fmt.Errorf("slices %s and %s conflict on %s and %s", old.slice, new.slice, oldPath, newPath)
paths[newPath] = new
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/setup/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1518,7 +1518,7 @@ var setupTests = []setupTest{{
/path/file:
`,
},
relerror: `slices mypkg_myslice and mypkg_myslice conflict on /path/file and /path/\*\*`,
relerror: `slices mypkg_myslice and mypkg_myslice conflict on /path/\*\* and /path/file`,
}, {
summary: "Generate paths cannot conflict with any other path across slices",
input: map[string]string{
Expand Down

0 comments on commit b06fdd1

Please sign in to comment.