2017-07-14 19:03:54 +02:00
|
|
|
// handle.go - libalpm handle type and methods.
|
|
|
|
//
|
|
|
|
// Copyright (c) 2013 The go-alpm Authors
|
|
|
|
//
|
|
|
|
// MIT Licensed. See LICENSE for details.
|
|
|
|
|
|
|
|
// Package alpm implements Go bindings to the libalpm library used by Pacman,
|
|
|
|
// the Arch Linux package manager. Libalpm allows the creation of custom front
|
|
|
|
// ends to the Arch Linux package ecosystem.
|
|
|
|
//
|
|
|
|
// Libalpm does not include support for the Arch User Repository (AUR).
|
|
|
|
package alpm
|
|
|
|
|
|
|
|
// #include <alpm.h>
|
2018-01-14 18:21:50 +01:00
|
|
|
// #include <stdio.h> //C.free
|
|
|
|
// #include <fnmatch.h> //C.FNM_NOMATCH
|
2017-07-14 19:03:54 +02:00
|
|
|
import "C"
|
|
|
|
|
|
|
|
import (
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
2018-09-14 02:29:33 +02:00
|
|
|
// Handle contains the pointer to the alpm handle
|
2017-07-14 19:03:54 +02:00
|
|
|
type Handle struct {
|
|
|
|
ptr *C.alpm_handle_t
|
|
|
|
}
|
|
|
|
|
2018-01-14 18:21:50 +01:00
|
|
|
//
|
|
|
|
//alpm options getters and setters
|
|
|
|
//
|
|
|
|
|
|
|
|
//helper functions for wrapping list_t getters and setters
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) optionGetList(f func(*C.alpm_handle_t) *C.alpm_list_t) (StringList, error) {
|
2018-01-14 18:21:50 +01:00
|
|
|
alpmList := f(h.ptr)
|
|
|
|
goList := StringList{(*list)(unsafe.Pointer(alpmList))}
|
|
|
|
|
|
|
|
if alpmList == nil {
|
|
|
|
return goList, h.LastError()
|
|
|
|
}
|
|
|
|
return goList, nil
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) optionSetList(hookDirs []string, f func(*C.alpm_handle_t, *C.alpm_list_t) C.int) error {
|
2018-09-14 02:29:33 +02:00
|
|
|
var list *C.alpm_list_t
|
2018-01-14 18:21:50 +01:00
|
|
|
|
|
|
|
for _, dir := range hookDirs {
|
2018-09-14 02:29:33 +02:00
|
|
|
cDir := C.CString(dir)
|
|
|
|
list = C.alpm_list_add(list, unsafe.Pointer(cDir))
|
|
|
|
defer C.free(unsafe.Pointer(cDir))
|
2018-01-14 18:21:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ok := f(h.ptr, list)
|
|
|
|
if ok < 0 {
|
|
|
|
return h.LastError()
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) optionAddList(hookDir string, f func(*C.alpm_handle_t, *C.char) C.int) error {
|
2018-09-14 02:29:33 +02:00
|
|
|
cHookDir := C.CString(hookDir)
|
|
|
|
defer C.free(unsafe.Pointer(cHookDir))
|
|
|
|
ok := f(h.ptr, cHookDir)
|
2018-01-14 18:21:50 +01:00
|
|
|
if ok < 0 {
|
|
|
|
return h.LastError()
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) optionRemoveList(dir string, f func(*C.alpm_handle_t, *C.char) C.int) (bool, error) {
|
2018-09-14 02:29:33 +02:00
|
|
|
cDir := C.CString(dir)
|
|
|
|
ok := f(h.ptr, cDir)
|
|
|
|
defer C.free(unsafe.Pointer(cDir))
|
2018-01-14 18:21:50 +01:00
|
|
|
if ok < 0 {
|
|
|
|
return ok == 1, h.LastError()
|
|
|
|
}
|
|
|
|
return ok == 1, nil
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) optionMatchList(dir string, f func(*C.alpm_handle_t, *C.char) C.int) (bool, error) {
|
2018-09-14 02:29:33 +02:00
|
|
|
cDir := C.CString(dir)
|
|
|
|
ok := f(h.ptr, cDir)
|
|
|
|
defer C.free(unsafe.Pointer(cDir))
|
2018-01-14 18:21:50 +01:00
|
|
|
if ok == 0 {
|
|
|
|
return true, nil
|
|
|
|
} else if ok == C.FNM_NOMATCH {
|
|
|
|
return false, h.LastError()
|
|
|
|
}
|
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
//helper functions for *char based getters and setters
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) optionGetStr(f func(*C.alpm_handle_t) *C.char) (string, error) {
|
2018-09-14 02:29:33 +02:00
|
|
|
cStr := f(h.ptr)
|
|
|
|
str := C.GoString(cStr)
|
|
|
|
if cStr == nil {
|
2018-01-14 18:21:50 +01:00
|
|
|
return str, h.LastError()
|
|
|
|
}
|
|
|
|
|
|
|
|
return str, nil
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) optionSetStr(str string, f func(*C.alpm_handle_t, *C.char) C.int) error {
|
2018-09-14 02:29:33 +02:00
|
|
|
cStr := C.CString(str)
|
|
|
|
defer C.free(unsafe.Pointer(cStr))
|
|
|
|
ok := f(h.ptr, cStr)
|
2018-01-14 18:21:50 +01:00
|
|
|
|
|
|
|
if ok < 0 {
|
2018-03-20 08:54:58 +01:00
|
|
|
h.LastError()
|
2018-01-14 18:21:50 +01:00
|
|
|
}
|
2018-03-20 08:54:58 +01:00
|
|
|
return nil
|
2018-01-14 18:21:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
//end of helpers
|
|
|
|
//
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) Root() (string, error) {
|
2018-01-14 18:21:50 +01:00
|
|
|
return h.optionGetStr(func(handle *C.alpm_handle_t) *C.char {
|
|
|
|
return C.alpm_option_get_root(handle)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) DBPath() (string, error) {
|
2018-01-14 18:21:50 +01:00
|
|
|
return h.optionGetStr(func(handle *C.alpm_handle_t) *C.char {
|
|
|
|
return C.alpm_option_get_dbpath(handle)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) Lockfile() (string, error) {
|
2018-01-14 18:21:50 +01:00
|
|
|
return h.optionGetStr(func(handle *C.alpm_handle_t) *C.char {
|
|
|
|
return C.alpm_option_get_lockfile(handle)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) CacheDirs() (StringList, error) {
|
2018-01-14 18:21:50 +01:00
|
|
|
return h.optionGetList(func(handle *C.alpm_handle_t) *C.alpm_list_t {
|
|
|
|
return C.alpm_option_get_cachedirs(handle)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) AddCacheDir(hookDir string) error {
|
2018-01-14 18:21:50 +01:00
|
|
|
return h.optionAddList(hookDir, func(handle *C.alpm_handle_t, str *C.char) C.int {
|
|
|
|
return C.alpm_option_add_cachedir(handle, str)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) SetCacheDirs(hookDirs []string) error {
|
2018-01-14 18:21:50 +01:00
|
|
|
return h.optionSetList(hookDirs, func(handle *C.alpm_handle_t, l *C.alpm_list_t) C.int {
|
|
|
|
return C.alpm_option_set_cachedirs(handle, l)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) RemoveCacheDir(dir string) (bool, error) {
|
2018-01-14 18:21:50 +01:00
|
|
|
return h.optionRemoveList(dir, func(handle *C.alpm_handle_t, str *C.char) C.int {
|
|
|
|
return C.alpm_option_remove_cachedir(handle, str)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) HookDirs() (StringList, error) {
|
2018-01-14 18:21:50 +01:00
|
|
|
return h.optionGetList(func(handle *C.alpm_handle_t) *C.alpm_list_t {
|
|
|
|
return C.alpm_option_get_hookdirs(handle)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) AddHookDir(hookDir string) error {
|
2018-01-14 18:21:50 +01:00
|
|
|
return h.optionAddList(hookDir, func(handle *C.alpm_handle_t, str *C.char) C.int {
|
|
|
|
return C.alpm_option_add_hookdir(handle, str)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) SetHookDirs(hookDirs []string) error {
|
2018-01-14 18:21:50 +01:00
|
|
|
return h.optionSetList(hookDirs, func(handle *C.alpm_handle_t, l *C.alpm_list_t) C.int {
|
|
|
|
return C.alpm_option_set_hookdirs(handle, l)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) RemoveHookDir(dir string) (bool, error) {
|
2018-01-14 18:21:50 +01:00
|
|
|
return h.optionRemoveList(dir, func(handle *C.alpm_handle_t, str *C.char) C.int {
|
|
|
|
return C.alpm_option_remove_hookdir(handle, str)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) LogFile() (string, error) {
|
2018-01-14 18:21:50 +01:00
|
|
|
return h.optionGetStr(func(handle *C.alpm_handle_t) *C.char {
|
|
|
|
return C.alpm_option_get_logfile(handle)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) SetLogFile(str string) error {
|
2018-01-14 18:21:50 +01:00
|
|
|
return h.optionSetStr(str, func(handle *C.alpm_handle_t, c_str *C.char) C.int {
|
|
|
|
return C.alpm_option_set_logfile(handle, c_str)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) GPGDir() (string, error) {
|
2018-01-14 18:21:50 +01:00
|
|
|
return h.optionGetStr(func(handle *C.alpm_handle_t) *C.char {
|
|
|
|
return C.alpm_option_get_gpgdir(handle)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) SetGPGDir(str string) error {
|
2018-01-14 18:21:50 +01:00
|
|
|
return h.optionSetStr(str, func(handle *C.alpm_handle_t, c_str *C.char) C.int {
|
|
|
|
return C.alpm_option_set_gpgdir(handle, c_str)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) UseSyslog() (bool, error) {
|
2018-01-14 18:21:50 +01:00
|
|
|
ok := C.alpm_option_get_usesyslog(h.ptr)
|
|
|
|
b := false
|
|
|
|
|
|
|
|
if ok > 0 {
|
|
|
|
b = true
|
|
|
|
}
|
|
|
|
if ok < 0 {
|
|
|
|
return b, h.LastError()
|
|
|
|
}
|
|
|
|
return b, nil
|
2017-07-14 19:03:54 +02:00
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) SetUseSyslog(value bool) error {
|
2018-09-14 02:29:33 +02:00
|
|
|
var intValue C.int
|
2017-07-14 19:03:54 +02:00
|
|
|
if value {
|
2018-09-14 02:29:33 +02:00
|
|
|
intValue = 1
|
2017-07-14 19:03:54 +02:00
|
|
|
}
|
2018-01-14 18:21:50 +01:00
|
|
|
|
2018-09-14 02:29:33 +02:00
|
|
|
ok := C.alpm_option_set_usesyslog(h.ptr, intValue)
|
2017-07-14 19:03:54 +02:00
|
|
|
if ok < 0 {
|
|
|
|
return h.LastError()
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2018-01-14 18:21:50 +01:00
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) NoUpgrades() (StringList, error) {
|
2018-01-14 18:21:50 +01:00
|
|
|
return h.optionGetList(func(handle *C.alpm_handle_t) *C.alpm_list_t {
|
|
|
|
return C.alpm_option_get_noupgrades(handle)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) AddNoUpgrade(hookDir string) error {
|
2018-01-14 18:21:50 +01:00
|
|
|
return h.optionAddList(hookDir, func(handle *C.alpm_handle_t, str *C.char) C.int {
|
|
|
|
return C.alpm_option_add_noupgrade(handle, str)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) SetNoUpgrades(hookDirs []string) error {
|
2018-01-14 18:21:50 +01:00
|
|
|
return h.optionSetList(hookDirs, func(handle *C.alpm_handle_t, l *C.alpm_list_t) C.int {
|
|
|
|
return C.alpm_option_set_noupgrades(handle, l)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) RemoveNoUpgrade(dir string) (bool, error) {
|
2018-01-14 18:21:50 +01:00
|
|
|
return h.optionRemoveList(dir, func(handle *C.alpm_handle_t, str *C.char) C.int {
|
|
|
|
return C.alpm_option_remove_noupgrade(handle, str)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) MatchNoUpgrade(dir string) (bool, error) {
|
2018-01-14 18:21:50 +01:00
|
|
|
return h.optionMatchList(dir, func(handle *C.alpm_handle_t, str *C.char) C.int {
|
|
|
|
return C.alpm_option_match_noupgrade(handle, str)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) NoExtracts() (StringList, error) {
|
2018-01-14 18:21:50 +01:00
|
|
|
return h.optionGetList(func(handle *C.alpm_handle_t) *C.alpm_list_t {
|
|
|
|
return C.alpm_option_get_noextracts(handle)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) AddNoExtract(hookDir string) error {
|
2018-01-14 18:21:50 +01:00
|
|
|
return h.optionAddList(hookDir, func(handle *C.alpm_handle_t, str *C.char) C.int {
|
|
|
|
return C.alpm_option_add_noextract(handle, str)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) SetNoExtracts(hookDirs []string) error {
|
2018-01-14 18:21:50 +01:00
|
|
|
return h.optionSetList(hookDirs, func(handle *C.alpm_handle_t, l *C.alpm_list_t) C.int {
|
|
|
|
return C.alpm_option_set_noextracts(handle, l)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) RemoveNoExtract(dir string) (bool, error) {
|
2018-01-14 18:21:50 +01:00
|
|
|
return h.optionRemoveList(dir, func(handle *C.alpm_handle_t, str *C.char) C.int {
|
|
|
|
return C.alpm_option_remove_noextract(handle, str)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) MatchNoExtract(dir string) (bool, error) {
|
2018-01-14 18:21:50 +01:00
|
|
|
return h.optionMatchList(dir, func(handle *C.alpm_handle_t, str *C.char) C.int {
|
|
|
|
return C.alpm_option_match_noextract(handle, str)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) IgnorePkgs() (StringList, error) {
|
2018-01-14 18:21:50 +01:00
|
|
|
return h.optionGetList(func(handle *C.alpm_handle_t) *C.alpm_list_t {
|
|
|
|
return C.alpm_option_get_ignorepkgs(handle)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) AddIgnorePkg(hookDir string) error {
|
2018-01-14 18:21:50 +01:00
|
|
|
return h.optionAddList(hookDir, func(handle *C.alpm_handle_t, str *C.char) C.int {
|
|
|
|
return C.alpm_option_add_ignorepkg(handle, str)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) SetIgnorePkgs(hookDirs []string) error {
|
2018-01-14 18:21:50 +01:00
|
|
|
return h.optionSetList(hookDirs, func(handle *C.alpm_handle_t, l *C.alpm_list_t) C.int {
|
|
|
|
return C.alpm_option_set_ignorepkgs(handle, l)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) RemoveIgnorePkg(dir string) (bool, error) {
|
2018-01-14 18:21:50 +01:00
|
|
|
return h.optionRemoveList(dir, func(handle *C.alpm_handle_t, str *C.char) C.int {
|
|
|
|
return C.alpm_option_remove_ignorepkg(handle, str)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) IgnoreGroups() (StringList, error) {
|
2018-01-14 18:21:50 +01:00
|
|
|
return h.optionGetList(func(handle *C.alpm_handle_t) *C.alpm_list_t {
|
|
|
|
return C.alpm_option_get_ignoregroups(handle)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) AddIgnoreGroup(hookDir string) error {
|
2018-01-14 18:21:50 +01:00
|
|
|
return h.optionAddList(hookDir, func(handle *C.alpm_handle_t, str *C.char) C.int {
|
|
|
|
return C.alpm_option_add_ignoregroup(handle, str)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) SetIgnoreGroups(hookDirs []string) error {
|
2018-01-14 18:21:50 +01:00
|
|
|
return h.optionSetList(hookDirs, func(handle *C.alpm_handle_t, l *C.alpm_list_t) C.int {
|
|
|
|
return C.alpm_option_set_ignoregroups(handle, l)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) RemoveIgnoreGroup(dir string) (bool, error) {
|
2018-01-14 18:21:50 +01:00
|
|
|
return h.optionRemoveList(dir, func(handle *C.alpm_handle_t, str *C.char) C.int {
|
|
|
|
return C.alpm_option_remove_ignoregroup(handle, str)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
/*func (h *Handle) optionGetList(f func(*C.alpm_handle_t) *C.alpm_list_t) (StringList, error){
|
2018-01-14 18:21:50 +01:00
|
|
|
alpmList := f(h.ptr)
|
|
|
|
goList := StringList{(*list)(unsafe.Pointer(alpmList))}
|
|
|
|
|
|
|
|
if alpmList == nil {
|
|
|
|
return goList, h.LastError()
|
|
|
|
}
|
|
|
|
return goList, nil
|
|
|
|
}*/
|
|
|
|
|
|
|
|
//use alpm_depend_t
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) AssumeInstalled() (DependList, error) {
|
2018-01-14 18:21:50 +01:00
|
|
|
alpmList := C.alpm_option_get_assumeinstalled(h.ptr)
|
|
|
|
depList := DependList{(*list)(unsafe.Pointer(alpmList))}
|
|
|
|
|
|
|
|
if alpmList == nil {
|
|
|
|
return depList, h.LastError()
|
|
|
|
}
|
|
|
|
return depList, nil
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) AddAssumeInstalled(dep Depend) error {
|
2018-09-14 02:29:33 +02:00
|
|
|
cDep := convertCDepend(dep)
|
|
|
|
defer freeCDepend(cDep)
|
2018-01-14 18:21:50 +01:00
|
|
|
|
2018-09-14 02:29:33 +02:00
|
|
|
ok := C.alpm_option_add_assumeinstalled(h.ptr, cDep)
|
2018-01-14 18:21:50 +01:00
|
|
|
if ok < 0 {
|
|
|
|
return h.LastError()
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) SetAssumeInstalled(deps []Depend) error {
|
2018-01-14 18:21:50 +01:00
|
|
|
//calling this function the first time causes alpm to set the
|
|
|
|
//assumeinstalled list to a list containing go allocated alpm_depend_t's
|
|
|
|
//this is bad because alpm might at some point tree to free them
|
|
|
|
//i believe this is whats causing this function to misbhave
|
|
|
|
//although i am not 100% sure
|
|
|
|
//maybe using C.malloc to make the struct could fix the problem
|
|
|
|
//pacamn does not use alpm_option_set_assumeinstalled in its source
|
|
|
|
//code so anybody using this should beable to do file without it
|
|
|
|
//although for the sake of completeness it would be nice to have this
|
|
|
|
//working
|
|
|
|
panic("This function (SetAssumeInstalled) does not work properly, please do not use. See source code for more details")
|
2018-09-14 02:29:33 +02:00
|
|
|
var list *C.alpm_list_t
|
2018-01-14 18:21:50 +01:00
|
|
|
|
|
|
|
for _, dep := range deps {
|
2018-09-14 02:29:33 +02:00
|
|
|
cDep := convertCDepend(dep)
|
|
|
|
defer freeCDepend(cDep)
|
|
|
|
list = C.alpm_list_add(list, unsafe.Pointer(cDep))
|
2018-01-14 18:21:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ok := C.alpm_option_set_assumeinstalled(h.ptr, list)
|
|
|
|
if ok < 0 {
|
|
|
|
return h.LastError()
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) RemoveAssumeInstalled(dep Depend) (bool, error) {
|
2018-01-14 18:21:50 +01:00
|
|
|
//internally alpm uses alpm_list_remove to remove a alpm_depend_t from
|
|
|
|
//the list
|
|
|
|
//i believe this function considers items equal if they are the same
|
|
|
|
//item in memeory, not just the same data
|
|
|
|
//every time we convert a go Depend to a alpm_depend_c we create a new
|
|
|
|
//instance of a alpm_depend_c
|
|
|
|
//this means that if you add a Depend using AddAssumeInstalled then try
|
|
|
|
//to remove it using the same Depend c will consider them different
|
|
|
|
//items and not remove them
|
|
|
|
//pacamn does not use alpm_option_set_assumeinstalled in its source
|
|
|
|
//code so anybody using this should beable to do file without it
|
|
|
|
//although for the sake of completeness it would be nice to have this
|
|
|
|
//working
|
|
|
|
panic("This function (RemoveAssumeInstalled) does not work properly, please do not use. See source code for more details")
|
2018-09-14 02:29:33 +02:00
|
|
|
cDep := convertCDepend(dep)
|
|
|
|
defer freeCDepend(cDep)
|
2018-01-14 18:21:50 +01:00
|
|
|
|
2018-09-14 02:29:33 +02:00
|
|
|
ok := C.alpm_option_remove_assumeinstalled(h.ptr, cDep)
|
2018-01-14 18:21:50 +01:00
|
|
|
if ok < 0 {
|
|
|
|
return ok == 1, h.LastError()
|
|
|
|
}
|
|
|
|
return ok == 1, nil
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) Arch() (string, error) {
|
2018-01-14 18:21:50 +01:00
|
|
|
return h.optionGetStr(func(handle *C.alpm_handle_t) *C.char {
|
|
|
|
return C.alpm_option_get_arch(handle)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) SetArch(str string) error {
|
2018-09-14 02:29:33 +02:00
|
|
|
return h.optionSetStr(str, func(handle *C.alpm_handle_t, cStr *C.char) C.int {
|
|
|
|
return C.alpm_option_set_arch(handle, cStr)
|
2018-01-14 18:21:50 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) DeltaRatio() (float64, error) {
|
2018-01-14 18:21:50 +01:00
|
|
|
ok := C.alpm_option_get_deltaratio(h.ptr)
|
|
|
|
if ok < 0 {
|
|
|
|
return float64(ok), h.LastError()
|
|
|
|
}
|
|
|
|
return float64(ok), nil
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) SetDeltaRatio(ratio float64) error {
|
2018-01-14 18:21:50 +01:00
|
|
|
ok := C.alpm_option_set_deltaratio(h.ptr, C.double(ratio))
|
|
|
|
if ok < 0 {
|
|
|
|
return h.LastError()
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
// LocalDB returns the local database relative to the given handle.
|
|
|
|
func (h *Handle) LocalDB() (*DB, error) {
|
|
|
|
db := C.alpm_get_localdb(h.ptr)
|
|
|
|
if db == nil {
|
|
|
|
return nil, h.LastError()
|
|
|
|
}
|
|
|
|
return &DB{db, *h}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// SyncDBs returns list of Synced DBs.
|
|
|
|
func (h *Handle) SyncDBs() (DBList, error) {
|
|
|
|
dblist := C.alpm_get_syncdbs(h.ptr)
|
|
|
|
if dblist == nil {
|
|
|
|
return DBList{nil, *h}, h.LastError()
|
|
|
|
}
|
|
|
|
dblistPtr := unsafe.Pointer(dblist)
|
|
|
|
return DBList{(*list)(dblistPtr), *h}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Handle) CheckSpace() (bool, error) {
|
2018-01-14 18:21:50 +01:00
|
|
|
ok := C.alpm_option_get_checkspace(h.ptr)
|
|
|
|
b := false
|
|
|
|
|
|
|
|
if ok > 0 {
|
|
|
|
b = true
|
|
|
|
}
|
|
|
|
if ok < 0 {
|
|
|
|
return b, h.LastError()
|
|
|
|
}
|
|
|
|
return b, nil
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) SetCheckSpace(value bool) error {
|
2018-09-14 02:29:33 +02:00
|
|
|
var cValue C.int
|
2018-01-14 18:21:50 +01:00
|
|
|
if value {
|
2018-09-14 02:29:33 +02:00
|
|
|
cValue = 1
|
2018-01-14 18:21:50 +01:00
|
|
|
}
|
|
|
|
|
2018-09-14 02:29:33 +02:00
|
|
|
ok := C.alpm_option_set_checkspace(h.ptr, cValue)
|
2018-01-14 18:21:50 +01:00
|
|
|
if ok < 0 {
|
|
|
|
return h.LastError()
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) DBExt() (string, error) {
|
2018-01-14 18:21:50 +01:00
|
|
|
return h.optionGetStr(func(handle *C.alpm_handle_t) *C.char {
|
|
|
|
return C.alpm_option_get_dbext(handle)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) SetDBExt(str string) error {
|
2018-09-14 02:29:33 +02:00
|
|
|
return h.optionSetStr(str, func(handle *C.alpm_handle_t, cStr *C.char) C.int {
|
|
|
|
return C.alpm_option_set_dbext(handle, cStr)
|
2018-01-14 18:21:50 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) GetDefaultSigLevel() (SigLevel, error) {
|
2018-01-14 18:21:50 +01:00
|
|
|
sigLevel := C.alpm_option_get_default_siglevel(h.ptr)
|
|
|
|
|
|
|
|
if sigLevel < 0 {
|
|
|
|
return SigLevel(sigLevel), h.LastError()
|
|
|
|
}
|
|
|
|
return SigLevel(sigLevel), nil
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) SetDefaultSigLevel(siglevel SigLevel) error {
|
2018-05-29 01:05:37 +02:00
|
|
|
ok := C.alpm_option_set_default_siglevel(h.ptr, C.int(siglevel))
|
2018-03-20 08:54:58 +01:00
|
|
|
|
2018-01-14 18:21:50 +01:00
|
|
|
if ok < 0 {
|
|
|
|
return h.LastError()
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) GetLocalFileSigLevel() (SigLevel, error) {
|
2018-01-14 18:21:50 +01:00
|
|
|
sigLevel := C.alpm_option_get_local_file_siglevel(h.ptr)
|
|
|
|
|
|
|
|
if sigLevel < 0 {
|
|
|
|
return SigLevel(sigLevel), h.LastError()
|
|
|
|
}
|
|
|
|
return SigLevel(sigLevel), nil
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) SetLocalFileSigLevel(siglevel SigLevel) error {
|
2018-05-29 01:05:37 +02:00
|
|
|
ok := C.alpm_option_set_local_file_siglevel(h.ptr, C.int(siglevel))
|
2018-03-20 08:54:58 +01:00
|
|
|
|
2018-01-14 18:21:50 +01:00
|
|
|
if ok < 0 {
|
|
|
|
return h.LastError()
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) GetRemoteFileSigLevel() (SigLevel, error) {
|
2018-01-14 18:21:50 +01:00
|
|
|
sigLevel := C.alpm_option_get_remote_file_siglevel(h.ptr)
|
|
|
|
|
|
|
|
if sigLevel < 0 {
|
|
|
|
return SigLevel(sigLevel), h.LastError()
|
|
|
|
}
|
|
|
|
return SigLevel(sigLevel), nil
|
|
|
|
}
|
|
|
|
|
2019-02-04 17:56:02 +01:00
|
|
|
func (h *Handle) SetRemoteFileSigLevel(siglevel SigLevel) error {
|
2018-05-29 01:05:37 +02:00
|
|
|
ok := C.alpm_option_set_remote_file_siglevel(h.ptr, C.int(siglevel))
|
2018-01-14 18:21:50 +01:00
|
|
|
|
|
|
|
if ok < 0 {
|
|
|
|
return h.LastError()
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|