Skip to content

Commit

Permalink
Fix yay -Sc wiping ~/.cache/yay on 3rd question.
Browse files Browse the repository at this point in the history
If you answer yes to
    :: Do you want to remove all other AUR packages from cache? [Y/n]
then we run cleanAUR(), intending to remove subdirectories of
~/.cache/yay that do not share a name with installed packages not
found in the sync repositories.

Where this was going wrong was cleanAUR() was getting an empty map from
dbExecutor.InstalledRemotePackages()---because InstalledRemotePackages
only recomputes its result if installedRemotePkgMap is nil, whereas
NewExecutor initialized it to an empty map. The symptom was it emptied
my ~/.cache/yay.

We do want a non-nil, empty installedRemotePkgMap to block recomputing
(that is, to indicate the user really has no remote packages), so now
NewExecutor initializes it to nil, and getPackageNamesBySource is
responsible for making sure it's non-nil before writing to it.

Fixes #2152, which seems to have been introduced in
4626a04.
  • Loading branch information
pteromys committed May 22, 2023
1 parent ec15a5b commit 3e4901e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/db/ialpm/alpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func NewExecutor(pacmanConf *pacmanconf.Config, logger *text.Logger) (*AlpmExecu
conf: pacmanConf,
log: logger,
installedRemotePkgNames: nil,
installedRemotePkgMap: map[string]alpm.IPackage{},
installedRemotePkgMap: nil,
installedSyncPkgNames: nil,
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/db/ialpm/high_level.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (

// GetPackageNamesBySource returns package names with and without correspondence in SyncDBS respectively.
func (ae *AlpmExecutor) getPackageNamesBySource() {
if ae.installedRemotePkgMap == nil {
ae.installedRemotePkgMap = map[string]alpm.IPackage{}
}
for _, localpkg := range ae.LocalPackages() {
pkgName := localpkg.Name()
if ae.SyncPackage(pkgName) != nil {
Expand Down

0 comments on commit 3e4901e

Please sign in to comment.