diff options
author | Tim Smith <tsmith@chef.io> | 2020-07-07 17:55:30 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-07 17:55:30 -0700 |
commit | e603bcdf8e93a70addd50e3be1f848400b933365 (patch) | |
tree | 70de57d90bacbe6be118c9b6ead9efc1e650098e | |
parent | 824d9da7173d0dff9bb2786dcf5584e53e9866eb (diff) | |
parent | 6c4c32340ac0fcebb53768cb78f5760e55c35514 (diff) | |
download | chef-e603bcdf8e93a70addd50e3be1f848400b933365.tar.gz |
Merge pull request #10125 from chef/expand_path
expand_path with __dir__ instead of __FILE__
33 files changed, 42 insertions, 42 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..1e7c45d8e9 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..15bf9be9cb 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..c3d90e5e6c 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..6229acdade 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..9aa286ee82 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..cbd745e991 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/chef-utils/lib/chef-utils/version.rb b/chef-utils/lib/chef-utils/version.rb index 35506123ab..c55084200a 100644 --- a/chef-utils/lib/chef-utils/version.rb +++ b/chef-utils/lib/chef-utils/version.rb @@ -14,6 +14,6 @@ # limitations under the License. module ChefUtils - CHEFUTILS_ROOT = File.expand_path("../..", __FILE__) + CHEFUTILS_ROOT = File.expand_path('..', __dir__) VERSION = "16.2.86".freeze end diff --git a/lib/chef/knife/core/gem_glob_loader.rb b/lib/chef/knife/core/gem_glob_loader.rb index dc812e515f..b29df38c86 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..b0f8381d64 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..6254b71342 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..956d5ae64c 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..d2d4d68d76 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..882544a8bc 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..3ea777ce9c 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..533cb42279 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..bd1c7de60e 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..d138eeabf3 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..57f2c023fe 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..329137440c 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..dff2c886be 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..b7a0589675 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..a31ba6370b 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..7a2c5631c1 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..b2c3620fdb 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..c9f1e8e509 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..b03fe4af42 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..5dba5ea0be 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..a933d23afe 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..4d744edc3a 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) |