cask uninstall script: allow tilde expansion to '$HOME'

This commit is contained in:
Michael Cho 2021-03-21 19:32:15 -07:00
parent 3bfa59bd2f
commit a0261c4b39
3 changed files with 46 additions and 0 deletions

View File

@ -30,6 +30,7 @@ module Cask
def staged_path_join_executable(path)
path = Pathname(path)
path = path.expand_path if path.to_s.start_with?("~")
absolute_path = if path.absolute?
path

View File

@ -90,6 +90,30 @@ describe Cask::Cmd::Uninstall, :cask do
expect(cask).not_to be_installed
end
context "when Casks use script path with `~` as `HOME`" do
let(:home_dir) { mktmpdir }
let(:app) { Pathname.new("#{home_dir}/MyFancyApp.app") }
let(:cask) { Cask::CaskLoader.load(cask_path("with-uninstall-script-user-relative")) }
before do
ENV["HOME"] = home_dir
end
it "can still uninstall them" do
Cask::Installer.new(cask).install
expect(cask).to be_installed
expect(app).to exist
expect {
described_class.run("with-uninstall-script-user-relative")
}.not_to raise_error
expect(cask).not_to be_installed
expect(app).not_to exist
end
end
describe "when multiple versions of a cask are installed" do
let(:token) { "versioned-cask" }
let(:first_installed_version) { "1.2.3" }

View File

@ -0,0 +1,21 @@
cask "with-uninstall-script-user-relative" do
version "1.2.3"
sha256 "5633c3a0f2e572cbf021507dec78c50998b398c343232bdfc7e26221d0a5db4d"
url "file://#{TEST_FIXTURE_DIR}/cask/MyFancyApp.zip"
homepage "https://brew.sh/MyFancyApp"
app "MyFancyApp/MyFancyApp.app", target: "~/MyFancyApp.app"
postflight do
IO.write "#{ENV["HOME"]}/MyFancyApp.app/uninstall.sh", <<~SH
#!/bin/sh
/bin/rm -r "#{ENV["HOME"]}/MyFancyApp.app"
SH
end
uninstall script: {
executable: "~/MyFancyApp.app/uninstall.sh",
sudo: false,
}
end