summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Mundrawala <jdmundrawala@gmail.com>2014-09-30 13:13:50 -0700
committerJay Mundrawala <jdmundrawala@gmail.com>2014-09-30 13:13:50 -0700
commita93b2b67209db49ebbf9a52655894e3b7e150618 (patch)
tree093c93e6d2e22c80928e6b3a1a3220cb2d7114d3
parent0d32643ea573e28c5e62e77b04fdbb5ee98d2a05 (diff)
parenta944d11c108a2bfb91f4b7756030a3e98abec9eb (diff)
downloadchef-a93b2b67209db49ebbf9a52655894e3b7e150618.tar.gz
Merge pull request #2130 from opscode/jdmundrawala/cookbook-loading
Fixing cookbook loading for windows
-rw-r--r--lib/chef/cookbook/cookbook_version_loader.rb12
-rw-r--r--lib/chef/cookbook/syntax_check.rb4
-rw-r--r--lib/chef/cookbook_version.rb2
-rw-r--r--lib/chef/util/path_helper.rb4
-rw-r--r--spec/unit/cookbook/cookbook_version_loader_spec.rb3
-rw-r--r--spec/unit/cookbook/syntax_check_spec.rb3
-rw-r--r--spec/unit/cookbook_loader_spec.rb4
7 files changed, 24 insertions, 8 deletions
diff --git a/lib/chef/cookbook/cookbook_version_loader.rb b/lib/chef/cookbook/cookbook_version_loader.rb
index 5c9de6b8ca..5481ba7ddc 100644
--- a/lib/chef/cookbook/cookbook_version_loader.rb
+++ b/lib/chef/cookbook/cookbook_version_loader.rb
@@ -214,23 +214,29 @@ class Chef
def load_root_files
Dir.glob(File.join(Chef::Util::PathHelper.escape_glob(cookbook_path), '*'), File::FNM_DOTMATCH).each do |file|
+ file = Chef::Util::PathHelper.cleanpath(file)
next if File.directory?(file)
next if File.basename(file) == UPLOADED_COOKBOOK_VERSION_FILE
- cookbook_settings[:root_filenames][file[@relative_path, 1]] = file
+ name = Chef::Util::PathHelper.relative_path_from(@cookbook_path, file)
+ cookbook_settings[:root_filenames][name] = file
end
end
def load_recursively_as(category, category_dir, glob)
file_spec = File.join(Chef::Util::PathHelper.escape_glob(cookbook_path, category_dir), '**', glob)
Dir.glob(file_spec, File::FNM_DOTMATCH).each do |file|
+ file = Chef::Util::PathHelper.cleanpath(file)
next if File.directory?(file)
- cookbook_settings[category][file[@relative_path, 1]] = file
+ name = Chef::Util::PathHelper.relative_path_from(@cookbook_path, file)
+ cookbook_settings[category][name] = file
end
end
def load_as(category, *path_glob)
Dir[File.join(Chef::Util::PathHelper.escape_glob(cookbook_path), *path_glob)].each do |file|
- cookbook_settings[category][file[@relative_path, 1]] = file
+ file = Chef::Util::PathHelper.cleanpath(file)
+ name = Chef::Util::PathHelper.relative_path_from(@cookbook_path, file)
+ cookbook_settings[category][name] = file
end
end
diff --git a/lib/chef/cookbook/syntax_check.rb b/lib/chef/cookbook/syntax_check.rb
index 69c194516b..1437785259 100644
--- a/lib/chef/cookbook/syntax_check.rb
+++ b/lib/chef/cookbook/syntax_check.rb
@@ -103,9 +103,7 @@ class Chef
def remove_ignored_files(file_list)
return file_list unless chefignore.ignores.length > 0
file_list.reject do |full_path|
- cookbook_pn = Pathname.new cookbook_path
- full_pn = Pathname.new full_path
- relative_pn = full_pn.relative_path_from cookbook_pn
+ relative_pn = Chef::Util::PathHelper.relative_path_from(cookbook_path, full_path)
chefignore.ignored? relative_pn.to_s
end
end
diff --git a/lib/chef/cookbook_version.rb b/lib/chef/cookbook_version.rb
index 76e6d152b2..1503add33a 100644
--- a/lib/chef/cookbook_version.rb
+++ b/lib/chef/cookbook_version.rb
@@ -660,7 +660,7 @@ class Chef
def parse_segment_file_from_root_paths(segment, segment_file)
root_paths.each do |root_path|
- pathname = Pathname.new(segment_file).relative_path_from(Pathname.new(root_path))
+ pathname = Chef::Util::PathHelper.relative_path_from(root_path, segment_file)
parts = pathname.each_filename.take(2)
# Check if path is actually under root_path
diff --git a/lib/chef/util/path_helper.rb b/lib/chef/util/path_helper.rb
index 8ca8279593..26c9c76fe5 100644
--- a/lib/chef/util/path_helper.rb
+++ b/lib/chef/util/path_helper.rb
@@ -141,6 +141,10 @@ class Chef
path = cleanpath(join(*parts))
path.gsub(/[\\\{\}\[\]\*\?]/) { |x| "\\"+x }
end
+
+ def self.relative_path_from(from, to)
+ pathname = Pathname.new(Chef::Util::PathHelper.cleanpath(to)).relative_path_from(Pathname.new(Chef::Util::PathHelper.cleanpath(from)))
+ end
end
end
end
diff --git a/spec/unit/cookbook/cookbook_version_loader_spec.rb b/spec/unit/cookbook/cookbook_version_loader_spec.rb
index ad10f24573..5772c5352d 100644
--- a/spec/unit/cookbook/cookbook_version_loader_spec.rb
+++ b/spec/unit/cookbook/cookbook_version_loader_spec.rb
@@ -19,6 +19,9 @@
require 'spec_helper'
describe Chef::Cookbook::CookbookVersionLoader do
+ before do
+ Chef::Platform.stub(:windows?) { false }
+ end
describe "loading a cookbook" do
diff --git a/spec/unit/cookbook/syntax_check_spec.rb b/spec/unit/cookbook/syntax_check_spec.rb
index b83bffe1c9..cd1ce96716 100644
--- a/spec/unit/cookbook/syntax_check_spec.rb
+++ b/spec/unit/cookbook/syntax_check_spec.rb
@@ -20,6 +20,9 @@ require 'spec_helper'
require "chef/cookbook/syntax_check"
describe Chef::Cookbook::SyntaxCheck do
+ before do
+ Chef::Platform.stub(:windows?) { false }
+ end
let(:cookbook_path) { File.join(CHEF_SPEC_DATA, 'cookbooks', 'openldap') }
let(:syntax_check) { Chef::Cookbook::SyntaxCheck.new(cookbook_path) }
diff --git a/spec/unit/cookbook_loader_spec.rb b/spec/unit/cookbook_loader_spec.rb
index d5d585b8e1..f40bbd5696 100644
--- a/spec/unit/cookbook_loader_spec.rb
+++ b/spec/unit/cookbook_loader_spec.rb
@@ -19,7 +19,9 @@
require 'spec_helper'
describe Chef::CookbookLoader do
-
+ before do
+ Chef::Platform.stub(:windows?) {false}
+ end
let(:repo_paths) do
[
File.expand_path(File.join(CHEF_SPEC_DATA, "kitchen")),