summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/chef/application/apply.rb4
-rw-r--r--lib/chef/provider/ifconfig.rb31
-rw-r--r--lib/chef/provider/link.rb2
-rw-r--r--lib/chef/provider/whyrun_safe_ruby_block.rb2
-rw-r--r--lib/chef/win32/api/file.rb6
5 files changed, 22 insertions, 23 deletions
diff --git a/lib/chef/application/apply.rb b/lib/chef/application/apply.rb
index ab35b35389..ea9154c6f2 100644
--- a/lib/chef/application/apply.rb
+++ b/lib/chef/application/apply.rb
@@ -134,6 +134,10 @@ class Chef::Application::Apply < Chef::Application
@recipe_text = STDIN.read
temp_recipe_file
else
+ if !ARGV[0]
+ puts opt_parser
+ Chef::Application.exit! "No recipe file provided", 1
+ end
@recipe_filename = ARGV[0]
@recipe_text,@recipe_fh = read_recipe_file @recipe_filename
end
diff --git a/lib/chef/provider/ifconfig.rb b/lib/chef/provider/ifconfig.rb
index 31f88e5406..ac52100b56 100644
--- a/lib/chef/provider/ifconfig.rb
+++ b/lib/chef/provider/ifconfig.rb
@@ -19,6 +19,7 @@
require 'chef/log'
require 'chef/mixin/command'
require 'chef/provider'
+require 'chef/resource/file'
require 'chef/exceptions'
require 'erb'
@@ -109,11 +110,11 @@ class Chef
:command => command
)
Chef::Log.info("#{@new_resource} added")
- # Write out the config files
- generate_config
end
end
end
+ # Write out the config files
+ generate_config
end
def action_enable
@@ -140,12 +141,12 @@ class Chef
run_command(
:command => command
)
- delete_config
Chef::Log.info("#{@new_resource} deleted")
end
else
Chef::Log.debug("#{@new_resource} does not exist - nothing to do")
end
+ delete_config
end
def action_disable
@@ -168,27 +169,25 @@ class Chef
! @config_template.nil? and ! @config_path.nil?
end
+ def resource_for_config(path)
+ Chef::Resource::File.new(path, run_context)
+ end
+
def generate_config
return unless can_generate_config?
b = binding
template = ::ERB.new(@config_template)
- converge_by ("generate configuration file : #{@config_path}") do
- network_file = ::File.new(@config_path, "w")
- network_file.puts(template.result(b))
- network_file.close
- end
- Chef::Log.info("#{@new_resource} created configuration file")
+ config = resource_for_config(@config_path)
+ config.content(template.result(b))
+ config.run_action(:create)
+ @new_resource.updated_by_last_action(true) if config.updated?
end
def delete_config
return unless can_generate_config?
- require 'fileutils'
- if ::File.exist?(@config_path)
- converge_by ("delete the #{@config_path}") do
- FileUtils.rm_f(@config_path, :verbose => false)
- end
- end
- Chef::Log.info("#{@new_resource} deleted configuration file")
+ config = resource_for_config(@config_path)
+ config.run_action(:delete)
+ @new_resource.updated_by_last_action(true) if config.updated?
end
private
diff --git a/lib/chef/provider/link.rb b/lib/chef/provider/link.rb
index d6602c2e03..af2fe4a84f 100644
--- a/lib/chef/provider/link.rb
+++ b/lib/chef/provider/link.rb
@@ -83,7 +83,7 @@ class Chef
end
def canonicalize(path)
- Chef::Platform.windows? ? path.gsub('/', '\\') : path
+ Chef::Util::PathHelper.canonical_path(path)
end
def action_create
diff --git a/lib/chef/provider/whyrun_safe_ruby_block.rb b/lib/chef/provider/whyrun_safe_ruby_block.rb
index 4b491a4f60..e5f35debd7 100644
--- a/lib/chef/provider/whyrun_safe_ruby_block.rb
+++ b/lib/chef/provider/whyrun_safe_ruby_block.rb
@@ -19,7 +19,7 @@
class Chef
class Provider
class WhyrunSafeRubyBlock < Chef::Provider::RubyBlock
- def action_create
+ def action_run
@new_resource.block.call
@new_resource.updated_by_last_action(true)
@run_context.events.resource_update_applied(@new_resource, :create, "execute the whyrun_safe_ruby_block #{@new_resource.name}")
diff --git a/lib/chef/win32/api/file.rb b/lib/chef/win32/api/file.rb
index 7a8dafd8b5..da9713e119 100644
--- a/lib/chef/win32/api/file.rb
+++ b/lib/chef/win32/api/file.rb
@@ -459,11 +459,7 @@ BOOL WINAPI DeviceIoControl(
# to be passed to the *W vesion of WinAPI File
# functions
def encode_path(path)
- (path_prepender << path.gsub(::File::SEPARATOR, ::File::ALT_SEPARATOR)).to_wstring
- end
-
- def path_prepender
- "\\\\?\\"
+ Chef::Util::PathHelper.canonical_path(path).to_wstring
end
# retrieves a file search handle and passes it