diff options
author | jkeiser <jkeiser@opscode.com> | 2013-01-04 16:53:12 -0800 |
---|---|---|
committer | John Keiser <jkeiser@opscode.com> | 2013-06-07 13:12:16 -0700 |
commit | f9902ce0d14ee0f69726c69c128fd0d2c5c2b616 (patch) | |
tree | 4d117e99e0b2e864fa70b9f0e4d0a4030147be36 /lib/chef/chef_fs | |
parent | 2b450f0606bd29cb65b9da59f4480aa1e87b5c15 (diff) | |
download | chef-f9902ce0d14ee0f69726c69c128fd0d2c5c2b616.tar.gz |
Fix issue where cwd=cookbooks/cookbook1 listed everything at /
Diffstat (limited to 'lib/chef/chef_fs')
-rw-r--r-- | lib/chef/chef_fs/knife.rb | 11 | ||||
-rw-r--r-- | lib/chef/chef_fs/path_utils.rb | 4 |
2 files changed, 11 insertions, 4 deletions
diff --git a/lib/chef/chef_fs/knife.rb b/lib/chef/chef_fs/knife.rb index 0d2457aea2..ce3ae9c0df 100644 --- a/lib/chef/chef_fs/knife.rb +++ b/lib/chef/chef_fs/knife.rb @@ -120,7 +120,7 @@ class Chef paths.each do |path| realest_path = Chef::ChefFS::PathUtils.realest_path(path) if absolute_path[0,realest_path.length] == realest_path - relative_path = Chef::ChefFS::PathUtils::relative_to(realest_path, absolute_path) + relative_path = Chef::ChefFS::PathUtils::relative_to(absolute_path, realest_path) return relative_path == '.' ? "/#{name}" : "/#{name}/#{relative_path}" end end @@ -128,9 +128,8 @@ class Chef # Check chef_repo_path realest_chef_repo_path = Chef::ChefFS::PathUtils.realest_path(chef_repo_path) - if absolute_path[0,realest_chef_repo_path.length] == realest_chef_repo_path - relative_path = Chef::ChefFS::PathUtils::relative_to(realest_chef_repo_path, absolute_path) - return relative_path == '.' ? '/' : "/#{relative_path}" + if absolute_path == realest_chef_repo_path + return '/' end nil @@ -167,6 +166,10 @@ class Chef # TODO support absolute file paths and not just patterns? Too much? # Could be super useful in a world with multiple repo paths args.map do |arg| + if !base_path && !PathUtils.is_absolute?(arg) + ui.error("Attempt to use relative path '#{arg}' when current directory is outside the repository path") + exit(1) + end Chef::ChefFS::FilePattern::relative_to(base_path, arg) end end diff --git a/lib/chef/chef_fs/path_utils.rb b/lib/chef/chef_fs/path_utils.rb index 4fd8f8610e..a034bea66e 100644 --- a/lib/chef/chef_fs/path_utils.rb +++ b/lib/chef/chef_fs/path_utils.rb @@ -79,6 +79,10 @@ class Chef end end end + + def self.is_absolute?(path) + path =~ /^#{regexp_path_separator}/ + end end end end |