fix rubocop Style/GuardClause cop

This commit is contained in:
Pavel Lobashov 2015-03-24 19:16:03 +03:00
parent 63b3ee3465
commit b920a1eb49
5 changed files with 42 additions and 55 deletions

View File

@ -139,11 +139,6 @@ Style/FileName:
Style/FormatString: Style/FormatString:
Enabled: false Enabled: false
# Offense count: 10
# Configuration parameters: MinBodyLength.
Style/GuardClause:
Enabled: false
# Offense count: 1 # Offense count: 1
# Cop supports --auto-correct. # Cop supports --auto-correct.
Style/InfiniteLoop: Style/InfiniteLoop:

View File

@ -45,9 +45,8 @@ module Zip
end end
def check_name(name) def check_name(name)
if name.start_with?('/') return unless name.start_with?('/')
raise ::Zip::EntryNameError, "Illegal ZipEntry name '#{name}', name must not start with /" raise ::Zip::EntryNameError, "Illegal ZipEntry name '#{name}', name must not start with /"
end
end end
def initialize(*args) def initialize(*args)
@ -332,21 +331,18 @@ module Zip
end end
def check_c_dir_entry_static_header_length(buf) def check_c_dir_entry_static_header_length(buf)
unless buf.bytesize == ::Zip::CDIR_ENTRY_STATIC_HEADER_LENGTH return if buf.bytesize == ::Zip::CDIR_ENTRY_STATIC_HEADER_LENGTH
raise Error, 'Premature end of file. Not enough data for zip cdir entry header' raise Error, 'Premature end of file. Not enough data for zip cdir entry header'
end
end end
def check_c_dir_entry_signature def check_c_dir_entry_signature
unless header_signature == ::Zip::CENTRAL_DIRECTORY_ENTRY_SIGNATURE return if header_signature == ::Zip::CENTRAL_DIRECTORY_ENTRY_SIGNATURE
raise Error, "Zip local header magic not found at location '#{local_header_offset}'" raise Error, "Zip local header magic not found at location '#{local_header_offset}'"
end
end end
def check_c_dir_entry_comment_size def check_c_dir_entry_comment_size
unless @comment && @comment.bytesize == @comment_length return if @comment && @comment.bytesize == @comment_length
raise ::Zip::Error, 'Truncated cdir zip entry header' raise ::Zip::Error, 'Truncated cdir zip entry header'
end
end end
def read_c_dir_extra_field(io) def read_c_dir_extra_field(io)
@ -380,12 +376,11 @@ module Zip
end end
def get_extra_attributes_from_path(path) # :nodoc: def get_extra_attributes_from_path(path) # :nodoc:
unless Zip::RUNNING_ON_WINDOWS return if Zip::RUNNING_ON_WINDOWS
stat = file_stat(path) stat = file_stat(path)
@unix_uid = stat.uid @unix_uid = stat.uid
@unix_gid = stat.gid @unix_gid = stat.gid
@unix_perms = stat.mode & 07777 @unix_perms = stat.mode & 07777
end
end end
def set_unix_permissions_on_path(dest_path) def set_unix_permissions_on_path(dest_path)

View File

@ -26,12 +26,11 @@ module Zip
tags = parse_tags(content) tags = parse_tags(content)
tag1 = tags[1] tag1 = tags[1]
if tag1 return unless tag1
ntfs_mtime, ntfs_atime, ntfs_ctime = tag1.unpack('Q<Q<Q<') ntfs_mtime, ntfs_atime, ntfs_ctime = tag1.unpack('Q<Q<Q<')
ntfs_mtime && @mtime ||= from_ntfs_time(ntfs_mtime) ntfs_mtime && @mtime ||= from_ntfs_time(ntfs_mtime)
ntfs_atime && @atime ||= from_ntfs_time(ntfs_atime) ntfs_atime && @atime ||= from_ntfs_time(ntfs_atime)
ntfs_ctime && @ctime ||= from_ntfs_time(ntfs_ctime) ntfs_ctime && @ctime ||= from_ntfs_time(ntfs_ctime)
end
end end
def ==(other) def ==(other)

View File

@ -385,13 +385,12 @@ module Zip
def check_entry_exists(entryName, continue_on_exists_proc, procedureName) def check_entry_exists(entryName, continue_on_exists_proc, procedureName)
continue_on_exists_proc ||= proc { Zip.continue_on_exists_proc } continue_on_exists_proc ||= proc { Zip.continue_on_exists_proc }
if @entry_set.include?(entryName) return unless @entry_set.include?(entryName)
if continue_on_exists_proc.call if continue_on_exists_proc.call
remove get_entry(entryName) remove get_entry(entryName)
else else
raise ::Zip::EntryExistsError, raise ::Zip::EntryExistsError,
procedureName + " failed. Entry #{entryName} already exists" procedureName + " failed. Entry #{entryName} already exists"
end
end end
end end

View File

@ -27,32 +27,31 @@ class ZipFileSplitTest < MiniTest::Test
def test_split def test_split
result = ::Zip::File.split(TEST_ZIP.zip_name, 65_536, false) result = ::Zip::File.split(TEST_ZIP.zip_name, 65_536, false)
unless result.nil? return if result.nil?
Dir["#{TEST_ZIP.zip_name}.*"].sort.each_with_index do |zip_file_name, index| Dir["#{TEST_ZIP.zip_name}.*"].sort.each_with_index do |zip_file_name, index|
File.open(zip_file_name, 'rb') do |zip_file| File.open(zip_file_name, 'rb') do |zip_file|
zip_file.read([::Zip::File::SPLIT_SIGNATURE].pack('V').size) if index == 0 zip_file.read([::Zip::File::SPLIT_SIGNATURE].pack('V').size) if index == 0
File.open(UNSPLITTED_FILENAME, 'ab') do |file| File.open(UNSPLITTED_FILENAME, 'ab') do |file|
file << zip_file.read file << zip_file.read
end
end end
end end
end
::Zip::File.open(UNSPLITTED_FILENAME) do |zf| ::Zip::File.open(UNSPLITTED_FILENAME) do |zf|
zf.extract(ENTRY_TO_EXTRACT, EXTRACTED_FILENAME) zf.extract(ENTRY_TO_EXTRACT, EXTRACTED_FILENAME)
assert(File.exist?(EXTRACTED_FILENAME)) assert(File.exist?(EXTRACTED_FILENAME))
AssertEntry.assert_contents(EXTRACTED_FILENAME, AssertEntry.assert_contents(EXTRACTED_FILENAME,
zf.get_input_stream(ENTRY_TO_EXTRACT) { |is| is.read }) zf.get_input_stream(ENTRY_TO_EXTRACT) { |is| is.read })
File.unlink(EXTRACTED_FILENAME) File.unlink(EXTRACTED_FILENAME)
entry = zf.get_entry(ENTRY_TO_EXTRACT) entry = zf.get_entry(ENTRY_TO_EXTRACT)
entry.extract(EXTRACTED_FILENAME) entry.extract(EXTRACTED_FILENAME)
assert(File.exist?(EXTRACTED_FILENAME)) assert(File.exist?(EXTRACTED_FILENAME))
AssertEntry.assert_contents(EXTRACTED_FILENAME, AssertEntry.assert_contents(EXTRACTED_FILENAME,
entry.get_input_stream { |is| is.read }) entry.get_input_stream { |is| is.read })
end
end end
end end
end end