Skip to content

Commit

Permalink
chore(alpm): remove support for pacman 5
Browse files Browse the repository at this point in the history
  • Loading branch information
Jguer committed Jul 3, 2021
1 parent 0ad3134 commit 1e98d80
Show file tree
Hide file tree
Showing 14 changed files with 103 additions and 308 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ LDFLAGS := $(LDFLAGS)
GO ?= go

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

.PHONY: default
default: build
Expand Down
6 changes: 1 addition & 5 deletions callbacks_six.c → callbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
//
// MIT Licensed. See LICENSE for details.

#if SIX

#include <stdint.h>
#include <stdio.h>
#include <stdarg.h>
#include "callbacks_six.h"
#include "callbacks.h"

typedef struct {
void *go_cb;
Expand Down Expand Up @@ -58,5 +56,3 @@ void go_alpm_set_question_callback(alpm_handle_t *handle, void *go_cb, go_ctx_t
ctx = alloc_ctx(ctx, *(void**)go_cb, go_ctx);
alpm_option_set_questioncb(handle, _question_cb, ctx);
}

#endif
59 changes: 59 additions & 0 deletions callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,63 @@

package alpm

/*
#include "callbacks.h"
*/
import "C"
import "unsafe"

var DefaultLogLevel = LogWarning

type (
logCallbackSig func(interface{}, LogLevel, string)
questionCallbackSig func(interface{}, QuestionAny)
callbackContextPool map[C.go_ctx_t]interface{}
)

var (
logCallbackContextPool callbackContextPool = callbackContextPool{}
questionCallbackContextPool callbackContextPool = callbackContextPool{}
)

func DefaultLogCallback(ctx interface{}, lvl LogLevel, s string) {
if lvl <= DefaultLogLevel {
print("go-alpm: ", s)
}
}

//export go_alpm_go_log_callback
func go_alpm_go_log_callback(go_cb unsafe.Pointer, go_ctx C.go_ctx_t, lvl C.alpm_loglevel_t, s *C.char) {
cb := *(*logCallbackSig)(go_cb)
ctx := logCallbackContextPool[go_ctx]

cb(ctx, LogLevel(lvl), C.GoString(s))
}

//export go_alpm_go_question_callback
func go_alpm_go_question_callback(go_cb unsafe.Pointer, go_ctx C.go_ctx_t, question *C.alpm_question_t) {
q := (*C.alpm_question_any_t)(unsafe.Pointer(question))

cb := *(*questionCallbackSig)(go_cb)
ctx := questionCallbackContextPool[go_ctx]

cb(ctx, QuestionAny{q})
}

func (h *Handle) SetLogCallback(cb logCallbackSig, ctx interface{}) {
go_cb := unsafe.Pointer(&cb)
go_ctx := C.go_ctx_t(h.ptr)

logCallbackContextPool[go_ctx] = ctx

C.go_alpm_set_log_callback(h.ptr, go_cb, go_ctx)
}

func (h *Handle) SetQuestionCallback(cb questionCallbackSig, ctx interface{}) {
go_cb := unsafe.Pointer(&cb)
go_ctx := C.go_ctx_t(h.ptr)

questionCallbackContextPool[go_ctx] = ctx

C.go_alpm_set_question_callback(h.ptr, go_cb, go_ctx)
}
4 changes: 0 additions & 4 deletions callbacks_six.h → callbacks.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#if SIX

#include <alpm.h>

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

void go_alpm_set_log_callback(alpm_handle_t *handle, void *go_cb, go_ctx_t go_ctx);
void go_alpm_set_question_callback(alpm_handle_t *handle, void *go_cb, go_ctx_t go_ctx);

#endif
43 changes: 0 additions & 43 deletions callbacks_five.c

This file was deleted.

52 changes: 0 additions & 52 deletions callbacks_five.go

This file was deleted.

66 changes: 0 additions & 66 deletions callbacks_six.go

This file was deleted.

2 changes: 0 additions & 2 deletions callbacks_six_test.go → callbacks_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// +build six

package alpm

import (
Expand Down
19 changes: 19 additions & 0 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,22 @@ func (db *DB) PkgCache() IPackageList {
pkgcache := (*list)(unsafe.Pointer(C.alpm_db_get_pkgcache(db.ptr)))
return PackageList{pkgcache, db.handle}
}

// Search returns a list of packages matching the targets.
// In case of error the Package List will be nil
func (db *DB) Search(targets []string) IPackageList {
var needles *C.alpm_list_t = nil
var ret *C.alpm_list_t = nil

for _, str := range targets {
needles = C.alpm_list_add(needles, unsafe.Pointer(C.CString(str)))
}

ok := C.alpm_db_search(db.ptr, needles, &ret)
if ok != 0 {
return PackageList{nil, db.handle}
}

C.alpm_list_free(needles)
return PackageList{(*list)(unsafe.Pointer(ret)), db.handle}
}
30 changes: 0 additions & 30 deletions db_five.go

This file was deleted.

37 changes: 0 additions & 37 deletions db_six.go

This file was deleted.

24 changes: 24 additions & 0 deletions handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,3 +535,27 @@ func (h *Handle) SetRemoteFileSigLevel(siglevel SigLevel) error {
}
return nil
}

func (h *Handle) GetArchitectures() (StringList, error) {
return h.optionGetList(func(handle *C.alpm_handle_t) *C.alpm_list_t {
return C.alpm_option_get_architectures(handle)
})
}

func (h *Handle) SetArchitectures(str []string) error {
return h.optionSetList(str, func(handle *C.alpm_handle_t, l *C.alpm_list_t) C.int {
return C.alpm_option_set_architectures(handle, l)
})
}

func (h *Handle) AddArchitecture(str string) error {
return h.optionAddList(str, func(handle *C.alpm_handle_t, cStr *C.char) C.int {
return C.alpm_option_add_architecture(handle, cStr)
})
}

func (h *Handle) RemoveArchitecture(str string) (bool, error) {
return h.optionRemoveList(str, func(handle *C.alpm_handle_t, cStr *C.char) C.int {
return C.alpm_option_remove_architecture(handle, cStr)
})
}
Loading

0 comments on commit 1e98d80

Please sign in to comment.