summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2021-06-17 14:20:23 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2021-06-21 17:07:23 -0700
commit3e30faf4b7e171bca29f3a079ed53ca0e4e058c0 (patch)
treee1b3fbaf2c858149714ef18d46f1d6fb0b61d941
parentf88e0578fddabd9ac235d0709bc0a1d41d4a6b28 (diff)
downloadchef-3e30faf4b7e171bca29f3a079ed53ca0e4e058c0.tar.gz
eliminate some File.exists? from the file provider
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r--lib/chef/provider/file.rb4
-rw-r--r--spec/support/shared/unit/provider/file.rb10
2 files changed, 4 insertions, 10 deletions
diff --git a/lib/chef/provider/file.rb b/lib/chef/provider/file.rb
index 59724a8340..96f6eef061 100644
--- a/lib/chef/provider/file.rb
+++ b/lib/chef/provider/file.rb
@@ -157,7 +157,7 @@ class Chef
end
action :delete do
- if ::File.exists?(new_resource.path)
+ if ::File.exist?(new_resource.path)
converge_by("delete file #{new_resource.path}") do
do_backup unless file_class.symlink?(new_resource.path)
::File.delete(new_resource.path)
@@ -393,7 +393,7 @@ class Chef
# a nil tempfile is okay, means the resource has no content or no new content
return if tempfile.nil?
# but a tempfile that has no path or doesn't exist should not happen
- if tempfile.path.nil? || !::File.exists?(tempfile.path)
+ if tempfile.path.nil? || !::File.exist?(tempfile.path)
raise "#{ChefUtils::Dist::Infra::CLIENT} is confused, trying to deploy a file that has no path or does not exist..."
end
diff --git a/spec/support/shared/unit/provider/file.rb b/spec/support/shared/unit/provider/file.rb
index dccfd5d027..3a717e91c1 100644
--- a/spec/support/shared/unit/provider/file.rb
+++ b/spec/support/shared/unit/provider/file.rb
@@ -43,7 +43,6 @@ end
def setup_normal_file
[ resource_path, normalized_path, windows_path].each do |path|
allow(File).to receive(:file?).with(path).and_return(true)
- allow(File).to receive(:exists?).with(path).and_return(true)
allow(File).to receive(:exist?).with(path).and_return(true)
allow(File).to receive(:directory?).with(path).and_return(false)
allow(File).to receive(:writable?).with(path).and_return(true)
@@ -57,7 +56,6 @@ def setup_missing_file
[ resource_path, normalized_path, windows_path].each do |path|
allow(File).to receive(:file?).with(path).and_return(false)
allow(File).to receive(:realpath?).with(path).and_return(resource_path)
- allow(File).to receive(:exists?).with(path).and_return(false)
allow(File).to receive(:exist?).with(path).and_return(false)
allow(File).to receive(:directory?).with(path).and_return(false)
allow(File).to receive(:writable?).with(path).and_return(false)
@@ -70,7 +68,6 @@ def setup_symlink
[ resource_path, normalized_path, windows_path].each do |path|
allow(File).to receive(:file?).with(path).and_return(true)
allow(File).to receive(:realpath?).with(path).and_return(normalized_path)
- allow(File).to receive(:exists?).with(path).and_return(true)
allow(File).to receive(:exist?).with(path).and_return(true)
allow(File).to receive(:directory?).with(path).and_return(false)
allow(File).to receive(:writable?).with(path).and_return(true)
@@ -84,7 +81,6 @@ def setup_unwritable_file
[ resource_path, normalized_path, windows_path].each do |path|
allow(File).to receive(:file?).with(path).and_return(false)
allow(File).to receive(:realpath?).with(path).and_raise(Errno::ENOENT)
- allow(File).to receive(:exists?).with(path).and_return(true)
allow(File).to receive(:exist?).with(path).and_return(true)
allow(File).to receive(:directory?).with(path).and_return(false)
allow(File).to receive(:writable?).with(path).and_return(false)
@@ -97,7 +93,6 @@ def setup_missing_enclosing_directory
[ resource_path, normalized_path, windows_path].each do |path|
allow(File).to receive(:file?).with(path).and_return(false)
allow(File).to receive(:realpath?).with(path).and_raise(Errno::ENOENT)
- allow(File).to receive(:exists?).with(path).and_return(false)
allow(File).to receive(:exist?).with(path).and_return(false)
allow(File).to receive(:directory?).with(path).and_return(false)
allow(File).to receive(:writable?).with(path).and_return(false)
@@ -138,7 +133,6 @@ shared_examples_for Chef::Provider::File do
before(:each) do
allow(content).to receive(:tempfile).and_return(tempfile)
allow(File).to receive(:exist?).with(tempfile.path).and_call_original
- allow(File).to receive(:exists?).with(tempfile.path).and_call_original
end
after do
@@ -547,7 +541,7 @@ shared_examples_for Chef::Provider::File do
provider.load_current_resource
tempfile = double("Tempfile", path: "/tmp/foo-bar-baz")
allow(content).to receive(:tempfile).and_return(tempfile)
- expect(File).to receive(:exists?).with("/tmp/foo-bar-baz").and_return(true)
+ expect(File).to receive(:exist?).with("/tmp/foo-bar-baz").and_return(true)
expect(tempfile).to receive(:close).once
expect(tempfile).to receive(:unlink).once
end
@@ -630,7 +624,7 @@ shared_examples_for Chef::Provider::File do
it "raises an exception when the content object returns a tempfile that does not exist" do
tempfile = double("Tempfile", path: "/tmp/foo-bar-baz")
expect(provider.send(:content)).to receive(:tempfile).at_least(:once).and_return(tempfile)
- expect(File).to receive(:exists?).with("/tmp/foo-bar-baz").and_return(false)
+ expect(File).to receive(:exist?).with("/tmp/foo-bar-baz").and_return(false)
expect { provider.send(:do_contents_changes) }.to raise_error(RuntimeError)
end
end