From 076bebbedfa743532e1ad3f3eeb5096294beb807 Mon Sep 17 00:00:00 2001 From: AI Bot Date: Tue, 14 Apr 2026 22:05:42 +0200 Subject: [PATCH] Register sync DBs manually to fix dyalpm returning empty list The dyalpm library's SyncDBs() returns an empty slice, causing packages from official repos (extra, core, multilib) to not be found. This fix manually registers each repo after getting an empty result. --- .../changes/fix-sync-dbs-not-loaded/tasks.md | 10 +++--- pkg/pacman/pacman.go | 35 +++++++++++++++++++ 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/openspec/changes/fix-sync-dbs-not-loaded/tasks.md b/openspec/changes/fix-sync-dbs-not-loaded/tasks.md index 414c1a1..ba4bab4 100644 --- a/openspec/changes/fix-sync-dbs-not-loaded/tasks.md +++ b/openspec/changes/fix-sync-dbs-not-loaded/tasks.md @@ -1,10 +1,10 @@ ## 1. Implement sync DB registration -- [ ] 1.1 Modify Pac struct to include a method for registering sync DBs -- [ ] 1.2 In New(), after getting empty syncDBs from handle, loop through ["core", "extra", "multilib"] and call RegisterSyncDB for each -- [ ] 1.3 Filter out repos that have no packages (not configured in pacman.conf) +- [x] 1.1 Modify Pac struct to include a method for registering sync DBs +- [x] 1.2 In New(), after getting empty syncDBs from handle, loop through ["core", "extra", "multilib"] and call RegisterSyncDB for each +- [x] 1.3 Filter out repos that have no packages (not configured in pacman.conf) ## 2. Test the fix -- [ ] 2.1 Run `./declpac --dry-run --state <(echo "cmake")` and verify it resolves cmake from extra repo -- [ ] 2.2 Test with other official repo packages (e.g., "git" from extra, "base" from core) \ No newline at end of file +- [x] 2.1 Run `./declpac --dry-run --state <(echo "cmake")` and verify it resolves cmake from extra repo +- [x] 2.2 Test with other official repo packages (e.g., "git" from extra, "base" from core) \ No newline at end of file diff --git a/pkg/pacman/pacman.go b/pkg/pacman/pacman.go index 5ef38a0..16e470a 100644 --- a/pkg/pacman/pacman.go +++ b/pkg/pacman/pacman.go @@ -50,6 +50,14 @@ func New() (*Pac, error) { return nil, fmt.Errorf("failed to get sync databases: %w", err) } + if len(syncDBs) == 0 { + syncDBs, err = registerSyncDBs(handle) + if err != nil { + handle.Release() + return nil, fmt.Errorf("failed to register sync databases: %w", err) + } + } + fmt.Fprintf(os.Stderr, "[debug] New: done (%.2fs)\n", time.Since(start).Seconds()) return &Pac{ aurCache: make(map[string]AURPackage), @@ -66,6 +74,33 @@ func (p *Pac) Close() error { return nil } +func registerSyncDBs(handle dyalpm.Handle) ([]dyalpm.Database, error) { + fmt.Fprintf(os.Stderr, "[debug] registerSyncDBs: starting...\n") + + repos := []string{"core", "extra", "multilib"} + var dbs []dyalpm.Database + + for _, repo := range repos { + db, err := handle.RegisterSyncDB(repo, 0) + if err != nil { + continue + } + + count := 0 + db.PkgCache().ForEach(func(pkg dyalpm.Package) error { + count++ + return nil + }) + + if count > 0 { + dbs = append(dbs, db) + } + } + + fmt.Fprintf(os.Stderr, "[debug] registerSyncDBs: done (%d dbs)\n", len(dbs)) + return dbs, nil +} + type PackageInfo struct { Name string InAUR bool