Skip to content

Commit 3581fc9

Browse files
authored
chore: remove libalpm13 support (#64)
* remove libalpm.so=13 support * fix build lint * fix lint error
1 parent e5b2e18 commit 3581fc9

File tree

13 files changed

+81
-256
lines changed

13 files changed

+81
-256
lines changed

.github/workflows/test-git.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
name: Build and test go-alpm
1616
runs-on: ubuntu-latest
1717
container:
18-
image: jguer/goalpm-builder:latest
18+
image: jguer/yay-builder:latest
1919
steps:
2020
- name: Checkout
2121
uses: actions/checkout@v2

.github/workflows/test.yml

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,11 @@ jobs:
1515
name: Build and test go-alpm
1616
runs-on: ubuntu-latest
1717
container:
18-
image: jguer/goalpm-builder:latest
18+
image: jguer/yay-builder:latest
1919
steps:
2020
- name: Checkout
2121
uses: actions/checkout@v2
2222
- name: Lint
2323
run: /app/bin/golangci-lint run ./...
2424
- name: Run Build and Tests
25-
run: make test
26-
- name: Build and install pacman-git
27-
run: |
28-
useradd github
29-
pacman -Sy --noconfirm --needed sudo base-devel git
30-
echo "github ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
31-
git clone https://aur.archlinux.org/pacman-git
32-
chown -R github pacman-git
33-
su github -c "cd pacman-git; yes | makepkg -si --nocheck"
34-
- name: Run Build and Tests with pacman-git
35-
run: make test
36-
25+
run: make test

.golangci.yml

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,42 +14,52 @@ linters-settings:
1414
- opinionated
1515
- performance
1616
- style
17-
disabled-checks:
18-
- dupImport
1917
gocyclo:
2018
min-complexity: 15
2119
goimports:
22-
local-prefixes: github.com/Jguer/go-alpm/v2
20+
local-prefixes: github.com/Jguer/yay/v12
2321
gomnd:
24-
settings:
25-
mnd:
26-
# don't include the "operation" and "assign"
27-
checks: argument,case,condition,return
28-
govet:
29-
check-shadowing: true
22+
checks:
23+
- argument
24+
- case
25+
- condition
26+
- return
27+
ignored-numbers:
28+
- "0"
29+
- "1"
30+
- "2"
31+
- "3"
32+
ignored-functions:
33+
- strings.SplitN
3034
lll:
3135
line-length: 140
32-
maligned:
33-
suggest-new: true
3436
misspell:
3537
locale: US
38+
nolintlint:
39+
allow-unused: false # report any unused nolint directives
40+
require-explanation: false # don't require an explanation for nolint directives
41+
require-specific: false # don't require nolint directives to be specific about which linter is being skipped
3642

3743
linters:
3844
# please, do not use `enable-all`: it's deprecated and will be removed soon.
3945
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
4046
disable-all: true
4147
enable:
48+
- forbidigo
4249
- bodyclose
43-
- depguard
4450
- dogsled
4551
- dupl
46-
- errcheck
4752
- errorlint
53+
- errcheck
4854
- exportloopref
55+
# - funlen # TOFIX
4956
- gochecknoinits
50-
- gocritic
57+
# - goconst # TOFIX
58+
# - gocritic
59+
# - gocyclo # TOFIX
5160
- gofmt
5261
- goimports
62+
# - gomnd # TOFIX
5363
- goprintffuncname
5464
- gosec
5565
- gosimple
@@ -69,10 +79,12 @@ linters:
6979
- whitespace
7080

7181
run:
82+
go: "1.22"
83+
timeout: "10m"
7284

7385
issues:
7486
exclude-rules:
75-
- path: _test\.go
87+
- path: (.+)_test.go
7688
linters:
7789
- lll
7890
- revive
@@ -84,6 +96,7 @@ issues:
8496
- dupl
8597
- gocritic
8698
- gochecknoinits
99+
- errorlint
87100

88101
exclude:
89102
- G204

callbacks_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"testing"
55

66
alpm "github.com/Jguer/go-alpm/v2"
7+
"github.com/stretchr/testify/require"
78
)
89

