Skip to content

Commit

Permalink
cleanup: remove broken symlink for uninstalled migrated Casks
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Cho <[email protected]>
  • Loading branch information
cho-m committed Mar 10, 2024
1 parent cd1f040 commit 5d52045
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Library/Homebrew/cleanup.rb
Expand Up @@ -630,6 +630,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
16 changes: 16 additions & 0 deletions Library/Homebrew/test/cleanup_spec.rb
Expand Up @@ -95,6 +95,22 @@
end
end

describe "::prune_prefix_symlinks_and_directories" do
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
f1 = Class.new(Testball) do
version "1.0"
Expand Down

0 comments on commit 5d52045

Please sign in to comment.