diff options
| author | Markus Reiter | 2017-02-04 23:53:16 +0100 |
|---|---|---|
| committer | GitHub | 2017-02-04 23:53:16 +0100 |
| commit | 33fa80944ebff6b609e67712fb87ccc394cb327b (patch) | |
| tree | fe188fd49cebef15c2a92b1366981655c785f149 | |
| parent | 7c368962c9fc968beb812af9d209da2038c74cfb (diff) | |
| parent | d22cfd3866257abb9c3ade46c6c34f341cf70514 (diff) | |
| download | brew-33fa80944ebff6b609e67712fb87ccc394cb327b.tar.bz2 | |
Merge pull request #1743 from toonetown/robust-pkgutil-cleanup
Delete pkgutil directories that are really files.
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/pkg.rb | 8 | ||||
| -rw-r--r-- | Library/Homebrew/cask/test/cask/pkg_test.rb | 27 |
2 files changed, 30 insertions, 5 deletions
diff --git a/Library/Homebrew/cask/lib/hbc/pkg.rb b/Library/Homebrew/cask/lib/hbc/pkg.rb index 2fb634f24..39252b48a 100644 --- a/Library/Homebrew/cask/lib/hbc/pkg.rb +++ b/Library/Homebrew/cask/lib/hbc/pkg.rb @@ -26,6 +26,7 @@ module Hbc _deepest_path_first(pkgutil_bom_dirs).each do |dir| next unless dir.exist? && !MacOS.undeletable?(dir) _with_full_permissions(dir) do + _delete_broken_file_dir(dir) && next _clean_broken_symlinks(dir) _clean_ds_store(dir) _rmdir(dir) @@ -97,6 +98,13 @@ module Hbc end end + # Some pkgs incorrectly report files (generally nibs) + # as directories; we remove these as files instead. + def _delete_broken_file_dir(path) + return unless path.file? && !path.symlink? + @command.run!("/bin/rm", args: ["-f", "--", path], sudo: true) + end + # Some pkgs leave broken symlinks hanging around; we clean them out before # attempting to rmdir to prevent extra cruft from lying around after # uninstall diff --git a/Library/Homebrew/cask/test/cask/pkg_test.rb b/Library/Homebrew/cask/test/cask/pkg_test.rb index 85a42356e..ac43f9e63 100644 --- a/Library/Homebrew/cask/test/cask/pkg_test.rb +++ b/Library/Homebrew/cask/test/cask/pkg_test.rb @@ -5,13 +5,13 @@ describe Hbc::Pkg do it "removes files and dirs referenced by the pkg" do pkg = Hbc::Pkg.new("my.fake.pkg", Hbc::NeverSudoSystemCommand) - some_files = Array.new(3) { Pathname(Tempfile.new("testfile").path) } + some_files = Array.new(3) { Pathname.new(Tempfile.new("testfile").path) } pkg.stubs(:pkgutil_bom_files).returns some_files - some_specials = Array.new(3) { Pathname(Tempfile.new("testfile").path) } + some_specials = Array.new(3) { Pathname.new(Tempfile.new("testfile").path) } pkg.stubs(:pkgutil_bom_specials).returns some_specials - some_dirs = Array.new(3) { Pathname(Dir.mktmpdir) } + some_dirs = Array.new(3) { Pathname.new(Dir.mktmpdir) } pkg.stubs(:pkgutil_bom_dirs).returns some_dirs pkg.stubs(:forget) @@ -50,7 +50,7 @@ describe Hbc::Pkg do it "cleans broken symlinks, but leaves AOK symlinks" do pkg = Hbc::Pkg.new("my.fake.pkg", Hbc::NeverSudoSystemCommand) - fake_dir = Pathname(Dir.mktmpdir) + fake_dir = Pathname.new(Dir.mktmpdir) fake_file = fake_dir.join("ima_file").tap { |path| FileUtils.touch(path) } intact_symlink = fake_dir.join("intact_symlink").tap { |path| path.make_symlink(fake_file) } @@ -68,10 +68,27 @@ describe Hbc::Pkg do fake_dir.must_be :exist? end + it "cleans files incorrectly reported as directories" do + pkg = Hbc::Pkg.new("my.fake.pkg", Hbc::NeverSudoSystemCommand) + + fake_dir = Pathname.new(Dir.mktmpdir) + fake_file = fake_dir.join("ima_file_pretending_to_be_a_dir").tap { |path| FileUtils.touch(path) } + + pkg.stubs(:pkgutil_bom_specials).returns([]) + pkg.stubs(:pkgutil_bom_files).returns([]) + pkg.stubs(:pkgutil_bom_dirs).returns([fake_file, fake_dir]) + pkg.stubs(:forget) + + pkg.uninstall + + fake_file.wont_be :exist? + fake_dir.wont_be :exist? + end + it "snags permissions on ornery dirs, but returns them afterwords" do pkg = Hbc::Pkg.new("my.fake.pkg", Hbc::NeverSudoSystemCommand) - fake_dir = Pathname(Dir.mktmpdir) + fake_dir = Pathname.new(Dir.mktmpdir) fake_file = fake_dir.join("ima_installed_file").tap { |path| FileUtils.touch(path) } |
