diff --git a/db.go b/db.go index 9870a51..639406b 100644 --- a/db.go +++ b/db.go @@ -48,6 +48,16 @@ func (l DBList) Slice() []IDB { return slice } +// Append modifies a DB list by appending the given DB. +func (l *DBList) Append(db IDB) { + cdblist := (*C.alpm_list_t)(unsafe.Pointer(l.list)) + cdb := unsafe.Pointer(db.(*DB).ptr) + + cdblist = C.alpm_list_add(cdblist, cdb) + + l.list = (*list)(unsafe.Pointer(cdblist)) +} + // SyncDBByName finds a registered database by name. func (h *Handle) SyncDBByName(name string) (db IDB, err error) { dblist, err := h.SyncDBs() @@ -70,6 +80,20 @@ func (h *Handle) SyncDBByName(name string) (db IDB, err error) { return nil, fmt.Errorf("database %s not found", name) } +// SyncDBListByDBName creates and returns a database list with a single +// database given by name. +func (h *Handle) SyncDBListByDBName(name string) (IDBList, error) { + db, err := h.SyncDBByName(name) + if err != nil { + return nil, err + } + + dblist := h.NewDBList() + dblist.Append(db) + + return dblist, nil +} + // RegisterSyncDB Loads a sync database with given name and signature check level. func (h *Handle) RegisterSyncDB(dbname string, siglevel SigLevel) (IDB, error) { cName := C.CString(dbname) diff --git a/handle.go b/handle.go index a874ffc..a0911a4 100644 --- a/handle.go +++ b/handle.go @@ -408,6 +408,11 @@ func (h *Handle) SyncDBs() (IDBList, error) { return &DBList{(*list)(unsafe.Pointer(dblist)), *h}, nil } +// NewDBList returns a new empty DB list. +func (h *Handle) NewDBList() IDBList { + return &DBList{nil, *h} +} + func (h *Handle) CheckSpace() (bool, error) { ok := C.alpm_option_get_checkspace(h.ptr) diff --git a/interfaces.go b/interfaces.go index aff77d8..987dc97 100644 --- a/interfaces.go +++ b/interfaces.go @@ -123,6 +123,8 @@ type IDBList interface { ForEach(func(IDB) error) error // Slice converts DB list to DB slice. Slice() []IDB + // Append modifies DB list with given DB appended. + Append(IDB) // PkgCachebyGroup returns a PackageList of packages belonging to a group FindGroupPkgs(string) IPackageList // FindSatisfier searches a DBList for a package that satisfies depstring