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 Jun 17, 2024
1 parent 7e8f254 commit 6e5b3fd
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 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 @@ -99,7 +99,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 @@ -108,12 +108,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
}

Check warning on line 793 in deb/reflist.go

View check run for this annotation

Codecov / codecov/patch

deb/reflist.go#L792-L793

Added lines #L792 - L793 were not covered by tests
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
4 changes: 2 additions & 2 deletions system/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ FROM debian:bookworm-slim

RUN apt-get update -y && apt-get install -y --no-install-recommends curl gnupg && apt-get clean && rm -rf /var/lib/apt/lists/*

RUN echo deb http://deb.debian.org/debian bookworm-backports main > /etc/apt/sources.list.d/backports.list
#RUN echo deb http://deb.debian.org/debian bookworm-backports main > /etc/apt/sources.list.d/backports.list
RUN apt-get update && \
apt-get install -y --no-install-recommends apg bzip2 xz-utils ca-certificates golang/bookworm-backports golang-go/bookworm-backports golang-doc/bookworm-backports golang-src/bookworm-backports make git python3 python3-requests-unixsocket python3-termcolor python3-swiftclient python3-boto && \
apt-get install -y --no-install-recommends apg bzip2 xz-utils ca-certificates golang golang-go golang-doc golang-src make git python3 python3-requests-unixsocket python3-termcolor python3-swiftclient python3-boto g++ && \
apt-get clean && rm -rf /var/lib/apt/lists/*

RUN useradd -m --shell /bin/sh --home-dir /var/lib/aptly aptly
Expand Down

0 comments on commit 6e5b3fd

Please sign in to comment.