fix rubocop Style/GuardClause cop
This commit is contained in:
parent
63b3ee3465
commit
b920a1eb49
|
@ -139,11 +139,6 @@ Style/FileName:
|
|||
Style/FormatString:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 10
|
||||
# Configuration parameters: MinBodyLength.
|
||||
Style/GuardClause:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
Style/InfiniteLoop:
|
||||
|
|
|
@ -45,9 +45,8 @@ module Zip
|
|||
end
|
||||
|
||||
def check_name(name)
|
||||
if name.start_with?('/')
|
||||
raise ::Zip::EntryNameError, "Illegal ZipEntry name '#{name}', name must not start with /"
|
||||
end
|
||||
return unless name.start_with?('/')
|
||||
raise ::Zip::EntryNameError, "Illegal ZipEntry name '#{name}', name must not start with /"
|
||||
end
|
||||
|
||||
def initialize(*args)
|
||||
|
@ -332,21 +331,18 @@ module Zip
|
|||
end
|
||||
|
||||
def check_c_dir_entry_static_header_length(buf)
|
||||
unless buf.bytesize == ::Zip::CDIR_ENTRY_STATIC_HEADER_LENGTH
|
||||
raise Error, 'Premature end of file. Not enough data for zip cdir entry header'
|
||||
end
|
||||
return if buf.bytesize == ::Zip::CDIR_ENTRY_STATIC_HEADER_LENGTH
|
||||
raise Error, 'Premature end of file. Not enough data for zip cdir entry header'
|
||||
end
|
||||
|
||||
def check_c_dir_entry_signature
|
||||
unless header_signature == ::Zip::CENTRAL_DIRECTORY_ENTRY_SIGNATURE
|
||||
raise Error, "Zip local header magic not found at location '#{local_header_offset}'"
|
||||
end
|
||||
return if header_signature == ::Zip::CENTRAL_DIRECTORY_ENTRY_SIGNATURE
|
||||
raise Error, "Zip local header magic not found at location '#{local_header_offset}'"
|
||||
end
|
||||
|
||||
def check_c_dir_entry_comment_size
|
||||
unless @comment && @comment.bytesize == @comment_length
|
||||
raise ::Zip::Error, 'Truncated cdir zip entry header'
|
||||
end
|
||||
return if @comment && @comment.bytesize == @comment_length
|
||||
raise ::Zip::Error, 'Truncated cdir zip entry header'
|
||||
end
|
||||
|
||||
def read_c_dir_extra_field(io)
|
||||
|
@ -380,12 +376,11 @@ module Zip
|
|||
end
|
||||
|
||||
def get_extra_attributes_from_path(path) # :nodoc:
|
||||
unless Zip::RUNNING_ON_WINDOWS
|
||||
stat = file_stat(path)
|
||||
@unix_uid = stat.uid
|
||||
@unix_gid = stat.gid
|
||||
@unix_perms = stat.mode & 07777
|
||||
end
|
||||
return if Zip::RUNNING_ON_WINDOWS
|
||||
stat = file_stat(path)
|
||||
@unix_uid = stat.uid
|
||||
@unix_gid = stat.gid
|
||||
@unix_perms = stat.mode & 07777
|
||||
end
|
||||
|
||||
def set_unix_permissions_on_path(dest_path)
|
||||
|
|
|
@ -26,12 +26,11 @@ module Zip
|
|||
tags = parse_tags(content)
|
||||
|
||||
tag1 = tags[1]
|
||||
if tag1
|
||||
ntfs_mtime, ntfs_atime, ntfs_ctime = tag1.unpack('Q<Q<Q<')
|
||||
ntfs_mtime && @mtime ||= from_ntfs_time(ntfs_mtime)
|
||||
ntfs_atime && @atime ||= from_ntfs_time(ntfs_atime)
|
||||
ntfs_ctime && @ctime ||= from_ntfs_time(ntfs_ctime)
|
||||
end
|
||||
return unless tag1
|
||||
ntfs_mtime, ntfs_atime, ntfs_ctime = tag1.unpack('Q<Q<Q<')
|
||||
ntfs_mtime && @mtime ||= from_ntfs_time(ntfs_mtime)
|
||||
ntfs_atime && @atime ||= from_ntfs_time(ntfs_atime)
|
||||
ntfs_ctime && @ctime ||= from_ntfs_time(ntfs_ctime)
|
||||
end
|
||||
|
||||
def ==(other)
|
||||
|
|
|
@ -385,13 +385,12 @@ module Zip
|
|||
|
||||
def check_entry_exists(entryName, continue_on_exists_proc, procedureName)
|
||||
continue_on_exists_proc ||= proc { Zip.continue_on_exists_proc }
|
||||
if @entry_set.include?(entryName)
|
||||
if continue_on_exists_proc.call
|
||||
remove get_entry(entryName)
|
||||
else
|
||||
raise ::Zip::EntryExistsError,
|
||||
procedureName + " failed. Entry #{entryName} already exists"
|
||||
end
|
||||
return unless @entry_set.include?(entryName)
|
||||
if continue_on_exists_proc.call
|
||||
remove get_entry(entryName)
|
||||
else
|
||||
raise ::Zip::EntryExistsError,
|
||||
procedureName + " failed. Entry #{entryName} already exists"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -27,32 +27,31 @@ class ZipFileSplitTest < MiniTest::Test
|
|||
def test_split
|
||||
result = ::Zip::File.split(TEST_ZIP.zip_name, 65_536, false)
|
||||
|
||||
unless result.nil?
|
||||
Dir["#{TEST_ZIP.zip_name}.*"].sort.each_with_index do |zip_file_name, index|
|
||||
File.open(zip_file_name, 'rb') do |zip_file|
|
||||
zip_file.read([::Zip::File::SPLIT_SIGNATURE].pack('V').size) if index == 0
|
||||
File.open(UNSPLITTED_FILENAME, 'ab') do |file|
|
||||
file << zip_file.read
|
||||
end
|
||||
return if result.nil?
|
||||
Dir["#{TEST_ZIP.zip_name}.*"].sort.each_with_index do |zip_file_name, index|
|
||||
File.open(zip_file_name, 'rb') do |zip_file|
|
||||
zip_file.read([::Zip::File::SPLIT_SIGNATURE].pack('V').size) if index == 0
|
||||
File.open(UNSPLITTED_FILENAME, 'ab') do |file|
|
||||
file << zip_file.read
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
::Zip::File.open(UNSPLITTED_FILENAME) do |zf|
|
||||
zf.extract(ENTRY_TO_EXTRACT, EXTRACTED_FILENAME)
|
||||
::Zip::File.open(UNSPLITTED_FILENAME) do |zf|
|
||||
zf.extract(ENTRY_TO_EXTRACT, EXTRACTED_FILENAME)
|
||||
|
||||
assert(File.exist?(EXTRACTED_FILENAME))
|
||||
AssertEntry.assert_contents(EXTRACTED_FILENAME,
|
||||
zf.get_input_stream(ENTRY_TO_EXTRACT) { |is| is.read })
|
||||
assert(File.exist?(EXTRACTED_FILENAME))
|
||||
AssertEntry.assert_contents(EXTRACTED_FILENAME,
|
||||
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.extract(EXTRACTED_FILENAME)
|
||||
entry = zf.get_entry(ENTRY_TO_EXTRACT)
|
||||
entry.extract(EXTRACTED_FILENAME)
|
||||
|
||||
assert(File.exist?(EXTRACTED_FILENAME))
|
||||
AssertEntry.assert_contents(EXTRACTED_FILENAME,
|
||||
entry.get_input_stream { |is| is.read })
|
||||
end
|
||||
assert(File.exist?(EXTRACTED_FILENAME))
|
||||
AssertEntry.assert_contents(EXTRACTED_FILENAME,
|
||||
entry.get_input_stream { |is| is.read })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue