diff options
author | Tim Smith <tsmith84@gmail.com> | 2020-08-11 13:30:10 -0700 |
---|---|---|
committer | Tim Smith <tsmith84@gmail.com> | 2020-08-12 14:02:34 -0700 |
commit | 4848c89b7cc5e4a4d4fac7c8bff962f7df69f719 (patch) | |
tree | cf1bc6d0b30f226573da88158049f1334b6ce1bd /lib | |
parent | 798cac61accc035b51aaac25160bf1d5e9715252 (diff) | |
download | chef-exist.tar.gz |
File.exists? -> File.exist?exist
Update some of these methods
Signed-off-by: Tim Smith <tsmith@chef.io>
Diffstat (limited to 'lib')
25 files changed, 37 insertions, 37 deletions
diff --git a/lib/chef/api_client/registration.rb b/lib/chef/api_client/registration.rb index 02b7258fba..b05a2852a8 100644 --- a/lib/chef/api_client/registration.rb +++ b/lib/chef/api_client/registration.rb @@ -72,14 +72,14 @@ class Chef def assert_destination_writable! abs_path = File.expand_path(destination) - unless File.exists?(File.dirname(abs_path)) + unless File.exist?(File.dirname(abs_path)) begin FileUtils.mkdir_p(File.dirname(abs_path)) rescue Errno::EACCES raise Chef::Exceptions::CannotWritePrivateKey, "I can't create the configuration directory at #{File.dirname(abs_path)} - check permissions?" end end - if (File.exists?(abs_path) && !File.writable?(abs_path)) || !File.writable?(File.dirname(abs_path)) + if (File.exist?(abs_path) && !File.writable?(abs_path)) || !File.writable?(File.dirname(abs_path)) raise Chef::Exceptions::CannotWritePrivateKey, "I can't write your private key to #{abs_path} - check permissions?" end end diff --git a/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb b/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb index 81fcb6801c..0bb1ba1cac 100644 --- a/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb +++ b/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb @@ -76,7 +76,7 @@ class Chef # Write out .uploaded-cookbook-version.json # cookbook_file_path = File.join(file_path, cookbook_name) <- this should be the same as self.file_path - unless File.exists?(file_path) + unless File.exist?(file_path) FileUtils.mkdir_p(file_path) end uploaded_cookbook_version_path = File.join(file_path, Chef::Cookbook::CookbookVersionLoader::UPLOADED_COOKBOOK_VERSION_FILE) @@ -132,7 +132,7 @@ class Chef end def can_upload? - File.exists?(uploaded_cookbook_version_path) || children.size > 0 + File.exist?(uploaded_cookbook_version_path) || children.size > 0 end protected diff --git a/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry.rb b/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry.rb index 99deddae41..d01d24c360 100644 --- a/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry.rb +++ b/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry.rb @@ -137,7 +137,7 @@ class Chef end def exists? - File.exists?(file_path) && (parent.nil? || parent.can_have_child?(name, dir?)) + File.exist?(file_path) && (parent.nil? || parent.can_have_child?(name, dir?)) end def read diff --git a/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb b/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb index c384113a02..f7c00e7754 100644 --- a/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb +++ b/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb @@ -161,7 +161,7 @@ class Chef # members.json and org.json may be found. # def root_dir - existing_paths = root_paths.select { |path| File.exists?(path) } + existing_paths = root_paths.select { |path| File.exist?(path) } if existing_paths.size > 0 MultiplexedDir.new(existing_paths.map do |path| dir = FileSystemEntry.new(name, parent, path) @@ -184,7 +184,7 @@ class Chef return root_dir.child(name) end - paths = (child_paths[name] || []).select { |path| File.exists?(path) } + paths = (child_paths[name] || []).select { |path| File.exist?(path) } if paths.size == 0 return NonexistentFSObject.new(name, self) end diff --git a/lib/chef/chef_fs/file_system/repository/directory.rb b/lib/chef/chef_fs/file_system/repository/directory.rb index 8d227fd9d2..72a12d665f 100644 --- a/lib/chef/chef_fs/file_system/repository/directory.rb +++ b/lib/chef/chef_fs/file_system/repository/directory.rb @@ -151,7 +151,7 @@ class Chef end def exists? - File.exists?(file_path) + File.exist?(file_path) end protected diff --git a/lib/chef/chef_fs/file_system/repository/file_system_entry.rb b/lib/chef/chef_fs/file_system/repository/file_system_entry.rb index 85f62d57ae..902bc63038 100644 --- a/lib/chef/chef_fs/file_system/repository/file_system_entry.rb +++ b/lib/chef/chef_fs/file_system/repository/file_system_entry.rb @@ -122,7 +122,7 @@ class Chef end def exists? - File.exists?(file_path) && (parent.nil? || parent.can_have_child?(name, dir?)) + File.exist?(file_path) && (parent.nil? || parent.can_have_child?(name, dir?)) end def read diff --git a/lib/chef/environment.rb b/lib/chef/environment.rb index c121e37880..4f0c365443 100644 --- a/lib/chef/environment.rb +++ b/lib/chef/environment.rb @@ -254,11 +254,11 @@ class Chef js_file = File.join(Chef::Config[:environment_path], "#{name}.json") rb_file = File.join(Chef::Config[:environment_path], "#{name}.rb") - if File.exists?(js_file) + if File.exist?(js_file) # from_json returns object.class => json_class in the JSON. hash = Chef::JSONCompat.parse(IO.read(js_file)) from_hash(hash) - elsif File.exists?(rb_file) + elsif File.exist?(rb_file) environment = Chef::Environment.new environment.name(name) environment.from_file(rb_file) diff --git a/lib/chef/knife/bootstrap.rb b/lib/chef/knife/bootstrap.rb index e48fd71194..a3f7d3a23c 100644 --- a/lib/chef/knife/bootstrap.rb +++ b/lib/chef/knife/bootstrap.rb @@ -480,7 +480,7 @@ class Chef template = bootstrap_template # Use the template directly if it's a path to an actual file - if File.exists?(template) + if File.exist?(template) Chef::Log.trace("Using the specified bootstrap template: #{File.dirname(template)}") return template end @@ -495,7 +495,7 @@ class Chef template_file = Array(bootstrap_files).find do |bootstrap_template| Chef::Log.trace("Looking for bootstrap template in #{File.dirname(bootstrap_template)}") - File.exists?(bootstrap_template) + File.exist?(bootstrap_template) end unless template_file diff --git a/lib/chef/knife/cookbook_download.rb b/lib/chef/knife/cookbook_download.rb index 6c567684af..a07b519511 100644 --- a/lib/chef/knife/cookbook_download.rb +++ b/lib/chef/knife/cookbook_download.rb @@ -73,7 +73,7 @@ class Chef manifest = cookbook.cookbook_manifest basedir = File.join(config[:download_directory], "#{@cookbook_name}-#{cookbook.version}") - if File.exists?(basedir) + if File.exist?(basedir) if config[:force] Chef::Log.trace("Deleting #{basedir}") FileUtils.rm_rf(basedir) diff --git a/lib/chef/knife/cookbook_metadata.rb b/lib/chef/knife/cookbook_metadata.rb index 3a55e8ba9e..8d8970b1c1 100644 --- a/lib/chef/knife/cookbook_metadata.rb +++ b/lib/chef/knife/cookbook_metadata.rb @@ -62,7 +62,7 @@ class Chef def generate_metadata(cookbook) Array(config[:cookbook_path]).reverse_each do |path| file = File.expand_path(File.join(path, cookbook, "metadata.rb")) - if File.exists?(file) + if File.exist?(file) generate_metadata_from_file(cookbook, file) else validate_metadata_json(path, cookbook) diff --git a/lib/chef/knife/core/hashed_command_loader.rb b/lib/chef/knife/core/hashed_command_loader.rb index b88cededc0..c1d71f3edf 100644 --- a/lib/chef/knife/core/hashed_command_loader.rb +++ b/lib/chef/knife/core/hashed_command_loader.rb @@ -53,7 +53,7 @@ class Chef paths = manifest[KEY]["plugins_paths"][command] if paths && paths.is_a?(Array) # It is only an error if all the paths don't exist - if paths.all? { |sc| !File.exists?(sc) } + if paths.all? { |sc| !File.exist?(sc) } errors[command] = paths end end @@ -77,7 +77,7 @@ class Chef false else paths.each do |sc| - if File.exists?(sc) + if File.exist?(sc) Kernel.load sc else return false diff --git a/lib/chef/knife/exec.rb b/lib/chef/knife/exec.rb index 77b10e6506..9286a91022 100644 --- a/lib/chef/knife/exec.rb +++ b/lib/chef/knife/exec.rb @@ -76,7 +76,7 @@ class Chef::Knife::Exec < Chef::Knife def find_script(x) # Try to find a script. First try expanding the path given. script = File.expand_path(x) - return script if File.exists?(script) + return script if File.exist?(script) # Failing that, try searching the script path. If we can't find # anything, fail gracefully. @@ -86,7 +86,7 @@ class Chef::Knife::Exec < Chef::Knife path = File.expand_path(path) test = File.join(path, x) Chef::Log.trace("Testing: #{test}") - if File.exists?(test) + if File.exist?(test) script = test Chef::Log.trace("Found: #{test}") return script diff --git a/lib/chef/provider/service/arch.rb b/lib/chef/provider/service/arch.rb index fe09baf2d5..400da506b1 100644 --- a/lib/chef/provider/service/arch.rb +++ b/lib/chef/provider/service/arch.rb @@ -32,7 +32,7 @@ class Chef::Provider::Service::Arch < Chef::Provider::Service::Init end def load_current_resource - raise Chef::Exceptions::Service, "Could not find /etc/rc.conf" unless ::File.exists?("/etc/rc.conf") + raise Chef::Exceptions::Service, "Could not find /etc/rc.conf" unless ::File.exist?("/etc/rc.conf") raise Chef::Exceptions::Service, "No DAEMONS found in /etc/rc.conf" unless /DAEMONS=\((.*)\)/m.match?(::File.read("/etc/rc.conf")) super diff --git a/lib/chef/provider/service/debian.rb b/lib/chef/provider/service/debian.rb index a89907bb50..da599fa2f6 100644 --- a/lib/chef/provider/service/debian.rb +++ b/lib/chef/provider/service/debian.rb @@ -45,7 +45,7 @@ class Chef shared_resource_requirements requirements.assert(:all_actions) do |a| update_rcd = "/usr/sbin/update-rc.d" - a.assertion { ::File.exists? update_rcd } + a.assertion { ::File.exist? update_rcd } a.failure_message Chef::Exceptions::Service, "#{update_rcd} does not exist!" # no whyrun recovery - this is a base system component of debian # distros and must be present diff --git a/lib/chef/provider/service/gentoo.rb b/lib/chef/provider/service/gentoo.rb index 748038cdaf..4678435129 100644 --- a/lib/chef/provider/service/gentoo.rb +++ b/lib/chef/provider/service/gentoo.rb @@ -34,7 +34,7 @@ class Chef::Provider::Service::Gentoo < Chef::Provider::Service::Init @current_resource.enabled( Dir.glob("/etc/runlevels/**/#{Chef::Util::PathHelper.escape_glob_dir(@current_resource.service_name)}").any? do |file| @found_script = true - exists = ::File.exists? file + exists = ::File.exist? file readable = ::File.readable? file logger.trace "#{@new_resource} exists: #{exists}, readable: #{readable}" exists && readable @@ -47,7 +47,7 @@ class Chef::Provider::Service::Gentoo < Chef::Provider::Service::Init def define_resource_requirements requirements.assert(:all_actions) do |a| - a.assertion { ::File.exists?("/sbin/rc-update") } + a.assertion { ::File.exist?("/sbin/rc-update") } a.failure_message Chef::Exceptions::Service, "/sbin/rc-update does not exist" # no whyrun recovery -t his is a core component whose presence is # unlikely to be affected by what we do in the course of a chef run diff --git a/lib/chef/provider/service/macosx.rb b/lib/chef/provider/service/macosx.rb index a2f8f15b7b..7e695aaf2b 100644 --- a/lib/chef/provider/service/macosx.rb +++ b/lib/chef/provider/service/macosx.rb @@ -81,7 +81,7 @@ class Chef end requirements.assert(:all_actions) do |a| - a.assertion { ::File.exists?(@plist.to_s) } + a.assertion { ::File.exist?(@plist.to_s) } a.failure_message Chef::Exceptions::Service, "Could not find plist for #{@new_resource}" end @@ -221,7 +221,7 @@ class Chef return nil if @plist.nil? # Plist must exist by this point - raise Chef::Exceptions::FileNotFound, "Cannot find #{@plist}!" unless ::File.exists?(@plist) + raise Chef::Exceptions::FileNotFound, "Cannot find #{@plist}!" unless ::File.exist?(@plist) # Most services have the same internal label as the name of the # plist file. However, there is no rule saying that *has* to be diff --git a/lib/chef/provider/service/openbsd.rb b/lib/chef/provider/service/openbsd.rb index 99e8cff6aa..2b484f9fc8 100644 --- a/lib/chef/provider/service/openbsd.rb +++ b/lib/chef/provider/service/openbsd.rb @@ -129,7 +129,7 @@ class Chef end def update_rcl(value) - FileUtils.touch RC_CONF_LOCAL_PATH unless ::File.exists? RC_CONF_LOCAL_PATH + FileUtils.touch RC_CONF_LOCAL_PATH unless ::File.exist? RC_CONF_LOCAL_PATH ::File.write(RC_CONF_LOCAL_PATH, value) @rc_conf_local = value end diff --git a/lib/chef/provider/service/redhat.rb b/lib/chef/provider/service/redhat.rb index ec78ef2240..3ef7110002 100644 --- a/lib/chef/provider/service/redhat.rb +++ b/lib/chef/provider/service/redhat.rb @@ -56,7 +56,7 @@ class Chef requirements.assert(:all_actions) do |a| chkconfig_file = "/sbin/chkconfig" - a.assertion { ::File.exists? chkconfig_file } + a.assertion { ::File.exist? chkconfig_file } a.failure_message Chef::Exceptions::Service, "#{chkconfig_file} does not exist!" end @@ -80,7 +80,7 @@ class Chef super - if ::File.exists?("/sbin/chkconfig") + if ::File.exist?("/sbin/chkconfig") chkconfig = shell_out!("/sbin/chkconfig --list #{current_resource.service_name}", returns: [0, 1]) unless run_levels.nil? || run_levels.empty? all_levels_match = true diff --git a/lib/chef/provider/service/upstart.rb b/lib/chef/provider/service/upstart.rb index 5b93e6f5a9..2b9e304160 100644 --- a/lib/chef/provider/service/upstart.rb +++ b/lib/chef/provider/service/upstart.rb @@ -135,7 +135,7 @@ class Chef end end # Get enabled/disabled state by reading job configuration file - if ::File.exists?("#{@upstart_job_dir}/#{@new_resource.service_name}#{@upstart_conf_suffix}") + if ::File.exist?("#{@upstart_job_dir}/#{@new_resource.service_name}#{@upstart_conf_suffix}") logger.trace("#{@new_resource} found #{@upstart_job_dir}/#{@new_resource.service_name}#{@upstart_conf_suffix}") ::File.open("#{@upstart_job_dir}/#{@new_resource.service_name}#{@upstart_conf_suffix}", "r") do |file| while line = file.gets diff --git a/lib/chef/resource/sudo.rb b/lib/chef/resource/sudo.rb index bd1c7de60e..99bea022ef 100644 --- a/lib/chef/resource/sudo.rb +++ b/lib/chef/resource/sudo.rb @@ -255,7 +255,7 @@ class Chef end def visudo_content(path) - if ::File.exists?(path) + if ::File.exist?(path) "cat #{new_resource.config_prefix}/sudoers | #{new_resource.visudo_binary} -cf - && #{new_resource.visudo_binary} -cf %{path}" else "cat #{new_resource.config_prefix}/sudoers %{path} | #{new_resource.visudo_binary} -cf -" diff --git a/lib/chef/role.rb b/lib/chef/role.rb index 9142f85d15..d43e331da4 100644 --- a/lib/chef/role.rb +++ b/lib/chef/role.rb @@ -256,11 +256,11 @@ class Chef js_path, rb_path = js_files.first, rb_files.first - if js_path && File.exists?(js_path) + if js_path && File.exist?(js_path) # from_json returns object.class => json_class in the JSON. hsh = Chef::JSONCompat.parse(IO.read(js_path)) return from_hash(hsh) - elsif rb_path && File.exists?(rb_path) + elsif rb_path && File.exist?(rb_path) role = Chef::Role.new role.name(name) role.from_file(rb_path) diff --git a/lib/chef/shell.rb b/lib/chef/shell.rb index fbee4c093b..8429110eec 100644 --- a/lib/chef/shell.rb +++ b/lib/chef/shell.rb @@ -339,7 +339,7 @@ module Shell config[:config_file] = config_file_for_shell_mode(environment) config_msg = config[:config_file] || "none (standalone session)" puts "loading configuration: #{config_msg}" - Chef::Config.from_file(config[:config_file]) if !config[:config_file].nil? && File.exists?(config[:config_file]) && File.readable?(config[:config_file]) + Chef::Config.from_file(config[:config_file]) if !config[:config_file].nil? && File.exist?(config[:config_file]) && File.readable?(config[:config_file]) Chef::Config.merge!(config) end diff --git a/lib/chef/util/diff.rb b/lib/chef/util/diff.rb index 806da5922e..3f8a925c4d 100644 --- a/lib/chef/util/diff.rb +++ b/lib/chef/util/diff.rb @@ -63,7 +63,7 @@ class Chef def use_tempfile_if_missing(file) tempfile = nil - unless File.exists?(file) + unless File.exist?(file) Chef::Log.trace("File #{file} does not exist to diff against, using empty tempfile") tempfile = Tempfile.new("chef-diff") file = tempfile.path diff --git a/lib/chef/util/powershell/cmdlet.rb b/lib/chef/util/powershell/cmdlet.rb index e9e3be1738..344e20f466 100644 --- a/lib/chef/util/powershell/cmdlet.rb +++ b/lib/chef/util/powershell/cmdlet.rb @@ -164,7 +164,7 @@ class Chef end def self.destroy(name) - proc { File.delete(name) if File.exists? name } + proc { File.delete(name) if File.exist? name } end end end diff --git a/lib/chef/win32/file.rb b/lib/chef/win32/file.rb index e051a53e4d..e898144414 100644 --- a/lib/chef/win32/file.rb +++ b/lib/chef/win32/file.rb @@ -78,7 +78,7 @@ class Chef def self.symlink?(file_name) is_symlink = false path = encode_path(file_name) - if ::File.exists?(file_name) || ::File.symlink?(file_name) + if ::File.exist?(file_name) || ::File.symlink?(file_name) if (GetFileAttributesW(path) & FILE_ATTRIBUTE_REPARSE_POINT) > 0 file_search_handle(file_name) do |handle, find_data| if find_data[:dw_reserved_0] == IO_REPARSE_TAG_SYMLINK @@ -104,7 +104,7 @@ class Chef # will raise a NotImplementedError, as per MRI. # def self.readlink(link_name) - raise Errno::ENOENT, link_name unless ::File.exists?(link_name) || ::File.symlink?(link_name) + raise Errno::ENOENT, link_name unless ::File.exist?(link_name) || ::File.symlink?(link_name) symlink_file_handle(link_name) do |handle| # Go to DeviceIoControl to get the symlink information |