diff options
author | Tim Smith <tsmith84@gmail.com> | 2020-07-07 15:31:02 -0700 |
---|---|---|
committer | Tim Smith <tsmith84@gmail.com> | 2020-07-07 17:30:49 -0700 |
commit | ed460911a49716817ded2986e81a5116dfbb795e (patch) | |
tree | 05939eafb0047711ff008e89fe84312fbfdc9531 | |
parent | 824d9da7173d0dff9bb2786dcf5584e53e9866eb (diff) | |
download | chef-ed460911a49716817ded2986e81a5116dfbb795e.tar.gz |
expand_path with __dir__ instead of __FILE__
It's easier to read this at a glance and understand what path we're trying to get.
Signed-off-by: Tim Smith <tsmith@chef.io>
32 files changed, 41 insertions, 41 deletions
@@ -9,12 +9,12 @@ gem "chef", path: "." gem "ohai", git: "https://github.com/chef/ohai.git", branch: "master" -gem "chef-utils", path: File.expand_path("../chef-utils", __FILE__) if File.exist?(File.expand_path("../chef-utils", __FILE__)) -gem "chef-config", path: File.expand_path("../chef-config", __FILE__) if File.exist?(File.expand_path("../chef-config", __FILE__)) +gem "chef-utils", path: File.expand_path('chef-utils', __dir__) if File.exist?(File.expand_path('chef-utils', __dir__)) +gem "chef-config", path: File.expand_path('chef-config', __dir__) if File.exist?(File.expand_path('chef-config', __dir__)) -if File.exist?(File.expand_path("../chef-bin", __FILE__)) +if File.exist?(File.expand_path('chef-bin', __dir__)) # bundling in a git checkout - gem "chef-bin", path: File.expand_path("../chef-bin", __FILE__) + gem "chef-bin", path: File.expand_path('chef-bin', __dir__) else # bundling in omnibus gem "chef-bin" # rubocop:disable Bundler/DuplicatedGem @@ -18,7 +18,7 @@ # # we need this to resolve files required by lib/chef/dist -$LOAD_PATH.unshift(File.expand_path("../chef-config/lib", __FILE__)) +$LOAD_PATH.unshift(File.expand_path('chef-config/lib', __dir__)) begin require_relative "tasks/rspec" diff --git a/chef-bin/chef-bin.gemspec b/chef-bin/chef-bin.gemspec index 66d14f3f52..0b87227be8 100644 --- a/chef-bin/chef-bin.gemspec +++ b/chef-bin/chef-bin.gemspec @@ -1,5 +1,5 @@ # coding: utf-8 -lib = File.expand_path("../lib", __FILE__) +lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require "chef-bin/version" diff --git a/chef-bin/lib/chef-bin/version.rb b/chef-bin/lib/chef-bin/version.rb index 1832141f59..3aa4f15786 100644 --- a/chef-bin/lib/chef-bin/version.rb +++ b/chef-bin/lib/chef-bin/version.rb @@ -20,7 +20,7 @@ # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! module ChefBin - CHEFBIN_ROOT = File.expand_path("../..", __FILE__) + CHEFBIN_ROOT = File.expand_path('..', __dir__) VERSION = "16.2.86".freeze end diff --git a/chef-config/Gemfile b/chef-config/Gemfile index 1652c89ad6..312045d7c7 100644 --- a/chef-config/Gemfile +++ b/chef-config/Gemfile @@ -1,6 +1,6 @@ source "https://rubygems.org" -gem "chef-utils", path: File.expand_path("../../chef-utils", __FILE__) if File.exist?(File.expand_path("../../chef-utils", __FILE__)) +gem "chef-utils", path: File.expand_path('../chef-utils', __dir__) if File.exist?(File.expand_path('../chef-utils', __dir__)) # Specify your gem's dependencies in chef-config.gemspec gemspec diff --git a/chef-config/chef-config.gemspec b/chef-config/chef-config.gemspec index 2e978236ee..80aa6da7ed 100644 --- a/chef-config/chef-config.gemspec +++ b/chef-config/chef-config.gemspec @@ -1,5 +1,5 @@ # coding: utf-8 -lib = File.expand_path("../lib", __FILE__) +lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require "chef-config/version" diff --git a/chef-config/lib/chef-config/version.rb b/chef-config/lib/chef-config/version.rb index 8e72b65fe6..3e2d2427a3 100644 --- a/chef-config/lib/chef-config/version.rb +++ b/chef-config/lib/chef-config/version.rb @@ -14,6 +14,6 @@ # limitations under the License. module ChefConfig - CHEFCONFIG_ROOT = File.expand_path("../..", __FILE__) + CHEFCONFIG_ROOT = File.expand_path('..', __dir__) VERSION = "16.2.86".freeze end diff --git a/chef-universal-mingw32.gemspec b/chef-universal-mingw32.gemspec index 9d77b2526e..3aced09d1b 100644 --- a/chef-universal-mingw32.gemspec +++ b/chef-universal-mingw32.gemspec @@ -1,4 +1,4 @@ -gemspec = eval(IO.read(File.expand_path("../chef.gemspec", __FILE__))) +gemspec = eval(IO.read(File.expand_path('chef.gemspec', __dir__))) gemspec.platform = Gem::Platform.new(%w{universal mingw32}) diff --git a/chef-utils/chef-utils.gemspec b/chef-utils/chef-utils.gemspec index dbe0ef751e..0e91ed49aa 100644 --- a/chef-utils/chef-utils.gemspec +++ b/chef-utils/chef-utils.gemspec @@ -1,5 +1,5 @@ # coding: utf-8 -lib = File.expand_path("../lib", __FILE__) +lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require "chef-utils/version" diff --git a/lib/chef/knife/core/gem_glob_loader.rb b/lib/chef/knife/core/gem_glob_loader.rb index dc812e515f..e31d826081 100644 --- a/lib/chef/knife/core/gem_glob_loader.rb +++ b/lib/chef/knife/core/gem_glob_loader.rb @@ -47,7 +47,7 @@ class Chef def find_subcommands_via_dirglob # The "require paths" of the core knife subcommands bundled with chef - files = Dir[File.join(Chef::Util::PathHelper.escape_glob_dir(File.expand_path("../../../knife", __FILE__)), "*.rb")] + files = Dir[File.join(Chef::Util::PathHelper.escape_glob_dir(File.expand_path('../../knife', __dir__)), "*.rb")] subcommand_files = {} files.each do |knife_file| rel_path = knife_file[/#{CHEF_ROOT}#{Regexp.escape(File::SEPARATOR)}(.*)\.rb/, 1] diff --git a/lib/chef/knife/core/subcommand_loader.rb b/lib/chef/knife/core/subcommand_loader.rb index dd363b6634..e416d4a0c2 100644 --- a/lib/chef/knife/core/subcommand_loader.rb +++ b/lib/chef/knife/core/subcommand_loader.rb @@ -125,7 +125,7 @@ class Chef # def find_subcommands_via_dirglob # The "require paths" of the core knife subcommands bundled with chef - files = Dir[File.join(Chef::Util::PathHelper.escape_glob_dir(File.expand_path("../../../knife", __FILE__)), "*.rb")] + files = Dir[File.join(Chef::Util::PathHelper.escape_glob_dir(File.expand_path('../../knife', __dir__)), "*.rb")] subcommand_files = {} files.each do |knife_file| rel_path = knife_file[/#{CHEF_ROOT}#{Regexp.escape(File::SEPARATOR)}(.*)\.rb/, 1] diff --git a/lib/chef/log.rb b/lib/chef/log.rb index e835c605ba..63454e91a6 100644 --- a/lib/chef/log.rb +++ b/lib/chef/log.rb @@ -47,7 +47,7 @@ class Chef def self.caller_location # Pick the first caller that is *not* part of the Chef gem, that's the # thing the user wrote. Or failing that, the most recent caller. - chef_gem_path = File.expand_path("../..", __FILE__) + chef_gem_path = File.expand_path('..', __dir__) caller(0..20).find { |c| !c.start_with?(chef_gem_path) } || caller(0..1)[0] end diff --git a/lib/chef/provider/yum_repository.rb b/lib/chef/provider/yum_repository.rb index d3e281775a..787ce301f9 100644 --- a/lib/chef/provider/yum_repository.rb +++ b/lib/chef/provider/yum_repository.rb @@ -37,7 +37,7 @@ class Chef if template_available?(new_resource.source) source new_resource.source else - source ::File.expand_path("../support/yum_repo.erb", __FILE__) + source ::File.expand_path('support/yum_repo.erb', __dir__) local true end sensitive new_resource.sensitive diff --git a/lib/chef/provider/zypper_repository.rb b/lib/chef/provider/zypper_repository.rb index 4602d804b9..5173118ba6 100644 --- a/lib/chef/provider/zypper_repository.rb +++ b/lib/chef/provider/zypper_repository.rb @@ -41,7 +41,7 @@ class Chef if template_available?(new_resource.source) source new_resource.source else - source ::File.expand_path("../support/zypper_repo.erb", __FILE__) + source ::File.expand_path('support/zypper_repo.erb', __dir__) local true end sensitive new_resource.sensitive diff --git a/lib/chef/resource/cron/cron_d.rb b/lib/chef/resource/cron/cron_d.rb index 3a913b22c3..9749fa1976 100644 --- a/lib/chef/resource/cron/cron_d.rb +++ b/lib/chef/resource/cron/cron_d.rb @@ -158,7 +158,7 @@ class Chef # @todo this is Chef 12 era cleanup. Someday we should remove it all template "/etc/cron.d/#{sanitized_name}" do - source ::File.expand_path("../../support/cron.d.erb", __FILE__) + source ::File.expand_path('../support/cron.d.erb', __dir__) local true mode new_resource.mode variables( diff --git a/lib/chef/resource/cron_access.rb b/lib/chef/resource/cron_access.rb index 59b510a65f..1b991ae35c 100644 --- a/lib/chef/resource/cron_access.rb +++ b/lib/chef/resource/cron_access.rb @@ -70,7 +70,7 @@ class Chef with_run_context :root do edit_resource(:template, allow_path) do |new_resource| - source ::File.expand_path("../support/cron_access.erb", __FILE__) + source ::File.expand_path('support/cron_access.erb', __dir__) local true mode "0600" variables["users"] ||= [] @@ -87,7 +87,7 @@ class Chef with_run_context :root do edit_resource(:template, deny_path) do |new_resource| - source ::File.expand_path("../support/cron_access.erb", __FILE__) + source ::File.expand_path('support/cron_access.erb', __dir__) local true mode "0600" variables["users"] ||= [] diff --git a/lib/chef/resource/ssh_known_hosts_entry.rb b/lib/chef/resource/ssh_known_hosts_entry.rb index 0bc835392c..c4384d80f0 100644 --- a/lib/chef/resource/ssh_known_hosts_entry.rb +++ b/lib/chef/resource/ssh_known_hosts_entry.rb @@ -106,7 +106,7 @@ class Chef r = with_run_context :root do find_resource(:template, "update ssh known hosts file #{new_resource.file_location}") do - source ::File.expand_path("../support/ssh_known_hosts.erb", __FILE__) + source ::File.expand_path('support/ssh_known_hosts.erb', __dir__) local true path new_resource.file_location owner new_resource.owner diff --git a/lib/chef/resource/sudo.rb b/lib/chef/resource/sudo.rb index d7babd8f96..d3419d1aef 100644 --- a/lib/chef/resource/sudo.rb +++ b/lib/chef/resource/sudo.rb @@ -199,7 +199,7 @@ class Chef end else template file_path do - source ::File.expand_path("../support/sudoer.erb", __FILE__) + source ::File.expand_path('support/sudoer.erb', __dir__) local true mode "0440" variables sudoer: (new_resource.groups + new_resource.users).join(","), diff --git a/lib/chef/resource/user_ulimit.rb b/lib/chef/resource/user_ulimit.rb index 5b5c887de1..1cab5ee5f0 100644 --- a/lib/chef/resource/user_ulimit.rb +++ b/lib/chef/resource/user_ulimit.rb @@ -80,7 +80,7 @@ class Chef action :create do template "/etc/security/limits.d/#{new_resource.filename}" do - source ::File.expand_path("../support/ulimit.erb", __FILE__) + source ::File.expand_path('support/ulimit.erb', __dir__) local true mode "0644" variables( diff --git a/lib/chef/version.rb b/lib/chef/version.rb index 8502e5759a..cad18a24db 100644 --- a/lib/chef/version.rb +++ b/lib/chef/version.rb @@ -22,7 +22,7 @@ require_relative "version_string" class Chef - CHEF_ROOT = File.expand_path("../..", __FILE__) + CHEF_ROOT = File.expand_path('..', __dir__) VERSION = Chef::VersionString.new("16.2.86") end diff --git a/omnibus/config/projects/angrychef.rb b/omnibus/config/projects/angrychef.rb index eb6dce476d..c5d110408d 100644 --- a/omnibus/config/projects/angrychef.rb +++ b/omnibus/config/projects/angrychef.rb @@ -20,7 +20,7 @@ # `config/project/chef.rb`. # current_file = __FILE__ -chef_project_contents = IO.read(File.expand_path("../chef.rb", __FILE__)) +chef_project_contents = IO.read(File.expand_path('chef.rb', __dir__)) instance_eval chef_project_contents name "angrychef" diff --git a/spec/integration/recipes/accumulator_spec.rb b/spec/integration/recipes/accumulator_spec.rb index e0ecfd340a..dc3724707e 100644 --- a/spec/integration/recipes/accumulator_spec.rb +++ b/spec/integration/recipes/accumulator_spec.rb @@ -6,7 +6,7 @@ describe "Accumulators" do include IntegrationSupport include Chef::Mixin::ShellOut - let(:chef_dir) { File.expand_path("../../../../bin", __FILE__) } + let(:chef_dir) { File.expand_path('../../../bin', __dir__) } # Invoke `chef-client` as `ruby PATH/TO/chef-client`. This ensures the # following constraints are satisfied: diff --git a/spec/integration/recipes/lwrp_inline_resources_spec.rb b/spec/integration/recipes/lwrp_inline_resources_spec.rb index 833f866db4..7de6f78656 100644 --- a/spec/integration/recipes/lwrp_inline_resources_spec.rb +++ b/spec/integration/recipes/lwrp_inline_resources_spec.rb @@ -6,7 +6,7 @@ describe "LWRPs with inline resources" do include IntegrationSupport include Chef::Mixin::ShellOut - let(:chef_dir) { File.expand_path("../../../../bin", __FILE__) } + let(:chef_dir) { File.expand_path('../../../bin', __dir__) } # Invoke `chef-client` as `ruby PATH/TO/chef-client`. This ensures the # following constraints are satisfied: diff --git a/spec/integration/recipes/lwrp_spec.rb b/spec/integration/recipes/lwrp_spec.rb index 1c772a378f..247ed9125d 100644 --- a/spec/integration/recipes/lwrp_spec.rb +++ b/spec/integration/recipes/lwrp_spec.rb @@ -6,7 +6,7 @@ describe "LWRPs" do include IntegrationSupport include Chef::Mixin::ShellOut - let(:chef_dir) { File.expand_path("../../../../bin", __FILE__) } + let(:chef_dir) { File.expand_path('../../../bin', __dir__) } # Invoke `chef-client` as `ruby PATH/TO/chef-client`. This ensures the # following constraints are satisfied: diff --git a/spec/integration/recipes/notifies_spec.rb b/spec/integration/recipes/notifies_spec.rb index f8bd9df8db..299fcd1912 100644 --- a/spec/integration/recipes/notifies_spec.rb +++ b/spec/integration/recipes/notifies_spec.rb @@ -22,7 +22,7 @@ describe "notifications" do include IntegrationSupport include Chef::Mixin::ShellOut - let(:chef_dir) { File.expand_path("../../../../bin", __FILE__) } + let(:chef_dir) { File.expand_path('../../../bin', __dir__) } let(:chef_client) { "bundle exec chef-client --minimal-ohai" } when_the_repository "notifies a nameless resource" do diff --git a/spec/integration/recipes/notifying_block_spec.rb b/spec/integration/recipes/notifying_block_spec.rb index 5f472cecaa..292fce4aac 100644 --- a/spec/integration/recipes/notifying_block_spec.rb +++ b/spec/integration/recipes/notifying_block_spec.rb @@ -23,7 +23,7 @@ describe "notifying_block" do include IntegrationSupport include Chef::Mixin::ShellOut - let(:chef_dir) { File.expand_path("../../../../bin", __FILE__) } + let(:chef_dir) { File.expand_path('../../../bin', __dir__) } let(:chef_client) { "bundle exec chef-client --minimal-ohai" } when_the_repository "notifying_block test one" do diff --git a/spec/integration/recipes/unified_mode_spec.rb b/spec/integration/recipes/unified_mode_spec.rb index bb8cffae3f..45efd7a08b 100644 --- a/spec/integration/recipes/unified_mode_spec.rb +++ b/spec/integration/recipes/unified_mode_spec.rb @@ -6,7 +6,7 @@ describe "Unified Mode" do include IntegrationSupport include Chef::Mixin::ShellOut - let(:chef_dir) { File.expand_path("../../../../bin", __FILE__) } + let(:chef_dir) { File.expand_path('../../../bin', __dir__) } let(:chef_client) { "bundle exec chef-client --minimal-ohai" } diff --git a/spec/integration/recipes/use_partial_spec.rb b/spec/integration/recipes/use_partial_spec.rb index 32c1dd4a2d..9287a1ad1c 100644 --- a/spec/integration/recipes/use_partial_spec.rb +++ b/spec/integration/recipes/use_partial_spec.rb @@ -22,7 +22,7 @@ describe "notifying_block" do include IntegrationSupport include Chef::Mixin::ShellOut - let(:chef_dir) { File.expand_path("../../../../bin", __FILE__) } + let(:chef_dir) { File.expand_path('../../../bin', __dir__) } let(:chef_client) { "bundle exec chef-client --minimal-ohai" } when_the_repository "has a cookbook with partial resources" do diff --git a/spec/scripts/ssl-serve.rb b/spec/scripts/ssl-serve.rb index e9f645416c..40b77d4d1a 100644 --- a/spec/scripts/ssl-serve.rb +++ b/spec/scripts/ssl-serve.rb @@ -12,7 +12,7 @@ require "webrick/https" $ssl = true -CHEF_SPEC_DATA = File.expand_path("../../data", __FILE__) +CHEF_SPEC_DATA = File.expand_path('../data', __dir__) cert_text = File.read(File.expand_path("ssl/chef-rspec.cert", CHEF_SPEC_DATA)) cert = OpenSSL::X509::Certificate.new(cert_text) key_text = File.read(File.expand_path("ssl/chef-rspec.key", CHEF_SPEC_DATA)) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e2e967ba9c..a05a90e7a5 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -24,10 +24,10 @@ module Shell IRB = nil unless defined? IRB end -$LOAD_PATH.unshift File.expand_path("../..", __FILE__) +$LOAD_PATH.unshift File.expand_path('..', __dir__) -$LOAD_PATH.unshift File.expand_path("../../chef-config/lib", __FILE__) -$LOAD_PATH.unshift File.expand_path("../../chef-utils/lib", __FILE__) +$LOAD_PATH.unshift File.expand_path('../chef-config/lib', __dir__) +$LOAD_PATH.unshift File.expand_path('../chef-utils/lib', __dir__) require "rubygems" require "rspec/mocks" diff --git a/spec/unit/lwrp_spec.rb b/spec/unit/lwrp_spec.rb index b0ddf30b28..093503d1c4 100644 --- a/spec/unit/lwrp_spec.rb +++ b/spec/unit/lwrp_spec.rb @@ -140,7 +140,7 @@ describe "LWRP" do before do @tmpdir = Dir.mktmpdir("lwrp_test") @lwrp_path = File.join(@tmpdir, "foo.rb") - content = IO.read(File.expand_path("../../data/lwrp/resources/foo.rb", __FILE__)) + content = IO.read(File.expand_path('../data/lwrp/resources/foo.rb', __dir__)) IO.write(@lwrp_path, content) Chef::Resource::LWRPBase.build_from_file("lwrp", @lwrp_path, nil) @original_resource = Chef::ResourceResolver.resolve(:lwrp_foo) @@ -152,7 +152,7 @@ describe "LWRP" do context "And the LWRP is asked to load again, this time with different code" do before do - content = IO.read(File.expand_path("../../data/lwrp_override/resources/foo.rb", __FILE__)) + content = IO.read(File.expand_path('../data/lwrp_override/resources/foo.rb', __dir__)) IO.write(@lwrp_path, content) Chef::Resource::LWRPBase.build_from_file("lwrp", @lwrp_path, nil) end @@ -390,11 +390,11 @@ describe "LWRP" do end before(:each) do - Dir[File.expand_path(File.expand_path("../../data/lwrp/resources/*", __FILE__))].each do |file| + Dir[File.expand_path(File.expand_path('../data/lwrp/resources/*', __dir__))].each do |file| Chef::Resource::LWRPBase.build_from_file(lwrp_cookbook_name, file, run_context) end - Dir[File.expand_path(File.expand_path("../../data/lwrp/providers/*", __FILE__))].each do |file| + Dir[File.expand_path(File.expand_path('../data/lwrp/providers/*', __dir__))].each do |file| Chef::Provider::LWRPBase.build_from_file(lwrp_cookbook_name, file, run_context) end end diff --git a/spec/unit/run_context/cookbook_compiler_spec.rb b/spec/unit/run_context/cookbook_compiler_spec.rb index 3c6f8aa581..1a33e0f230 100644 --- a/spec/unit/run_context/cookbook_compiler_spec.rb +++ b/spec/unit/run_context/cookbook_compiler_spec.rb @@ -175,7 +175,7 @@ describe Chef::RunContext::CookbookCompiler do describe "event dispatch" do let(:recipe) { "dependency1::default" } let(:recipe_path) do - File.expand_path("../../../data/run_context/cookbooks/dependency1/recipes/default.rb", __FILE__) + File.expand_path('../../data/run_context/cookbooks/dependency1/recipes/default.rb', __dir__) end before do node.run_list(recipe) |