Skip to content

Commit 1e98d80

Browse files
committed
chore(alpm): remove support for pacman 5
1 parent 0ad3134 commit 1e98d80

14 files changed

+103
-308
lines changed

Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ LDFLAGS := $(LDFLAGS)
66
GO ?= go
77

88
SOURCES ?= $(shell find . -name "*.go")
9-
GOFLAGS += $(shell pacman -T 'pacman>6' && echo "-tags six")
109

1110
.PHONY: default
1211
default: build

callbacks_six.c renamed to callbacks.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44
//
55
// MIT Licensed. See LICENSE for details.
66

7-
#if SIX
8-
97
#include <stdint.h>
108
#include <stdio.h>
119
#include <stdarg.h>
12-
#include "callbacks_six.h"
10+
#include "callbacks.h"
1311

1412
typedef struct {
1513
void *go_cb;
@@ -58,5 +56,3 @@ void go_alpm_set_question_callback(alpm_handle_t *handle, void *go_cb, go_ctx_t
5856
ctx = alloc_ctx(ctx, *(void**)go_cb, go_ctx);
5957
alpm_option_set_questioncb(handle, _question_cb, ctx);
6058
}
61-
62-
#endif

callbacks.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,63 @@
66

77
package alpm
88

9+
/*
10+
#include "callbacks.h"
11+
*/
12+
import "C"
13+
import "unsafe"
14+
915
var DefaultLogLevel = LogWarning
16+
17+
type (
18+
logCallbackSig func(interface{}, LogLevel, string)
19+
questionCallbackSig func(interface{}, QuestionAny)
20+
callbackContextPool map[C.go_ctx_t]interface{}
21+
)
22+
23+
var (
24+
logCallbackContextPool callbackContextPool = callbackContextPool{}
25+
questionCallbackContextPool callbackContextPool = callbackContextPool{}
26+
)
27+
28+
func DefaultLogCallback(ctx interface{}, lvl LogLevel, s string) {
29+
if lvl <= DefaultLogLevel {
30+
print("go-alpm: ", s)
31+
}
32+
}
33+
34+
//export go_alpm_go_log_callback
35+
func go_alpm_go_log_callback(go_cb unsafe.Pointer, go_ctx C.go_ctx_t, lvl C.alpm_loglevel_t, s *C.char) {
36+
cb := *(*logCallbackSig)(go_cb)
37+
ctx := logCallbackContextPool[go_ctx]
38+
39+
cb(ctx, LogLevel(lvl), C.GoString(s))
40+
}
41+
42+
//export go_alpm_go_question_callback
43+
func go_alpm_go_question_callback(go_cb unsafe.Pointer, go_ctx C.go_ctx_t, question *C.alpm_question_t) {
44+
q := (*C.alpm_question_any_t)(unsafe.Pointer(question))
45+
46+
cb := *(*questionCallbackSig)(go_cb)
47+
ctx := questionCallbackContextPool[go_ctx]
48+
49+
cb(ctx, QuestionAny{q})
50+
}
51+
52+
func (h *Handle) SetLogCallback(cb logCallbackSig, ctx interface{}) {
53+
go_cb := unsafe.Pointer(&cb)
54+
go_ctx := C.go_ctx_t(h.ptr)
55+
56+
logCallbackContextPool[go_ctx] = ctx
57+
58+
C.go_alpm_set_log_callback(h.ptr, go_cb, go_ctx)
59+
}
60+
61+
func (h *Handle) SetQuestionCallback(cb questionCallbackSig, ctx interface{}) {
62+
go_cb := unsafe.Pointer(&cb)
63+
go_ctx := C.go_ctx_t(h.ptr)
64+
65+
questionCallbackContextPool[go_ctx] = ctx
66+
67+
C.go_alpm_set_question_callback(h.ptr, go_cb, go_ctx)
68+
}
Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#if SIX
2-
31
#include <alpm.h>
42

53
typedef void *go_ctx_t;
@@ -9,5 +7,3 @@ void go_alpm_go_question_callback(void *go_cb, go_ctx_t go_ctx, alpm_question_t
97

108
void go_alpm_set_log_callback(alpm_handle_t *handle, void *go_cb, go_ctx_t go_ctx);
119
void go_alpm_set_question_callback(alpm_handle_t *handle, void *go_cb, go_ctx_t go_ctx);
12-
13-
#endif

callbacks_five.c

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

callbacks_five.go

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

callbacks_six.go

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

callbacks_six_test.go renamed to callbacks_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// +build six
2-
31
package alpm
42

53
import (

db.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,22 @@ func (db *DB) PkgCache() IPackageList {
154154
pkgcache := (*list)(unsafe.Pointer(C.alpm_db_get_pkgcache(db.ptr)))
155155
return PackageList{pkgcache, db.handle}
156156
}
157+
158+
// Search returns a list of packages matching the targets.
159+
// In case of error the Package List will be nil
160+
func (db *DB) Search(targets []string) IPackageList {
161+
var needles *C.alpm_list_t = nil
162+
var ret *C.alpm_list_t = nil
163+
164+
for _, str := range targets {
165+
needles = C.alpm_list_add(needles, unsafe.Pointer(C.CString(str)))
166+
}
167+
168+
ok := C.alpm_db_search(db.ptr, needles, &ret)
169+
if ok != 0 {
170+
return PackageList{nil, db.handle}
171+
}
172+
173+
C.alpm_list_free(needles)
174+
return PackageList{(*list)(unsafe.Pointer(ret)), db.handle}
175+
}

db_five.go

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

0 commit comments

Comments
 (0)