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