aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Library/Homebrew/keg.rb8
-rw-r--r--Library/Homebrew/test/test_keg.rb10
2 files changed, 12 insertions, 6 deletions
diff --git a/Library/Homebrew/keg.rb b/Library/Homebrew/keg.rb
index 93e8b7857..6218668d6 100644
--- a/Library/Homebrew/keg.rb
+++ b/Library/Homebrew/keg.rb
@@ -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
diff --git a/Library/Homebrew/test/test_keg.rb b/Library/Homebrew/test/test_keg.rb
index de6ffa0d8..d9cce89fa 100644
--- a/Library/Homebrew/test/test_keg.rb
+++ b/Library/Homebrew/test/test_keg.rb
@@ -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