From 5a2bab642653a715cd73be1f04062e37322b82a7 Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Tue, 26 Jan 2021 08:21:19 -0800 Subject: Replace deprecated File.exists? with File.exist? in more places Just some boring cleanup Signed-off-by: Tim Smith --- lib/chef/dsl/reboot_pending.rb | 2 +- lib/chef/file_access_control/windows.rb | 8 ++++---- lib/chef/file_cache.rb | 8 ++++---- .../formatters/error_inspectors/resource_failure_inspector.rb | 2 +- lib/chef/handler/json_file.rb | 2 +- spec/unit/dsl/reboot_pending_spec.rb | 4 ++-- .../error_inspectors/resource_failure_inspector_spec.rb | 4 ++-- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/chef/dsl/reboot_pending.rb b/lib/chef/dsl/reboot_pending.rb index 19d3a6b0bd..5a6f8ee219 100644 --- a/lib/chef/dsl/reboot_pending.rb +++ b/lib/chef/dsl/reboot_pending.rb @@ -47,7 +47,7 @@ class Chef registry_key_exists?('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending') elsif platform?("ubuntu") # This should work for Debian as well if update-notifier-common happens to be installed. We need an API for that. - File.exists?("/var/run/reboot-required") + File.exist?("/var/run/reboot-required") else false end diff --git a/lib/chef/file_access_control/windows.rb b/lib/chef/file_access_control/windows.rb index cc1b96a84d..744c5f7466 100644 --- a/lib/chef/file_access_control/windows.rb +++ b/lib/chef/file_access_control/windows.rb @@ -33,7 +33,7 @@ class Chef module ClassMethods # We want to mix these in as class methods def writable?(path) - ::File.exists?(path) && Chef::ReservedNames::Win32::File.file_access_check( + ::File.exist?(path) && Chef::ReservedNames::Win32::File.file_access_check( path, Chef::ReservedNames::Win32::API::Security::FILE_GENERIC_WRITE ) end @@ -136,7 +136,7 @@ class Chef end def should_update_dacl? - return true unless ::File.exists?(file) || ::File.symlink?(file) + return true unless ::File.exist?(file) || ::File.symlink?(file) dacl = target_dacl existing_dacl = existing_descriptor.dacl @@ -170,7 +170,7 @@ class Chef end def should_update_group? - return true unless ::File.exists?(file) || ::File.symlink?(file) + return true unless ::File.exist?(file) || ::File.symlink?(file) (group = target_group) && (group != existing_descriptor.group) end @@ -190,7 +190,7 @@ class Chef end def should_update_owner? - return true unless ::File.exists?(file) || ::File.symlink?(file) + return true unless ::File.exist?(file) || ::File.symlink?(file) (owner = target_owner) && (owner != existing_descriptor.owner) end diff --git a/lib/chef/file_cache.rb b/lib/chef/file_cache.rb index 22060869da..851234596a 100644 --- a/lib/chef/file_cache.rb +++ b/lib/chef/file_cache.rb @@ -79,7 +79,7 @@ class Chef file_path_array = File.split(path) file_name = file_path_array.pop - if File.exists?(file) && File.writable?(file) + if File.exist?(file) && File.writable?(file) FileUtils.mv( file, File.join(create_cache_path(File.join(file_path_array), true), file_name) @@ -112,7 +112,7 @@ class Chef } ) cache_path = create_cache_path(path, false) - raise Chef::Exceptions::FileNotFound, "Cannot find #{cache_path} for #{path}!" unless File.exists?(cache_path) + raise Chef::Exceptions::FileNotFound, "Cannot find #{cache_path} for #{path}!" unless File.exist?(cache_path) if read File.read(cache_path) @@ -139,7 +139,7 @@ class Chef } ) cache_path = create_cache_path(path, false) - if File.exists?(cache_path) + if File.exist?(cache_path) File.unlink(cache_path) end true @@ -186,7 +186,7 @@ class Chef } ) full_path = create_cache_path(path, false) - if File.exists?(full_path) + if File.exist?(full_path) true else false diff --git a/lib/chef/formatters/error_inspectors/resource_failure_inspector.rb b/lib/chef/formatters/error_inspectors/resource_failure_inspector.rb index 905a438f56..8ddae24e6d 100644 --- a/lib/chef/formatters/error_inspectors/resource_failure_inspector.rb +++ b/lib/chef/formatters/error_inspectors/resource_failure_inspector.rb @@ -66,7 +66,7 @@ class Chef @snippet ||= begin if (file = parse_source) && (line = parse_line(file)) - return nil unless ::File.exists?(file) + return nil unless ::File.exist?(file) lines = IO.readlines(file) diff --git a/lib/chef/handler/json_file.rb b/lib/chef/handler/json_file.rb index 6318c30d74..998f2b0e0e 100644 --- a/lib/chef/handler/json_file.rb +++ b/lib/chef/handler/json_file.rb @@ -51,7 +51,7 @@ class Chef end def build_report_dir - unless File.exists?(config[:path]) + unless File.exist?(config[:path]) FileUtils.mkdir_p(config[:path]) File.chmod(00700, config[:path]) end diff --git a/spec/unit/dsl/reboot_pending_spec.rb b/spec/unit/dsl/reboot_pending_spec.rb index 4fed3be442..3ad1be9e38 100644 --- a/spec/unit/dsl/reboot_pending_spec.rb +++ b/spec/unit/dsl/reboot_pending_spec.rb @@ -57,12 +57,12 @@ describe Chef::DSL::RebootPending do end it "should return true if /var/run/reboot-required exists" do - allow(File).to receive(:exists?).with("/var/run/reboot-required").and_return(true) + allow(File).to receive(:exist?).with("/var/run/reboot-required").and_return(true) expect(recipe.reboot_pending?).to be_truthy end it "should return false if /var/run/reboot-required does not exist" do - allow(File).to receive(:exists?).with("/var/run/reboot-required").and_return(false) + allow(File).to receive(:exist?).with("/var/run/reboot-required").and_return(false) expect(recipe.reboot_pending?).to be_falsey end end diff --git a/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb b/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb index 9d8fb050da..6693eded03 100644 --- a/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb +++ b/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb @@ -115,7 +115,7 @@ describe Chef::Formatters::ErrorInspectors::ResourceFailureInspector do # fake code to run through #recipe_snippet source_file = [ "if true", "var = non_existent", "end" ] allow(IO).to receive(:readlines).and_return(source_file) - allow(File).to receive(:exists?).and_return(true) + allow(File).to receive(:exist?).and_return(true) end it "parses a Windows path" do @@ -141,7 +141,7 @@ describe Chef::Formatters::ErrorInspectors::ResourceFailureInspector do context "when the recipe file does not exist" do before do - allow(File).to receive(:exists?).and_return(false) + allow(File).to receive(:exist?).and_return(false) allow(IO).to receive(:readlines).and_raise(Errno::ENOENT) end -- cgit v1.2.1