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

cleanup: remove broken symlink for uninstalled migrated Casks #16872

Merged
merged 1 commit into from Mar 31, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions Library/Homebrew/cleanup.rb
Expand Up @@ -634,6 +634,20 @@ def prune_prefix_symlinks_and_directories
end
end

require "cask/caskroom"
if Cask::Caskroom.path.directory?
Cask::Caskroom.path.each_child do |path|
path.extend(ObserverPathnameExtension)
next if !path.symlink? || path.resolved_path_exists?

if dry_run?
puts "Would remove (broken link): #{path}"
else
path.unlink
end
end
end

return if dry_run?

return if ObserverPathnameExtension.total.zero?
Expand Down
14 changes: 14 additions & 0 deletions Library/Homebrew/test/cleanup_spec.rb
Expand Up @@ -163,6 +163,20 @@
expect(grandchild_dir).to exist
end
end

it "removes broken symlinks for uninstalled migrated Casks" do
caskroom = Cask::Caskroom.path
old_cask_dir = caskroom/"old"
new_cask_dir = caskroom/"new"
unrelated_cask_dir = caskroom/"other"
unrelated_cask_dir.mkpath
FileUtils.ln_s new_cask_dir, old_cask_dir

cleanup.prune_prefix_symlinks_and_directories
expect(unrelated_cask_dir).to exist
expect(old_cask_dir).not_to be_a_symlink
expect(old_cask_dir).not_to exist
end
end

specify "::cleanup_formula" do
Expand Down