Skip to content
Snippets Groups Projects
Unverified Commit cb4316df authored by Markus Reiter's avatar Markus Reiter Committed by GitHub
Browse files

Merge pull request #6922 from danielbayley/rmdir

Make rmdir: recursive
parents 11bdacf1 f3a0fcfb
No related branches found
No related tags found
No related merge requests found
......@@ -385,20 +385,37 @@ module Cask
[trashed, untrashable]
end
def uninstall_rmdir(*directories, command: nil, **_)
return if directories.empty?
def all_dirs?(*directories)
directories.all?(&:directory?)
end
def recursive_rmdir(*directories, command: nil, **_)
success = true
each_resolved_path(:rmdir, directories) do |_path, resolved_paths|
resolved_paths.select(&method(:all_dirs?)).each do |resolved_path|
puts resolved_path.sub(Dir.home, "~")
ohai "Removing directories if empty:"
each_resolved_path(:rmdir, directories) do |path, resolved_paths|
puts path
resolved_paths.select(&:directory?).each do |resolved_path|
if (ds_store = resolved_path.join(".DS_Store")).exist?
command.run!("/bin/rm", args: ["-f", "--", ds_store], sudo: true, print_stderr: false)
end
command.run("/bin/rmdir", args: ["--", resolved_path], sudo: true, print_stderr: false)
unless recursive_rmdir(*resolved_path.children, command: command)
success = false
next
end
status = command.run("/bin/rmdir", args: ["--", resolved_path], sudo: true, print_stderr: false).success?
success &= status
end
end
success
end
def uninstall_rmdir(*args)
return if args.empty?
ohai "Removing directories if empty:"
recursive_rmdir(*args)
end
end
end
......
......@@ -14,10 +14,11 @@ describe Cask::Artifact::Uninstall, :cask do
let(:fake_system_command) { NeverSudoSystemCommand }
let(:cask) { Cask::CaskLoader.load(cask_path("with-uninstall-rmdir")) }
let(:empty_directory) { Pathname.new("#{TEST_TMPDIR}/empty_directory_path") }
let(:empty_directory_tree) { empty_directory.join("nested", "empty_directory_path") }
let(:ds_store) { empty_directory.join(".DS_Store") }
before do
empty_directory.mkdir
empty_directory_tree.mkpath
FileUtils.touch ds_store
end
......@@ -26,7 +27,7 @@ describe Cask::Artifact::Uninstall, :cask do
end
it "is supported" do
expect(empty_directory).to exist
expect(empty_directory_tree).to exist
expect(ds_store).to exist
artifact.post_uninstall_phase(command: fake_system_command)
......
......@@ -12,10 +12,11 @@ describe Cask::Artifact::Zap, :cask do
let(:fake_system_command) { NeverSudoSystemCommand }
let(:cask) { Cask::CaskLoader.load(cask_path("with-zap-rmdir")) }
let(:empty_directory) { Pathname.new("#{TEST_TMPDIR}/empty_directory_path") }
let(:empty_directory_tree) { empty_directory.join("nested", "empty_directory_path") }
let(:ds_store) { empty_directory.join(".DS_Store") }
before do
empty_directory.mkdir
empty_directory_tree.mkpath
FileUtils.touch ds_store
end
......@@ -24,7 +25,7 @@ describe Cask::Artifact::Zap, :cask do
end
it "is supported" do
expect(empty_directory).to exist
expect(empty_directory_tree).to exist
expect(ds_store).to exist
artifact.zap_phase(command: fake_system_command)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment