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.
This commit is contained in:
@@ -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)
|
||||
- [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)
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user