Browse Source

Fix AUR package detection for installed packages

master
AI Bot 3 days ago committed by Riyyi
parent
commit
0fa0988666
  1. 59
      pkg/fetch/fetch.go
  2. 12
      pkg/pacman/pacman.go

59
pkg/fetch/fetch.go

@ -188,6 +188,9 @@ func (f *Fetcher) Resolve(packages []string) (map[string]*PackageInfo, error) {
fmt.Fprintf(os.Stderr, "[debug] Resolve: starting...\n")
result := make(map[string]*PackageInfo)
for _, pkg := range packages {
result[pkg] = &PackageInfo{Name: pkg, Exists: true}
}
localPkgs, err := f.buildLocalPkgMap()
if err != nil {
@ -215,44 +218,38 @@ func (f *Fetcher) Resolve(packages []string) (map[string]*PackageInfo, error) {
if err != nil {
return nil, err
}
fmt.Fprintf(os.Stderr, "[debug] Resolve: sync db checked (%.2fs)\n", time.Since(start).Seconds())
var notInSync []string
for _, pkg := range notInLocal {
if syncPkg, ok := syncPkgs[pkg]; ok {
result[pkg] = &PackageInfo{
Name: pkg,
Exists: true,
InAUR: false,
Installed: false,
syncPkg: syncPkg,
}
} else {
notInSync = append(notInSync, pkg)
}
}
f.ensureAURCache(packages)
if len(notInSync) > 0 {
f.ensureAURCache(notInSync)
fmt.Fprintf(os.Stderr, "[debug] Resolve: AUR cache ensured (%.2fs)\n", time.Since(start).Seconds())
for _, pkg := range packages {
info := result[pkg]
if info == nil {
continue
}
var unfound []string
for _, pkg := range notInSync {
if info.Installed {
if aurInfo, ok := f.aurCache[pkg]; ok {
result[pkg] = &PackageInfo{
Name: pkg,
Exists: true,
InAUR: true,
Installed: false,
AURInfo: &aurInfo,
}
} else {
unfound = append(unfound, pkg)
info.InAUR = true
info.AURInfo = &aurInfo
}
continue
}
if syncPkg, ok := syncPkgs[pkg]; ok {
info.InAUR = false
info.Installed = false
info.syncPkg = syncPkg
continue
}
if len(unfound) > 0 {
return nil, fmt.Errorf("package(s) not found: %s", strings.Join(unfound, ", "))
if aurInfo, ok := f.aurCache[pkg]; ok {
info.InAUR = true
info.Installed = false
info.AURInfo = &aurInfo
continue
}
return nil, fmt.Errorf("package not found: %s", pkg)
}
}

12
pkg/pacman/pacman.go

@ -200,7 +200,7 @@ func SyncPackages(packages []string) (int, error) {
start := time.Now()
fmt.Fprintf(os.Stderr, "[debug] SyncPackages: starting...\n")
args := append([]string{"-Syu"}, packages...)
args := append([]string{"-S", "--needed"}, packages...)
cmd := exec.Command("pacman", args...)
output, err := cmd.CombinedOutput()
if err != nil {
@ -271,12 +271,10 @@ func DryRun(packages []string) (*output.Result, error) {
if info == nil || !info.Exists {
return nil, fmt.Errorf("package not found: %s", pkg)
}
if _, installed := localPkgs[pkg]; !installed {
if info.InAUR {
aurPkgs = append(aurPkgs, pkg)
} else {
toInstall = append(toInstall, pkg)
}
if info.InAUR {
aurPkgs = append(aurPkgs, pkg)
} else if _, installed := localPkgs[pkg]; !installed {
toInstall = append(toInstall, pkg)
}
}
fmt.Fprintf(os.Stderr, "[debug] DryRun: packages categorized (%.2fs)\n", time.Since(start).Seconds())

Loading…
Cancel
Save