Merge pull request #5804 from reitermarkus/executable-path

Use same logic for `installer script:` and `uninstall script:`.
This commit is contained in:
Markus Reiter 2019-03-03 06:56:55 +01:00 committed by GitHub
commit 0b2eaa29fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 22 deletions

View File

@ -20,6 +20,24 @@ module Cask
@dirmethod ||= "#{dsl_key}dir".to_sym
end
def staged_path_join_executable(path)
path = Pathname(path)
absolute_path = if path.absolute?
path
else
cask.staged_path.join(path)
end
FileUtils.chmod "+x", absolute_path if absolute_path.exist? && !absolute_path.executable?
if absolute_path.exist?
absolute_path
else
path
end
end
def <=>(other)
return unless other.class < AbstractArtifact
return 0 if self.class == other.class

View File

@ -243,9 +243,10 @@ module Cask
ohai "Running uninstall script #{executable}"
raise CaskInvalidError.new(cask, "#{stanza} :#{directive_name} without :executable.") if executable.nil?
executable_path = cask.staged_path.join(executable)
executable_path = staged_path_join_executable(executable)
unless executable_path.exist?
if (executable_path.absolute? && !executable_path.exist?) ||
(!executable_path.absolute? && (which executable_path).nil?)
message = "uninstall script #{executable} does not exist"
raise CaskError, "#{message}." unless force
@ -253,7 +254,6 @@ module Cask
return
end
command.run("/bin/chmod", args: ["--", "+x", executable_path])
command.run(executable_path, script_arguments)
sleep 1
end

View File

@ -26,22 +26,10 @@ module Cask
def install_phase(command: nil, **_)
ohai "Running #{self.class.dsl_key} script '#{path}'"
absolute_path = if path.absolute?
path
else
cask.staged_path.join(path)
end
FileUtils.chmod "+x", absolute_path if absolute_path.exist? && !absolute_path.executable?
executable = if absolute_path.exist?
absolute_path
else
path
end
executable_path = staged_path_join_executable(path)
command.run!(
executable,
executable_path,
**args,
env: { "PATH" => PATH.new(
HOMEBREW_PREFIX/"bin", HOMEBREW_PREFIX/"sbin", ENV["PATH"]

View File

@ -228,11 +228,6 @@ shared_examples "#uninstall_phase or #zap_phase" do
it "is supported" do
allow(fake_system_command).to receive(:run).with(any_args).and_call_original
expect(fake_system_command).to receive(:run).with(
"/bin/chmod",
args: ["--", "+x", script_pathname],
)
expect(fake_system_command).to receive(:run).with(
cask.staged_path.join("MyFancyPkg", "FancyUninstaller.tool"),
args: ["--please"],