Skip to content

Commit

Permalink
make compatible with go 1.19
Browse files Browse the repository at this point in the history
  • Loading branch information
neolynx committed Jul 31, 2024
1 parent c8920b2 commit 0c066e2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
BOTO_CONFIG: /dev/null
GO111MODULE: "on"
GOPROXY: "https://proxy.golang.org"
GOVER: '1.21'
GOVER: '1.19'

steps:
- name: Checkout repository
Expand Down Expand Up @@ -100,7 +100,7 @@ jobs:
- name: Ubuntu-20
image: "ubuntu:20.04"
suite: focal
GOVER: '1.21'
GOVER: '1.19'
install: "make ca-certificates git curl"
- name: Ubuntu-22
image: "ubuntu:22.04"
Expand All @@ -109,12 +109,12 @@ jobs:
- name: Debian-10
image: "debian:buster"
suite: buster
GOVER: '1.21'
GOVER: '1.19'
install: "make ca-certificates git curl"
- name: Debian-11
image: "debian:bullseye"
suite: bullseye
GOVER: '1.21'
GOVER: '1.19'
install: "make ca-certificates git curl"
- name: Debian-12
image: "debian:bookworm"
Expand Down
32 changes: 26 additions & 6 deletions deb/reflist.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,10 @@ func bucketRefPrefix(ref []byte) []byte {
ref = ref[len(libPrefix):]
}

prefixLen := min(maxPrefixLen, len(ref))
prefixLen := len(ref)
if maxPrefixLen < prefixLen {
prefixLen = maxPrefixLen
}
prefix, _, _ := bytes.Cut(ref[:prefixLen], []byte{' '})
return prefix
}
Expand Down Expand Up @@ -715,9 +718,16 @@ func (set *RefListDigestSet) ForEach(handler func(digest []byte) error) error {
return nil
}

// workaround for: conversion of slices to arrays requires go1.20 or later
func newRefListArray(digest []byte) reflistDigestArray {
var array reflistDigestArray
copy(array[:], digest)
return array
}

// Add adds digest to set, doing nothing if the digest was already present
func (set *RefListDigestSet) Add(digest []byte) {
set.items[reflistDigestArray(digest)] = struct{}{}
set.items[newRefListArray(digest)] = struct{}{}
}

// AddAllInRefList adds all the bucket digests in a SplitRefList to the set
Expand All @@ -731,13 +741,13 @@ func (set *RefListDigestSet) AddAllInRefList(sl *SplitRefList) {

// Has checks whether a digest is part of set
func (set *RefListDigestSet) Has(digest []byte) bool {
_, ok := set.items[reflistDigestArray(digest)]
_, ok := set.items[newRefListArray(digest)]
return ok
}

// Remove removes a digest from set
func (set *RefListDigestSet) Remove(digest []byte) {
delete(set.items, reflistDigestArray(digest))
delete(set.items, newRefListArray(digest))
}

// RemoveAll removes all the digests in other from the current set
Expand Down Expand Up @@ -776,10 +786,20 @@ func segmentPrefix(encodedDigest string) []byte {
return []byte(fmt.Sprintf("F%s-", encodedDigest))
}

// workaround for go 1.19 instead of bytes.Clone
func cloneBytes(b []byte) []byte {
if b == nil {
return nil
}
cloned := make([]byte, len(b))
copy(cloned, b)
return cloned
}

func segmentIndexKey(prefix []byte, idx int) []byte {
// Assume most buckets won't have more than 0xFFFF = ~65k segments (which
// would be an extremely large bucket!).
return append(bytes.Clone(prefix), []byte(fmt.Sprintf("%04x", idx))...)
return append(cloneBytes(prefix), []byte(fmt.Sprintf("%04x", idx))...)
}

// AllBucketDigests returns a set of all the bucket digests in the database
Expand Down Expand Up @@ -861,7 +881,7 @@ func (collection *RefListCollection) loadBuckets(sl *SplitRefList) error {
var bucket *PackageRefList

if digest := sl.Buckets[idx]; len(digest) > 0 {
cacheKey := reflistDigestArray(digest)
cacheKey := newRefListArray(digest)
bucket = collection.cache[cacheKey]
if bucket == nil {
bucket = NewPackageRefList()
Expand Down
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/aptly-dev/aptly

go 1.21
go 1.19

require (
github.com/AlekSi/pointer v1.2.0
Expand Down

0 comments on commit 0c066e2

Please sign in to comment.