commit
afb66d0c69
@ -34,6 +34,10 @@ module Hbc
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.expand_glob(path_strings)
|
||||||
|
path_strings.flat_map(&Pathname.method(:glob))
|
||||||
|
end
|
||||||
|
|
||||||
def self.remove_relative_path_strings(action, path_strings)
|
def self.remove_relative_path_strings(action, path_strings)
|
||||||
relative = path_strings.map do |path_string|
|
relative = path_strings.map do |path_string|
|
||||||
path_string if %r{/\.\.(?:/|\Z)}.match(path_string) || !%r{\A/}.match(path_string)
|
path_string if %r{/\.\.(?:/|\Z)}.match(path_string) || !%r{\A/}.match(path_string)
|
||||||
@ -54,6 +58,13 @@ module Hbc
|
|||||||
path_strings - undeletable
|
path_strings - undeletable
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.prepare_path_strings(action, path_strings, expand_tilde)
|
||||||
|
path_strings = expand_path_strings(path_strings) if expand_tilde
|
||||||
|
path_strings = remove_relative_path_strings(action, path_strings)
|
||||||
|
path_strings = expand_glob(path_strings)
|
||||||
|
remove_undeletable_path_strings(action, path_strings)
|
||||||
|
end
|
||||||
|
|
||||||
def dispatch_uninstall_directives(expand_tilde: true)
|
def dispatch_uninstall_directives(expand_tilde: true)
|
||||||
directives_set = @cask.artifacts[stanza]
|
directives_set = @cask.artifacts[stanza]
|
||||||
ohai "Running #{stanza} process for #{@cask}; your password may be necessary"
|
ohai "Running #{stanza} process for #{@cask}; your password may be necessary"
|
||||||
@ -225,9 +236,7 @@ module Hbc
|
|||||||
def uninstall_delete(directives, expand_tilde = true)
|
def uninstall_delete(directives, expand_tilde = true)
|
||||||
Array(directives[:delete]).concat(Array(directives[:trash])).flatten.each_slice(PATH_ARG_SLICE_SIZE) do |path_slice|
|
Array(directives[:delete]).concat(Array(directives[:trash])).flatten.each_slice(PATH_ARG_SLICE_SIZE) do |path_slice|
|
||||||
ohai "Removing files: #{path_slice.utf8_inspect}"
|
ohai "Removing files: #{path_slice.utf8_inspect}"
|
||||||
path_slice = self.class.expand_path_strings(path_slice) if expand_tilde
|
path_slice = self.class.prepare_path_strings(:delete, path_slice, expand_tilde)
|
||||||
path_slice = self.class.remove_relative_path_strings(:delete, path_slice)
|
|
||||||
path_slice = self.class.remove_undeletable_path_strings(:delete, path_slice)
|
|
||||||
@command.run!("/bin/rm", args: path_slice.unshift("-rf", "--"), sudo: true)
|
@command.run!("/bin/rm", args: path_slice.unshift("-rf", "--"), sudo: true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -238,11 +247,9 @@ module Hbc
|
|||||||
uninstall_delete(directives, expand_tilde)
|
uninstall_delete(directives, expand_tilde)
|
||||||
end
|
end
|
||||||
|
|
||||||
def uninstall_rmdir(directives, expand_tilde = true)
|
def uninstall_rmdir(directories, expand_tilde = true)
|
||||||
Array(directives[:rmdir]).flatten.each do |directory|
|
action = :rmdir
|
||||||
directory = self.class.expand_path_strings([directory]).first if expand_tilde
|
self.class.prepare_path_strings(action, Array(directories[action]).flatten, expand_tilde).each do |directory|
|
||||||
directory = self.class.remove_relative_path_strings(:rmdir, [directory]).first
|
|
||||||
directory = self.class.remove_undeletable_path_strings(:rmdir, [directory]).first
|
|
||||||
next if directory.to_s.empty?
|
next if directory.to_s.empty?
|
||||||
ohai "Removing directory if empty: #{directory.to_s.utf8_inspect}"
|
ohai "Removing directory if empty: #{directory.to_s.utf8_inspect}"
|
||||||
directory = Pathname.new(directory)
|
directory = Pathname.new(directory)
|
||||||
|
|||||||
@ -7,7 +7,17 @@ describe Hbc::Artifact::Uninstall do
|
|||||||
Hbc::Artifact::Uninstall.new(cask, command: Hbc::FakeSystemCommand)
|
Hbc::Artifact::Uninstall.new(cask, command: Hbc::FakeSystemCommand)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let(:absolute_path) { Pathname.new("#{TEST_TMPDIR}/absolute_path") }
|
||||||
|
let(:path_with_tilde) { Pathname.new("#{TEST_TMPDIR}/path_with_tilde") }
|
||||||
|
let(:glob_path1) { Pathname.new("#{TEST_TMPDIR}/glob_path1") }
|
||||||
|
let(:glob_path2) { Pathname.new("#{TEST_TMPDIR}/glob_path2") }
|
||||||
|
|
||||||
before(:each) do
|
before(:each) do
|
||||||
|
FileUtils.touch(absolute_path)
|
||||||
|
FileUtils.touch(path_with_tilde)
|
||||||
|
FileUtils.touch(glob_path1)
|
||||||
|
FileUtils.touch(glob_path2)
|
||||||
|
ENV["HOME"] = TEST_TMPDIR
|
||||||
shutup do
|
shutup do
|
||||||
InstallHelper.install_without_artifacts(cask)
|
InstallHelper.install_without_artifacts(cask)
|
||||||
end
|
end
|
||||||
@ -233,8 +243,10 @@ describe Hbc::Artifact::Uninstall do
|
|||||||
it "can uninstall" do
|
it "can uninstall" do
|
||||||
Hbc::FakeSystemCommand.expects_command(
|
Hbc::FakeSystemCommand.expects_command(
|
||||||
sudo(%w[/bin/rm -rf --],
|
sudo(%w[/bin/rm -rf --],
|
||||||
Pathname.new("/permissible/absolute/path"),
|
absolute_path,
|
||||||
Pathname.new("~/permissible/path/with/tilde").expand_path),
|
path_with_tilde,
|
||||||
|
glob_path1,
|
||||||
|
glob_path2),
|
||||||
)
|
)
|
||||||
|
|
||||||
subject
|
subject
|
||||||
@ -247,8 +259,10 @@ describe Hbc::Artifact::Uninstall do
|
|||||||
it "can uninstall" do
|
it "can uninstall" do
|
||||||
Hbc::FakeSystemCommand.expects_command(
|
Hbc::FakeSystemCommand.expects_command(
|
||||||
sudo(%w[/bin/rm -rf --],
|
sudo(%w[/bin/rm -rf --],
|
||||||
Pathname.new("/permissible/absolute/path"),
|
absolute_path,
|
||||||
Pathname.new("~/permissible/path/with/tilde").expand_path),
|
path_with_tilde,
|
||||||
|
glob_path1,
|
||||||
|
glob_path2),
|
||||||
)
|
)
|
||||||
|
|
||||||
subject
|
subject
|
||||||
@ -257,15 +271,23 @@ describe Hbc::Artifact::Uninstall do
|
|||||||
|
|
||||||
context "when using rmdir" do
|
context "when using rmdir" do
|
||||||
let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-uninstall-rmdir.rb") }
|
let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-uninstall-rmdir.rb") }
|
||||||
let(:dir_pathname) { Pathname.new("#{TEST_FIXTURE_DIR}/cask/empty_directory") }
|
let(:empty_directory_path) { Pathname.new("#{TEST_TMPDIR}/empty_directory_path") }
|
||||||
|
|
||||||
|
before(:each) do
|
||||||
|
empty_directory_path.mkdir
|
||||||
|
end
|
||||||
|
|
||||||
|
after(:each) do
|
||||||
|
empty_directory_path.rmdir
|
||||||
|
end
|
||||||
|
|
||||||
it "can uninstall" do
|
it "can uninstall" do
|
||||||
Hbc::FakeSystemCommand.expects_command(
|
Hbc::FakeSystemCommand.expects_command(
|
||||||
sudo(%w[/bin/rm -f --], dir_pathname.join(".DS_Store")),
|
sudo(%w[/bin/rm -f --], empty_directory_path/".DS_Store"),
|
||||||
)
|
)
|
||||||
|
|
||||||
Hbc::FakeSystemCommand.expects_command(
|
Hbc::FakeSystemCommand.expects_command(
|
||||||
sudo(%w[/bin/rmdir --], dir_pathname),
|
sudo(%w[/bin/rmdir --], empty_directory_path),
|
||||||
)
|
)
|
||||||
|
|
||||||
subject
|
subject
|
||||||
|
|||||||
@ -8,7 +8,17 @@ describe Hbc::Artifact::Zap do
|
|||||||
Hbc::Artifact::Zap.new(cask, command: Hbc::FakeSystemCommand)
|
Hbc::Artifact::Zap.new(cask, command: Hbc::FakeSystemCommand)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let(:absolute_path) { Pathname.new("#{TEST_TMPDIR}/absolute_path") }
|
||||||
|
let(:path_with_tilde) { Pathname.new("#{TEST_TMPDIR}/path_with_tilde") }
|
||||||
|
let(:glob_path1) { Pathname.new("#{TEST_TMPDIR}/glob_path1") }
|
||||||
|
let(:glob_path2) { Pathname.new("#{TEST_TMPDIR}/glob_path2") }
|
||||||
|
|
||||||
before(:each) do
|
before(:each) do
|
||||||
|
FileUtils.touch(absolute_path)
|
||||||
|
FileUtils.touch(path_with_tilde)
|
||||||
|
FileUtils.touch(glob_path1)
|
||||||
|
FileUtils.touch(glob_path2)
|
||||||
|
ENV["HOME"] = TEST_TMPDIR
|
||||||
shutup do
|
shutup do
|
||||||
InstallHelper.install_without_artifacts(cask)
|
InstallHelper.install_without_artifacts(cask)
|
||||||
end
|
end
|
||||||
@ -234,8 +244,10 @@ describe Hbc::Artifact::Zap do
|
|||||||
it "can zap" do
|
it "can zap" do
|
||||||
Hbc::FakeSystemCommand.expects_command(
|
Hbc::FakeSystemCommand.expects_command(
|
||||||
sudo(%w[/bin/rm -rf --],
|
sudo(%w[/bin/rm -rf --],
|
||||||
Pathname.new("/permissible/absolute/path"),
|
absolute_path,
|
||||||
Pathname.new("~/permissible/path/with/tilde").expand_path),
|
path_with_tilde,
|
||||||
|
glob_path1,
|
||||||
|
glob_path2),
|
||||||
)
|
)
|
||||||
|
|
||||||
subject
|
subject
|
||||||
@ -248,8 +260,10 @@ describe Hbc::Artifact::Zap do
|
|||||||
it "can zap" do
|
it "can zap" do
|
||||||
Hbc::FakeSystemCommand.expects_command(
|
Hbc::FakeSystemCommand.expects_command(
|
||||||
sudo(%w[/bin/rm -rf --],
|
sudo(%w[/bin/rm -rf --],
|
||||||
Pathname.new("/permissible/absolute/path"),
|
absolute_path,
|
||||||
Pathname.new("~/permissible/path/with/tilde").expand_path),
|
path_with_tilde,
|
||||||
|
glob_path1,
|
||||||
|
glob_path2),
|
||||||
)
|
)
|
||||||
|
|
||||||
subject
|
subject
|
||||||
@ -258,15 +272,23 @@ describe Hbc::Artifact::Zap do
|
|||||||
|
|
||||||
context "when using rmdir" do
|
context "when using rmdir" do
|
||||||
let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-zap-rmdir.rb") }
|
let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-zap-rmdir.rb") }
|
||||||
let(:dir_pathname) { Pathname.new("#{TEST_FIXTURE_DIR}/cask/empty_directory") }
|
let(:empty_directory_path) { Pathname.new("#{TEST_TMPDIR}/empty_directory_path") }
|
||||||
|
|
||||||
|
before(:each) do
|
||||||
|
empty_directory_path.mkdir
|
||||||
|
end
|
||||||
|
|
||||||
|
after(:each) do
|
||||||
|
empty_directory_path.rmdir
|
||||||
|
end
|
||||||
|
|
||||||
it "can zap" do
|
it "can zap" do
|
||||||
Hbc::FakeSystemCommand.expects_command(
|
Hbc::FakeSystemCommand.expects_command(
|
||||||
sudo(%w[/bin/rm -f --], dir_pathname.join(".DS_Store")),
|
sudo(%w[/bin/rm -f --], empty_directory_path/".DS_Store"),
|
||||||
)
|
)
|
||||||
|
|
||||||
Hbc::FakeSystemCommand.expects_command(
|
Hbc::FakeSystemCommand.expects_command(
|
||||||
sudo(%w[/bin/rmdir --], dir_pathname),
|
sudo(%w[/bin/rmdir --], empty_directory_path),
|
||||||
)
|
)
|
||||||
|
|
||||||
subject
|
subject
|
||||||
|
|||||||
@ -11,10 +11,11 @@ cask 'with-installable' do
|
|||||||
quit: 'my.fancy.package.app',
|
quit: 'my.fancy.package.app',
|
||||||
login_item: 'Fancy',
|
login_item: 'Fancy',
|
||||||
delete: [
|
delete: [
|
||||||
'/permissible/absolute/path',
|
"#{TEST_TMPDIR}/absolute_path",
|
||||||
'~/permissible/path/with/tilde',
|
'~/path_with_tilde',
|
||||||
|
"#{TEST_TMPDIR}/glob_path*",
|
||||||
'impermissible/relative/path',
|
'impermissible/relative/path',
|
||||||
'/another/impermissible/../relative/path',
|
'/another/impermissible/../relative/path',
|
||||||
],
|
],
|
||||||
rmdir: "#{TEST_FIXTURE_DIR}/cask/empty_directory"
|
rmdir: "#{TEST_TMPDIR}/empty_directory_path"
|
||||||
end
|
end
|
||||||
|
|||||||
@ -8,8 +8,9 @@ cask 'with-uninstall-delete' do
|
|||||||
pkg 'Fancy.pkg'
|
pkg 'Fancy.pkg'
|
||||||
|
|
||||||
uninstall delete: [
|
uninstall delete: [
|
||||||
'/permissible/absolute/path',
|
"#{TEST_TMPDIR}/absolute_path",
|
||||||
'~/permissible/path/with/tilde',
|
'~/path_with_tilde',
|
||||||
|
"#{TEST_TMPDIR}/glob_path*",
|
||||||
'impermissible/relative/path',
|
'impermissible/relative/path',
|
||||||
'/another/impermissible/../relative/path',
|
'/another/impermissible/../relative/path',
|
||||||
]
|
]
|
||||||
|
|||||||
@ -7,5 +7,5 @@ cask 'with-uninstall-rmdir' do
|
|||||||
|
|
||||||
pkg 'MyFancyPkg/Fancy.pkg'
|
pkg 'MyFancyPkg/Fancy.pkg'
|
||||||
|
|
||||||
uninstall rmdir: "#{TEST_FIXTURE_DIR}/cask/empty_directory"
|
uninstall rmdir: "#{TEST_TMPDIR}/empty_directory_path"
|
||||||
end
|
end
|
||||||
|
|||||||
@ -8,8 +8,9 @@ cask 'with-uninstall-trash' do
|
|||||||
pkg 'Fancy.pkg'
|
pkg 'Fancy.pkg'
|
||||||
|
|
||||||
uninstall trash: [
|
uninstall trash: [
|
||||||
'/permissible/absolute/path',
|
"#{TEST_TMPDIR}/absolute_path",
|
||||||
'~/permissible/path/with/tilde',
|
'~/path_with_tilde',
|
||||||
|
"#{TEST_TMPDIR}/glob_path*",
|
||||||
'impermissible/relative/path',
|
'impermissible/relative/path',
|
||||||
'/another/impermissible/../relative/path',
|
'/another/impermissible/../relative/path',
|
||||||
]
|
]
|
||||||
|
|||||||
@ -8,8 +8,9 @@ cask 'with-zap-delete' do
|
|||||||
pkg 'Fancy.pkg'
|
pkg 'Fancy.pkg'
|
||||||
|
|
||||||
zap delete: [
|
zap delete: [
|
||||||
'/permissible/absolute/path',
|
"#{TEST_TMPDIR}/absolute_path",
|
||||||
'~/permissible/path/with/tilde',
|
'~/path_with_tilde',
|
||||||
|
"#{TEST_TMPDIR}/glob_path*",
|
||||||
'impermissible/relative/path',
|
'impermissible/relative/path',
|
||||||
'/another/impermissible/../relative/path',
|
'/another/impermissible/../relative/path',
|
||||||
]
|
]
|
||||||
|
|||||||
@ -7,5 +7,5 @@ cask 'with-zap-rmdir' do
|
|||||||
|
|
||||||
pkg 'MyFancyPkg/Fancy.pkg'
|
pkg 'MyFancyPkg/Fancy.pkg'
|
||||||
|
|
||||||
zap rmdir: "#{TEST_FIXTURE_DIR}/cask/empty_directory"
|
zap rmdir: "#{TEST_TMPDIR}/empty_directory_path"
|
||||||
end
|
end
|
||||||
|
|||||||
@ -8,8 +8,9 @@ cask 'with-zap-trash' do
|
|||||||
pkg 'Fancy.pkg'
|
pkg 'Fancy.pkg'
|
||||||
|
|
||||||
zap trash: [
|
zap trash: [
|
||||||
'/permissible/absolute/path',
|
"#{TEST_TMPDIR}/absolute_path",
|
||||||
'~/permissible/path/with/tilde',
|
'~/path_with_tilde',
|
||||||
|
"#{TEST_TMPDIR}/glob_path*",
|
||||||
'impermissible/relative/path',
|
'impermissible/relative/path',
|
||||||
'/another/impermissible/../relative/path',
|
'/another/impermissible/../relative/path',
|
||||||
]
|
]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user