lib/vagrant/plugin/v2/trigger.rb in vagrant-unbundled-2.1.2.0 vs lib/vagrant/plugin/v2/trigger.rb in vagrant-unbundled-2.1.4.0
- old
+ new
@@ -123,15 +123,15 @@
if trigger.warn
warn(trigger.warn)
end
if trigger.run
- run(trigger.run, trigger.on_error)
+ run(trigger.run, trigger.on_error, trigger.exit_codes)
end
if trigger.run_remote
- run_remote(trigger.run_remote, trigger.on_error)
+ run_remote(trigger.run_remote, trigger.on_error, trigger.exit_codes)
end
end
end
# Prints the given message at info level for a trigger
@@ -149,18 +149,19 @@
end
# Runs a script on a guest
#
# @param [Provisioners::Shell::Config] config A Shell provisioner config
- def run(config, on_error)
+ def run(config, on_error, exit_codes)
if config.inline
cmd = Shellwords.split(config.inline)
@machine.ui.detail(I18n.t("vagrant.trigger.run.inline", command: config.inline))
else
- cmd = File.expand_path(config.path, @env.root_path)
- cmd << " #{config.args.join(' ' )}" if config.args
+ cmd = File.expand_path(config.path, @env.root_path).shellescape
+ args = Array(config.args)
+ cmd << " #{args.join(' ')}" if !args.empty?
cmd = Shellwords.split(cmd)
@machine.ui.detail(I18n.t("vagrant.trigger.run.script", path: config.path))
end
@@ -186,10 +187,14 @@
options[:color] = :red if !config.keep_color
end
@machine.ui.detail(data, options)
end
+ if !exit_codes.include?(result.exit_code)
+ raise Errors::TriggersBadExitCodes,
+ code: result.exit_code
+ end
rescue => e
@machine.ui.error(I18n.t("vagrant.errors.triggers_run_fail"))
@machine.ui.error(e.message)
if on_error == :halt
@@ -203,10 +208,10 @@
end
# Runs a script on the guest
#
# @param [ShellProvisioner/Config] config A Shell provisioner config
- def run_remote(config, on_error)
+ def run_remote(config, on_error, exit_codes)
unless @machine.state.id == :running
if on_error == :halt
raise Errors::TriggersGuestNotRunning,
machine_name: @machine.name,
state: @machine.state.id