mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Merge pull request #16872 from cho-m/cleanup-cask-broken-symlinks
cleanup: remove broken symlink for uninstalled migrated Casks
This commit is contained in:
commit
87bf4af3fc
@ -642,6 +642,20 @@ module Homebrew
|
||||
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?
|
||||
|
@ -163,6 +163,20 @@ RSpec.describe Homebrew::Cleanup do
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user