Always prune empty toplevel directories when unlinking
Closes Homebrew/homebrew#21750.
This commit is contained in:
parent
e4b951520a
commit
d5325eb4e4
@ -37,6 +37,8 @@ class Keg < Pathname
|
||||
# of files and directories linked
|
||||
$n=$d=0
|
||||
|
||||
dirs = []
|
||||
|
||||
TOP_LEVEL_DIRECTORIES.map{ |d| self/d }.each do |dir|
|
||||
next unless dir.exist?
|
||||
dir.find do |src|
|
||||
@ -44,6 +46,8 @@ class Keg < Pathname
|
||||
dst = HOMEBREW_PREFIX + src.relative_path_from(self)
|
||||
dst.extend(ObserverPathnameExtension)
|
||||
|
||||
dirs << dst if dst.directory? && !dst.symlink?
|
||||
|
||||
# check whether the file to be unlinked is from the current keg first
|
||||
if !dst.symlink? || !dst.exist? || src != dst.resolved_path
|
||||
next
|
||||
@ -51,11 +55,13 @@ class Keg < Pathname
|
||||
|
||||
dst.uninstall_info if dst.to_s =~ INFOFILE_RX and ENV['HOMEBREW_KEEP_INFO']
|
||||
dst.unlink
|
||||
dst.parent.extend(ObserverPathnameExtension).rmdir_if_possible
|
||||
Find.prune if src.directory?
|
||||
end
|
||||
end
|
||||
linked_keg_record.unlink if linked_keg_record.symlink?
|
||||
|
||||
dirs.reverse_each(&:rmdir_if_possible)
|
||||
|
||||
$n+$d
|
||||
end
|
||||
|
||||
|
||||
@ -85,17 +85,17 @@ class LinkTests < Test::Unit::TestCase
|
||||
assert_equal "#{HOMEBREW_PREFIX}/bin/helloworld\n", $stdout.string
|
||||
end
|
||||
|
||||
def test_unlink_prunes_empty_toplevel_directories_fails
|
||||
def test_unlink_prunes_empty_toplevel_directories
|
||||
mkpath HOMEBREW_PREFIX/"lib/foo/bar"
|
||||
mkpath @keg/"lib/foo/bar"
|
||||
touch @keg/"lib/foo/bar/file1"
|
||||
|
||||
@keg.unlink
|
||||
|
||||
assert File.directory?(HOMEBREW_PREFIX/"lib/foo")
|
||||
assert !File.directory?(HOMEBREW_PREFIX/"lib/foo")
|
||||
end
|
||||
|
||||
def test_unlink_ignores_DS_Store_when_pruning_empty_dirs_fails
|
||||
def test_unlink_ignores_DS_Store_when_pruning_empty_dirs
|
||||
mkpath HOMEBREW_PREFIX/"lib/foo/bar"
|
||||
touch HOMEBREW_PREFIX/"lib/foo/.DS_Store"
|
||||
mkpath @keg/"lib/foo/bar"
|
||||
@ -103,8 +103,8 @@ class LinkTests < Test::Unit::TestCase
|
||||
|
||||
@keg.unlink
|
||||
|
||||
assert File.directory?(HOMEBREW_PREFIX/"lib/foo")
|
||||
assert File.exist?(HOMEBREW_PREFIX/"lib/foo/.DS_Store")
|
||||
assert !File.directory?(HOMEBREW_PREFIX/"lib/foo")
|
||||
assert !File.exist?(HOMEBREW_PREFIX/"lib/foo/.DS_Store")
|
||||
end
|
||||
|
||||
def teardown
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user