summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2020-08-13 20:34:53 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2020-08-14 16:34:46 -0700
commit6990bb7b7e4ad65b2a95687bc8389978f6f0bc22 (patch)
tree8b19cd45f4a4445ba5ec112e374bb545a88ab64f
parent1b50445c8cab9d06689a9474fbdc82e3e585b613 (diff)
downloadchef-6990bb7b7e4ad65b2a95687bc8389978f6f0bc22.tar.gz
see if this works
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r--chef-config/lib/chef-config/config.rb19
-rw-r--r--chef-config/lib/chef-config/path_helper.rb8
-rw-r--r--chef-config/spec/unit/config_spec.rb4
-rw-r--r--chef-config/spec/unit/path_helper_spec.rb2
-rw-r--r--lib/chef/knife/core/windows_bootstrap_context.rb6
5 files changed, 22 insertions, 17 deletions
diff --git a/chef-config/lib/chef-config/config.rb b/chef-config/lib/chef-config/config.rb
index 9549ace005..25a7e7ba2b 100644
--- a/chef-config/lib/chef-config/config.rb
+++ b/chef-config/lib/chef-config/config.rb
@@ -76,28 +76,31 @@ module ChefConfig
# On *nix, /etc/chef
def self.etc_chef_dir(windows: ChefUtils.windows?)
- windows ? c_chef_dir : File.join("/etc", ChefConfig::Dist::DIR_SUFFIX)
+ path = windows ? c_chef_dir : PathHelper.join("/etc", ChefConfig::Dist::DIR_SUFFIX, windows: windows)
+ PathHelper.cleanpath(path, windows: windows)
end
# On *nix, /var/chef
def self.var_chef_dir(windows: ChefUtils.windows?)
- windows ? c_chef_dir : File.join("/var", ChefConfig::Dist::DIR_SUFFIX)
+ path = windows ? c_chef_dir : PathHelper.join("/var", ChefConfig::Dist::DIR_SUFFIX, windows: windows)
+ PathHelper.cleanpath(path, windows: windows)
end
# On *nix, the root of /var/, used to test if we can create and write in /var/chef
- def self.var_root_dir
- windows ? c_chef_dir : "/var"
+ def self.var_root_dir(windows: ChefUtils.windows?)
+ path = windows ? c_chef_dir : "/var"
+ PathHelper.cleanpath(path, windows: windows)
end
# On windows, C:/chef/
def self.c_chef_dir(windows: ChefUtils.windows?)
drive = windows_installation_drive || "C:"
- File.join(drive, ChefConfig::Dist::DIR_SUFFIX)
+ PathHelper.join(drive, ChefConfig::Dist::DIR_SUFFIX, windows: windows)
end
def self.c_opscode_dir(windows: ChefUtils.windows?)
drive = windows_installation_drive || "C:"
- File.join(drive, ChefConfig::Dist::LEGACY_CONF_DIR, ChefConfig::Dist::DIR_SUFFIX)
+ PathHelper.join(drive, ChefConfig::Dist::LEGACY_CONF_DIR, ChefConfig::Dist::DIR_SUFFIX, windows: windows)
end
# the drive where Chef is installed on a windows host. This is determined
@@ -337,11 +340,11 @@ module ChefConfig
# the cache path.
unless path_accessible?(primary_cache_path) || path_accessible?(primary_cache_root)
secondary_cache_path = PathHelper.join(user_home, ChefConfig::Dist::USER_CONF_DIR)
- secondary_cache_path = target_mode? ? "#{secondary_cache_path}/#{target_mode.host}" : secondary_cache_path
+ secondary_cache_path = target_mode? ? PathHelper.join(secondary_cache_path, target_mode.host) : secondary_cache_path
ChefConfig.logger.trace("Unable to access cache at #{primary_cache_path}. Switching cache to #{secondary_cache_path}")
secondary_cache_path
else
- target_mode? ? "#{primary_cache_path}/#{target_mode.host}" : primary_cache_path
+ target_mode? ? PathHelper.join(primary_cache_path, target_mode.host) : primary_cache_path
end
end
end
diff --git a/chef-config/lib/chef-config/path_helper.rb b/chef-config/lib/chef-config/path_helper.rb
index b3f44d802a..6b501cb9cb 100644
--- a/chef-config/lib/chef-config/path_helper.rb
+++ b/chef-config/lib/chef-config/path_helper.rb
@@ -139,11 +139,13 @@ module ChefConfig
# using Pathname#cleanpath instead of this function.
def self.cleanpath(path, windows: ChefUtils.windows?)
path = Pathname.new(path).cleanpath.to_s
- # ensure all forward slashes are backslashes
if windows
- path = path.gsub(File::SEPARATOR, path_separator(windows: windows))
+ # ensure all forward slashes are backslashes
+ path.gsub(File::SEPARATOR, path_separator(windows: windows))
+ else
+ # ensure all backslashes are forward slashes
+ path.gsub(BACKSLASH, File::SEPARATOR)
end
- path
end
def self.paths_eql?(path1, path2, windows: ChefUtils.windows?)
diff --git a/chef-config/spec/unit/config_spec.rb b/chef-config/spec/unit/config_spec.rb
index ccfe57c57c..c080734ff3 100644
--- a/chef-config/spec/unit/config_spec.rb
+++ b/chef-config/spec/unit/config_spec.rb
@@ -430,8 +430,8 @@ RSpec.describe ChefConfig::Config do
describe "ChefConfig::Config[:cache_path]" do
let(:target_mode_host) { "fluffy.kittens.org" }
- let(:target_mode_primary_cache_path) { "#{primary_cache_path}/#{target_mode_host}" }
- let(:target_mode_secondary_cache_path) { "#{secondary_cache_path}/#{target_mode_host}" }
+ let(:target_mode_primary_cache_path) { ChefUtils.windows? ? "#{primary_cache_path}\\#{target_mode_host}" : "#{primary_cache_path}/#{target_mode_host}" }
+ let(:target_mode_secondary_cache_path) { ChefUtils.windows? ? "#{secondary_cache_path}\\#{target_mode_host}" : "#{secondary_cache_path}/#{target_mode_host}" }
before do
if is_windows
diff --git a/chef-config/spec/unit/path_helper_spec.rb b/chef-config/spec/unit/path_helper_spec.rb
index 60bc20d3f3..8d5eb61166 100644
--- a/chef-config/spec/unit/path_helper_spec.rb
+++ b/chef-config/spec/unit/path_helper_spec.rb
@@ -248,7 +248,7 @@ RSpec.describe ChefConfig::PathHelper do
it "escapes characters reserved by glob" do
path = "C:\\this\\*path\\[needs]\\escaping?"
escaped_path = "C:\\\\this\\\\\\*path\\\\\\[needs\\]\\\\escaping\\?"
- expect(path_helper.escape_glob(path)).to eq(escaped_path)
+ expect(path_helper.escape_glob(path, windows: true)).to eq(escaped_path)
end
context "when given more than one argument" do
diff --git a/lib/chef/knife/core/windows_bootstrap_context.rb b/lib/chef/knife/core/windows_bootstrap_context.rb
index f4b614af15..d4cad8d819 100644
--- a/lib/chef/knife/core/windows_bootstrap_context.rb
+++ b/lib/chef/knife/core/windows_bootstrap_context.rb
@@ -61,9 +61,9 @@ class Chef
client_rb = <<~CONFIG
chef_server_url "#{chef_config[:chef_server_url]}"
validation_client_name "#{chef_config[:validation_client_name]}"
- file_cache_path "#{ChefConfig::Config.var_chef_dir(windows: true)}/cache"
- file_backup_path "#{ChefConfig::Config.var_chef_dir(windows: true)}/backup"
- cache_options ({:path => "#{ChefConfig::Config.etc_chef_dir(windows: true)}/cache/checksums", :skip_expires => true})
+ file_cache_path "#{ChefConfig::PathHelper.cleanpath(ChefConfig::Config.var_chef_dir(windows: true), windows: false)}/cache"
+ file_backup_path "#{ChefConfig::PathHelper.cleanpath(ChefConfig::Config.var_chef_dir(windows: true), windows: false)}/backup"
+ cache_options ({:path => "#{ChefConfig::PathHelper.cleanpath(ChefConfig::Config.etc_chef_dir(windows: true), windows: false)}/cache/checksums", :skip_expires => true})
CONFIG
unless chef_config[:chef_license].nil?