summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2019-03-04 10:16:59 -0800
committerGitHub <noreply@github.com>2019-03-04 10:16:59 -0800
commit6baaaeb0de2d7036deabba99da8a3c6e95fb8f3c (patch)
treed44383afe2ca9443776c5d68642d502998fa5af2
parentf4ec9c96df1dd3bdc8ce9ea6d18c81e37fe2c54b (diff)
parent0e5e158beaa310ce21f0254d732a6f5d8235b1c7 (diff)
downloadchef-6baaaeb0de2d7036deabba99da8a3c6e95fb8f3c.tar.gz
Merge pull request #8262 from chef/share_14
windows_share: Improve path comparison to prevent convering on each run
-rw-r--r--lib/chef/resource/windows_share.rb15
1 files changed, 9 insertions, 6 deletions
diff --git a/lib/chef/resource/windows_share.rb b/lib/chef/resource/windows_share.rb
index 1fda67e820..07a65eb5ee 100644
--- a/lib/chef/resource/windows_share.rb
+++ b/lib/chef/resource/windows_share.rb
@@ -21,6 +21,7 @@
require "chef/resource"
require "chef/json_compat"
+require "chef/util/path_helper"
class Chef
class Resource
@@ -184,10 +185,12 @@ class Chef
converge_if_changed do
# you can't actually change the path so you have to delete the old share first
- delete_share if different_path?
-
- # powershell cmdlet for create is different than updates
- if current_resource.nil?
+ if different_path?
+ Chef::Log.debug("The path has changed so we will delete and recreate share")
+ delete_share
+ create_share
+ elsif current_resource.nil?
+ # powershell cmdlet for create is different than updates
Chef::Log.debug("The current resource is nil so we will create a new share")
create_share
else
@@ -215,7 +218,7 @@ class Chef
action_class do
def different_path?
return false if current_resource.nil? # going from nil to something isn't different for our concerns
- return false if current_resource.path == new_resource.path
+ return false if current_resource.path == Chef::Util::PathHelper.cleanpath(new_resource.path)
true
end
@@ -236,7 +239,7 @@ class Chef
def create_share
raise "#{new_resource.path} is missing or not a directory. Shares cannot be created if the path doesn't first exist." unless ::File.directory? new_resource.path
- share_cmd = "New-SmbShare -Name '#{new_resource.share_name}' -Path '#{new_resource.path}' -Description '#{new_resource.description}' -ConcurrentUserLimit #{new_resource.concurrent_user_limit} -CATimeout #{new_resource.ca_timeout} -EncryptData:#{bool_string(new_resource.encrypt_data)} -ContinuouslyAvailable:#{bool_string(new_resource.continuously_available)}"
+ share_cmd = "New-SmbShare -Name '#{new_resource.share_name}' -Path '#{Chef::Util::PathHelper.cleanpath(new_resource.path)}' -Description '#{new_resource.description}' -ConcurrentUserLimit #{new_resource.concurrent_user_limit} -CATimeout #{new_resource.ca_timeout} -EncryptData:#{bool_string(new_resource.encrypt_data)} -ContinuouslyAvailable:#{bool_string(new_resource.continuously_available)}"
share_cmd << " -ScopeName #{new_resource.scope_name}" unless new_resource.scope_name == "*" # passing * causes the command to fail
share_cmd << " -Temporary:#{bool_string(new_resource.temporary)}" if new_resource.temporary # only set true