Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SyncDBListByDBName method #62

Merged
merged 1 commit into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 2 additions & 0 deletions interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down