summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Mundrawala <jdmundrawala@gmail.com>2015-02-11 17:23:43 -0800
committerBryan McLellan <btm@opscode.com>2015-02-17 09:24:45 -0500
commitc020ea0c2a84ff532bdbf55dac3eab34189ede8e (patch)
tree830ba3eaaff4eecfa110e50121c76a652517d3f5
parente6981adeb7b1cb5622249d301d6bb3377dc89659 (diff)
downloadchef-c020ea0c2a84ff532bdbf55dac3eab34189ede8e.tar.gz
Update directory resource to use FileAccessControl to check if file is writable
-rw-r--r--lib/chef/provider/directory.rb6
-rw-r--r--spec/unit/provider/directory_spec.rb8
2 files changed, 7 insertions, 7 deletions
diff --git a/lib/chef/provider/directory.rb b/lib/chef/provider/directory.rb
index c9c3d466b9..416393ac60 100644
--- a/lib/chef/provider/directory.rb
+++ b/lib/chef/provider/directory.rb
@@ -61,7 +61,7 @@ class Chef
is_parent_writable = lambda do |base_dir|
base_dir = ::File.dirname(base_dir)
if ::File.exists?(base_dir)
- ::File.writable?(base_dir)
+ Chef::FileAccessControl.writable?(base_dir)
else
is_parent_writable.call(base_dir)
end
@@ -71,7 +71,7 @@ class Chef
# in why run mode & parent directory does not exist no permissions check is required
# If not in why run, permissions must be valid and we rely on prior assertion that dir exists
if !whyrun_mode? || ::File.exists?(parent_directory)
- ::File.writable?(parent_directory)
+ Chef::FileAccessControl.writable?(parent_directory)
else
true
end
@@ -84,7 +84,7 @@ class Chef
requirements.assert(:delete) do |a|
a.assertion do
if ::File.exists?(@new_resource.path)
- ::File.directory?(@new_resource.path) && ::File.writable?(@new_resource.path)
+ ::File.directory?(@new_resource.path) && Chef::FileAccessControl.writable?(@new_resource.path)
else
true
end
diff --git a/spec/unit/provider/directory_spec.rb b/spec/unit/provider/directory_spec.rb
index 98f860bc75..13c57bfe56 100644
--- a/spec/unit/provider/directory_spec.rb
+++ b/spec/unit/provider/directory_spec.rb
@@ -112,7 +112,7 @@ describe Chef::Provider::Directory do
expect(File).to receive(:exists?).with('/path/to').ordered.and_return(false)
expect(File).to receive(:exists?).with('/path').ordered.and_return(true)
- expect(File).to receive(:writable?).with('/path').ordered.and_return(true)
+ expect(Chef::FileAccessControl).to receive(:writable?).with('/path').ordered.and_return(true)
expect(File).to receive(:exists?).with(@new_resource.path).ordered.and_return(false)
expect(FileUtils).to receive(:mkdir_p).with(@new_resource.path).and_return(true)
@@ -137,7 +137,7 @@ describe Chef::Provider::Directory do
stub_file_cstats
@new_resource.path "/tmp/foo"
expect(File).to receive(:directory?).at_least(:once).and_return(true)
- expect(File).to receive(:writable?).with("/tmp").and_return(true)
+ expect(Chef::FileAccessControl).to receive(:writable?).with("/tmp").and_return(true)
expect(File).to receive(:exists?).at_least(:once).and_return(true)
expect(Dir).not_to receive(:mkdir).with(@new_resource.path)
expect(@directory).to receive(:do_acl_changes)
@@ -146,14 +146,14 @@ describe Chef::Provider::Directory do
it "should delete the directory if it exists, and is writable with action_delete" do
expect(File).to receive(:directory?).and_return(true)
- expect(File).to receive(:writable?).once.and_return(true)
+ expect(Chef::FileAccessControl).to receive(:writable?).once.and_return(true)
expect(Dir).to receive(:delete).with(@new_resource.path).once.and_return(true)
@directory.run_action(:delete)
end
it "should raise an exception if it cannot delete the directory due to bad permissions" do
allow(File).to receive(:exists?).and_return(true)
- allow(File).to receive(:writable?).and_return(false)
+ allow(Chef::FileAccessControl).to receive(:writable?).and_return(false)
expect { @directory.run_action(:delete) }.to raise_error(RuntimeError)
end