summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2015-02-18 19:07:45 -0800
committerLamont Granquist <lamont@scriptkiddie.org>2015-02-18 19:07:45 -0800
commited6ff97301ad9aced2ab175128a45ad011bd4716 (patch)
treed3ec2199185048f2d711114c98c0fc53755a7b8c
parent26d1abe6442bc7669f06f3edc656a785e40a23ee (diff)
parentb157f7895c73d97423799f6144396bc9840b187c (diff)
downloadchef-ed6ff97301ad9aced2ab175128a45ad011bd4716.tar.gz
Merge pull request #2940 from chef/lcg/unreachable-code
remove unreachable code
-rw-r--r--lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_entry.rb5
-rw-r--r--lib/chef/cookbook_site_streaming_uploader.rb46
-rw-r--r--lib/chef/knife/cookbook_site_share.rb54
-rw-r--r--lib/chef/knife/ssh.rb2
-rw-r--r--lib/chef/platform/provider_mapping.rb1
-rw-r--r--lib/chef/provider/env.rb4
-rw-r--r--lib/chef/provider/registry_key.rb4
-rw-r--r--lib/chef/role.rb4
-rw-r--r--lib/chef/util/path_helper.rb2
-rw-r--r--lib/chef/util/windows/net_use.rb6
10 files changed, 64 insertions, 64 deletions
diff --git a/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_entry.rb b/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_entry.rb
index 6541b07065..66709ccf68 100644
--- a/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_entry.rb
+++ b/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_entry.rb
@@ -53,7 +53,7 @@ class Chef
# Check chefignore
ignorer = parent
- begin
+ loop do
if ignorer.is_a?(ChefRepositoryFileSystemCookbooksDir)
# Grab the path from entry to child
path_to_child = name
@@ -66,7 +66,8 @@ class Chef
return !ignorer.chefignore || !ignorer.chefignore.ignored?(path_to_child)
end
ignorer = ignorer.parent
- end while ignorer
+ break unless ignorer
+ end
true
end
diff --git a/lib/chef/cookbook_site_streaming_uploader.rb b/lib/chef/cookbook_site_streaming_uploader.rb
index 879a578e15..9e7a55c772 100644
--- a/lib/chef/cookbook_site_streaming_uploader.rb
+++ b/lib/chef/cookbook_site_streaming_uploader.rb
@@ -35,22 +35,22 @@ class Chef
class << self
- def create_build_dir(cookbook)
- tmp_cookbook_path = Tempfile.new("chef-#{cookbook.name}-build")
- tmp_cookbook_path.close
- tmp_cookbook_dir = tmp_cookbook_path.path
- File.unlink(tmp_cookbook_dir)
- FileUtils.mkdir_p(tmp_cookbook_dir)
- Chef::Log.debug("Staging at #{tmp_cookbook_dir}")
- checksums_to_on_disk_paths = cookbook.checksums
- Chef::CookbookVersion::COOKBOOK_SEGMENTS.each do |segment|
- cookbook.manifest[segment].each do |manifest_record|
- path_in_cookbook = manifest_record[:path]
- on_disk_path = checksums_to_on_disk_paths[manifest_record[:checksum]]
- dest = File.join(tmp_cookbook_dir, cookbook.name.to_s, path_in_cookbook)
- FileUtils.mkdir_p(File.dirname(dest))
- Chef::Log.debug("Staging #{on_disk_path} to #{dest}")
- FileUtils.cp(on_disk_path, dest)
+ def create_build_dir(cookbook)
+ tmp_cookbook_path = Tempfile.new("chef-#{cookbook.name}-build")
+ tmp_cookbook_path.close
+ tmp_cookbook_dir = tmp_cookbook_path.path
+ File.unlink(tmp_cookbook_dir)
+ FileUtils.mkdir_p(tmp_cookbook_dir)
+ Chef::Log.debug("Staging at #{tmp_cookbook_dir}")
+ checksums_to_on_disk_paths = cookbook.checksums
+ Chef::CookbookVersion::COOKBOOK_SEGMENTS.each do |segment|
+ cookbook.manifest[segment].each do |manifest_record|
+ path_in_cookbook = manifest_record[:path]
+ on_disk_path = checksums_to_on_disk_paths[manifest_record[:checksum]]
+ dest = File.join(tmp_cookbook_dir, cookbook.name.to_s, path_in_cookbook)
+ FileUtils.mkdir_p(File.dirname(dest))
+ Chef::Log.debug("Staging #{on_disk_path} to #{dest}")
+ FileUtils.cp(on_disk_path, dest)
end
end
@@ -87,13 +87,13 @@ class Chef
filepath = value.path
filename = File.basename(filepath)
parts << StringPart.new( "--" + boundary + "\r\n" +
- "Content-Disposition: form-data; name=\"" + key.to_s + "\"; filename=\"" + filename + "\"\r\n" +
- "Content-Type: application/octet-stream\r\n\r\n")
+ "Content-Disposition: form-data; name=\"" + key.to_s + "\"; filename=\"" + filename + "\"\r\n" +
+ "Content-Type: application/octet-stream\r\n\r\n")
parts << StreamPart.new(value, File.size(filepath))
parts << StringPart.new("\r\n")
else
parts << StringPart.new( "--" + boundary + "\r\n" +
- "Content-Disposition: form-data; name=\"" + key.to_s + "\"\r\n\r\n")
+ "Content-Disposition: form-data; name=\"" + key.to_s + "\"\r\n\r\n")
parts << StringPart.new(value.to_s + "\r\n")
end
end
@@ -244,10 +244,10 @@ class Chef
@part_offset = 0
next_part = read(how_much_next_part)
result = current_part + if next_part
- next_part
- else
- ''
- end
+ next_part
+ else
+ ''
+ end
else
@part_offset += how_much_current_part
result = current_part
diff --git a/lib/chef/knife/cookbook_site_share.rb b/lib/chef/knife/cookbook_site_share.rb
index ee73bfc26a..560e0669c1 100644
--- a/lib/chef/knife/cookbook_site_share.rb
+++ b/lib/chef/knife/cookbook_site_share.rb
@@ -131,33 +131,33 @@ class Chef
end
def do_upload(cookbook_filename, cookbook_category, user_id, user_secret_filename)
- uri = "https://supermarket.chef.io/api/v1/cookbooks"
-
- category_string = Chef::JSONCompat.to_json({ 'category'=>cookbook_category })
-
- http_resp = Chef::CookbookSiteStreamingUploader.post(uri, user_id, user_secret_filename, {
- :tarball => File.open(cookbook_filename),
- :cookbook => category_string
- })
-
- res = Chef::JSONCompat.from_json(http_resp.body)
- if http_resp.code.to_i != 201
- if res['error_messages']
- if res['error_messages'][0] =~ /Version already exists/
- ui.error "The same version of this cookbook already exists on the Opscode Cookbook Site."
- exit(1)
- else
- ui.error "#{res['error_messages'][0]}"
- exit(1)
- end
- else
- ui.error "Unknown error while sharing cookbook"
- ui.error "Server response: #{http_resp.body}"
- exit(1)
- end
- end
- res
- end
+ uri = "https://supermarket.chef.io/api/v1/cookbooks"
+
+ category_string = Chef::JSONCompat.to_json({ 'category'=>cookbook_category })
+
+ http_resp = Chef::CookbookSiteStreamingUploader.post(uri, user_id, user_secret_filename, {
+ :tarball => File.open(cookbook_filename),
+ :cookbook => category_string
+ })
+
+ res = Chef::JSONCompat.from_json(http_resp.body)
+ if http_resp.code.to_i != 201
+ if res['error_messages']
+ if res['error_messages'][0] =~ /Version already exists/
+ ui.error "The same version of this cookbook already exists on the Opscode Cookbook Site."
+ exit(1)
+ else
+ ui.error "#{res['error_messages'][0]}"
+ exit(1)
+ end
+ else
+ ui.error "Unknown error while sharing cookbook"
+ ui.error "Server response: #{http_resp.body}"
+ exit(1)
+ end
+ end
+ res
+ end
end
end
diff --git a/lib/chef/knife/ssh.rb b/lib/chef/knife/ssh.rb
index de4c60d998..4569cc097e 100644
--- a/lib/chef/knife/ssh.rb
+++ b/lib/chef/knife/ssh.rb
@@ -313,7 +313,7 @@ class Chef
puts
puts "To exit interactive mode, use 'quit!'"
puts
- while 1
+ loop do
command = read_line
case command
when 'quit!'
diff --git a/lib/chef/platform/provider_mapping.rb b/lib/chef/platform/provider_mapping.rb
index 3c7ecf038c..3d8212e24f 100644
--- a/lib/chef/platform/provider_mapping.rb
+++ b/lib/chef/platform/provider_mapping.rb
@@ -473,7 +473,6 @@ class Chef
def provider_for_node(node, resource_type)
raise NotImplementedError, "#{self.class.name} no longer supports #provider_for_node"
- find_provider_for_node(node, resource_type).new(node, resource_type)
end
def find_provider_for_node(node, resource_type)
diff --git a/lib/chef/provider/env.rb b/lib/chef/provider/env.rb
index 970131c407..815a19bc0c 100644
--- a/lib/chef/provider/env.rb
+++ b/lib/chef/provider/env.rb
@@ -102,9 +102,9 @@ class Chef
return true #do not delete the key
else
new_value =
- current_values.select { |item|
+ current_values.select do |item|
not new_values.include?(item)
- }.join(@new_resource.delim)
+ end.join(@new_resource.delim)
if new_value.empty?
return false #nothing left here, delete the key
diff --git a/lib/chef/provider/registry_key.rb b/lib/chef/provider/registry_key.rb
index 01ee57895e..94f4e2655b 100644
--- a/lib/chef/provider/registry_key.rb
+++ b/lib/chef/provider/registry_key.rb
@@ -60,9 +60,9 @@ class Chef
@registry ||= Chef::Win32::Registry.new(@run_context, @new_resource.architecture)
end
- def values_to_hash(values)
+ def values_to_hash(values)
if values
- @name_hash = Hash[values.map { |val| [val[:name], val] }]
+ @name_hash = Hash[values.map { |val| [val[:name], val] }]
else
@name_hash = {}
end
diff --git a/lib/chef/role.rb b/lib/chef/role.rb
index 2e42788f06..c085d1d714 100644
--- a/lib/chef/role.rb
+++ b/lib/chef/role.rb
@@ -249,8 +249,8 @@ class Chef
paths = Array(Chef::Config[:role_path])
paths.each do |path|
roles_files = Dir.glob(File.join(Chef::Util::PathHelper.escape_glob(path), "**", "**"))
- js_files = roles_files.select { |file| file.match /\/#{name}\.json$/ }
- rb_files = roles_files.select { |file| file.match /\/#{name}\.rb$/ }
+ js_files = roles_files.select { |file| file.match(/\/#{name}\.json$/) }
+ rb_files = roles_files.select { |file| file.match(/\/#{name}\.rb$/) }
if js_files.count > 1 or rb_files.count > 1
raise Chef::Exceptions::DuplicateRole, "Multiple roles of same type found named #{name}"
end
diff --git a/lib/chef/util/path_helper.rb b/lib/chef/util/path_helper.rb
index a5485a864b..1ae489598d 100644
--- a/lib/chef/util/path_helper.rb
+++ b/lib/chef/util/path_helper.rb
@@ -26,7 +26,7 @@ class Chef
if Chef::Platform.windows?
# Find the first slash, not counting trailing slashes
end_slash = path.size
- while true
+ loop do
slash = path.rindex(/[#{Regexp.escape(File::SEPARATOR)}#{Regexp.escape(path_separator)}]/, end_slash - 1)
if !slash
return end_slash == path.size ? '.' : path_separator
diff --git a/lib/chef/util/windows/net_use.rb b/lib/chef/util/windows/net_use.rb
index 37efc02fcc..62d7e169dc 100644
--- a/lib/chef/util/windows/net_use.rb
+++ b/lib/chef/util/windows/net_use.rb
@@ -46,9 +46,9 @@ class Chef::Util::Windows::NetUse < Chef::Util::Windows
USE_INFO_2.collect { |field| field[1].class == Fixnum ? 'i' : 'L' }.join
SIZEOF_USE_INFO_2 = #sizeof(USE_INFO_2)
- USE_INFO_2.inject(0){|sum,item|
- sum + (item[1].class == Fixnum ? 4 : PTR_SIZE)
- }
+ USE_INFO_2.inject(0) do |sum, item|
+ sum + (item[1].class == Fixnum ? 4 : PTR_SIZE)
+ end
def use_info_2(args)
USE_INFO_2.collect { |field|