Skip to content

Commit

Permalink
refactor: split slicer into steps and remove unnecessary state
Browse files Browse the repository at this point in the history
  • Loading branch information
letFunny committed Jun 4, 2024
1 parent a00ec09 commit 6b60e86
Show file tree
Hide file tree
Showing 6 changed files with 192 additions and 159 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/canonical/chisel

go 1.20
go 1.21

require (
github.com/blakesmith/ar v0.0.0-20190502131153-809d4375e1fb
Expand Down
2 changes: 1 addition & 1 deletion internal/deb/extract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ func (s *S) TestExtractCreateCallback(c *C) {
relPath = relPath + "/"
}
sort.Slice(extractInfos, func(i, j int) bool {
return strings.Compare(extractInfos[i].Path, extractInfos[j].Path) < 0
return extractInfos[i].Path < extractInfos[j].Path
})
createExtractInfos[relPath] = extractInfos
return nil
Expand Down
15 changes: 5 additions & 10 deletions internal/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"path"
"path/filepath"
"regexp"
"slices"
"strings"

"golang.org/x/crypto/openpgp/packet"
Expand Down Expand Up @@ -545,11 +546,8 @@ func parsePackage(baseDir, pkgName, pkgPath string, data []byte) (*Package, erro
// Do not add the slice to its own essentials list.
continue
}
// TODO replace with slices.Contains once it is stable.
for _, sk := range slice.Essential {
if sk == sliceKey {
return nil, fmt.Errorf("package %s defined with redundant essential slice: %s", pkgName, refName)
}
if slices.Contains(slice.Essential, sliceKey) {
return nil, fmt.Errorf("package %s defined with redundant essential slice: %s", pkgName, refName)
}
slice.Essential = append(slice.Essential, sliceKey)
}
Expand All @@ -561,11 +559,8 @@ func parsePackage(baseDir, pkgName, pkgPath string, data []byte) (*Package, erro
if sliceKey.Package == slice.Package && sliceKey.Slice == slice.Name {
return nil, fmt.Errorf("cannot add slice to itself as essential %q in %s", refName, pkgPath)
}
// TODO replace with slices.Contains once it is stable.
for _, sk := range slice.Essential {
if sk == sliceKey {
return nil, fmt.Errorf("slice %s defined with redundant essential slice: %s", slice, refName)
}
if slices.Contains(slice.Essential, sliceKey) {
return nil, fmt.Errorf("slice %s defined with redundant essential slice: %s", slice, refName)
}
slice.Essential = append(slice.Essential, sliceKey)
}
Expand Down
Loading

0 comments on commit 6b60e86

Please sign in to comment.