910
type Cnt struct {
@@ -27,7 +28,5 @@ func TestCallbacks(t *testing.T) {
2728

2829
h.Release()
2930

30-
if cnt.cnt != 1 {
31-
panic(nil)
32-
}
31+
require.Equal(t, 1, cnt.cnt)
3332
}

db.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ func (db *DB) Search(targets []string) IPackageList {
197197
needles = C.alpm_list_add(needles, unsafe.Pointer(C.CString(str)))
198198
}
199199

200-
ok := C.alpm_db_search(db.ptr, needles, &ret) //nolint
200+
ok := C.alpm_db_search(db.ptr, needles, &ret)
201201
if ok != 0 {
202202
return PackageList{nil, db.handle}
203203
}
@@ -206,3 +206,15 @@ func (db *DB) Search(targets []string) IPackageList {
206206

207207
return PackageList{(*list)(unsafe.Pointer(ret)), db.handle}
208208
}
209+
210+
// PkgCachebyGroup returns a PackageList of packages belonging to a group
211+
func (l DBList) FindGroupPkgs(name string) IPackageList {
212+
cName := C.CString(name)
213+
214+
defer C.free(unsafe.Pointer(cName))
215+
216+
pkglist := (*C.struct__alpm_list_t)(unsafe.Pointer(l.list))
217+
pkgcache := (*list)(unsafe.Pointer(C.alpm_find_group_pkgs(pkglist, cName)))
218+
219+
return PackageList{pkgcache, l.handle}
220+
}

db_git.go

Lines changed: 0 additions & 32 deletions
This file was deleted.

db_six.go

Lines changed: 0 additions & 32 deletions
This file was deleted.

deps.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
//go:build !next
2-
// +build !next
3-
41
package alpm
52

63
/*
@@ -20,8 +17,8 @@ func (l DBList) FindSatisfier(depstring string) (IPackage, error) {
2017

2118
defer C.free(unsafe.Pointer(cDepString))
2219

23-
pkgList := (*C.struct___alpm_list_t)(unsafe.Pointer(l.list))
24-
pkgHandle := (*C.struct___alpm_handle_t)(unsafe.Pointer(l.handle.ptr))
20+
pkgList := (*C.struct__alpm_list_t)(unsafe.Pointer(l.list))
21+
pkgHandle := (*C.struct__alpm_handle_t)(unsafe.Pointer(l.handle.ptr))
2522

2623
ptr := C.alpm_find_dbs_satisfier(pkgHandle, pkgList, cDepString)
2724
if ptr == nil {
@@ -38,7 +35,7 @@ func (l PackageList) FindSatisfier(depstring string) (IPackage, error) {
3835

3936
defer C.free(unsafe.Pointer(cDepString))
4037

41-
pkgList := (*C.struct___alpm_list_t)(unsafe.Pointer(l.list))
38+
pkgList := (*C.struct__alpm_list_t)(unsafe.Pointer(l.list))
4239

4340
ptr := C.alpm_find_satisfier(pkgList, cDepString)
4441
if ptr == nil {

deps_git.go

Lines changed: 0 additions & 50 deletions
This file was deleted.

package.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,21 @@ package alpm
88

99
/*
1010
#include <alpm.h>
11+
12+
int pkg_cmp(const void *v1, const void *v2)
13+
{
14+
alpm_pkg_t *p1 = (alpm_pkg_t *)v1;
15+
alpm_pkg_t *p2 = (alpm_pkg_t *)v2;
16+
off_t s1 = alpm_pkg_get_isize(p1);
17+
off_t s2 = alpm_pkg_get_isize(p2);
18+
19+
if (s1 > s2)
20+
return -1;
21+
else if (s1 < s2)
22+
return 1;
23+
else
24+
return 0;
25+
}
1126
*/
1227
import "C"
1328

@@ -287,3 +302,18 @@ func (pkg *Package) ShouldIgnore() bool {
287302
func (pkg *Package) Type() string {
288303
return "alpm"
289304
}
305+
306+
// SortBySize returns a PackageList sorted by size.
307+
func (l PackageList) SortBySize() IPackageList {
308+
pkgList := (*C.struct__alpm_list_t)(unsafe.Pointer(l.list))
309+
310+
pkgCache := (*list)(unsafe.Pointer(
311+
C.alpm_list_msort(pkgList, //nolint
312+
C.alpm_list_count(pkgList),
313+
C.alpm_list_fn_cmp(C.pkg_cmp))))
314+
if pkgCache == nil {
315+
return nil
316+
}
317+
318+
return PackageList{pkgCache, l.handle}
319+
}

0 commit comments

Comments
 (0)