Fix Layout/EmptyLineAfterGuardClause cop.
This commit is contained in:
parent
fff2c41d68
commit
cfe4972e71
|
@ -6,11 +6,6 @@
|
||||||
# Note that changes in the inspected code, or installation of new
|
# Note that changes in the inspected code, or installation of new
|
||||||
# versions of RuboCop, may require this file to be generated again.
|
# versions of RuboCop, may require this file to be generated again.
|
||||||
|
|
||||||
# Offense count: 76
|
|
||||||
# Cop supports --auto-correct.
|
|
||||||
Layout/EmptyLineAfterGuardClause:
|
|
||||||
Enabled: false
|
|
||||||
|
|
||||||
# Offense count: 1
|
# Offense count: 1
|
||||||
# Cop supports --auto-correct.
|
# Cop supports --auto-correct.
|
||||||
# Configuration parameters: EnforcedStyle.
|
# Configuration parameters: EnforcedStyle.
|
||||||
|
|
|
@ -141,6 +141,7 @@ module Zip
|
||||||
def get_e_o_c_d(buf) #:nodoc:
|
def get_e_o_c_d(buf) #:nodoc:
|
||||||
sig_index = buf.rindex([END_OF_CDS].pack('V'))
|
sig_index = buf.rindex([END_OF_CDS].pack('V'))
|
||||||
raise Error, 'Zip end of central directory signature not found' unless sig_index
|
raise Error, 'Zip end of central directory signature not found' unless sig_index
|
||||||
|
|
||||||
buf = buf.slice!((sig_index + 4)..(buf.bytesize))
|
buf = buf.slice!((sig_index + 4)..(buf.bytesize))
|
||||||
|
|
||||||
def buf.read(count)
|
def buf.read(count)
|
||||||
|
@ -166,8 +167,10 @@ module Zip
|
||||||
def get_64_e_o_c_d(buf) #:nodoc:
|
def get_64_e_o_c_d(buf) #:nodoc:
|
||||||
zip_64_start = buf.rindex([ZIP64_END_OF_CDS].pack('V'))
|
zip_64_start = buf.rindex([ZIP64_END_OF_CDS].pack('V'))
|
||||||
raise Error, 'Zip64 end of central directory signature not found' unless zip_64_start
|
raise Error, 'Zip64 end of central directory signature not found' unless zip_64_start
|
||||||
|
|
||||||
zip_64_locator = buf.rindex([ZIP64_EOCD_LOCATOR].pack('V'))
|
zip_64_locator = buf.rindex([ZIP64_EOCD_LOCATOR].pack('V'))
|
||||||
raise Error, 'Zip64 end of central directory signature locator not found' unless zip_64_locator
|
raise Error, 'Zip64 end of central directory signature locator not found' unless zip_64_locator
|
||||||
|
|
||||||
buf = buf.slice!((zip_64_start + 4)..zip_64_locator)
|
buf = buf.slice!((zip_64_start + 4)..zip_64_locator)
|
||||||
|
|
||||||
def buf.read(count)
|
def buf.read(count)
|
||||||
|
@ -198,6 +201,7 @@ module Zip
|
||||||
|
|
||||||
def ==(other) #:nodoc:
|
def ==(other) #:nodoc:
|
||||||
return false unless other.kind_of?(CentralDirectory)
|
return false unless other.kind_of?(CentralDirectory)
|
||||||
|
|
||||||
@entry_set.entries.sort == other.entries.sort && comment == other.comment
|
@entry_set.entries.sort == other.entries.sort && comment == other.comment
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,6 +12,7 @@ module Zip
|
||||||
|
|
||||||
while length.nil? || (buffer.bytesize < length)
|
while length.nil? || (buffer.bytesize < length)
|
||||||
break if input_finished?
|
break if input_finished?
|
||||||
|
|
||||||
buffer << produce_input
|
buffer << produce_input
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,7 @@ module Zip
|
||||||
|
|
||||||
def check_name(name)
|
def check_name(name)
|
||||||
return unless 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
|
||||||
|
|
||||||
|
@ -104,6 +105,7 @@ module Zip
|
||||||
|
|
||||||
def file_type_is?(type)
|
def file_type_is?(type)
|
||||||
raise InternalError, "current filetype is unknown: #{inspect}" unless @ftype
|
raise InternalError, "current filetype is unknown: #{inspect}" unless @ftype
|
||||||
|
|
||||||
@ftype == type
|
@ftype == type
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -124,6 +126,7 @@ module Zip
|
||||||
def name_safe?
|
def name_safe?
|
||||||
cleanpath = Pathname.new(@name).cleanpath
|
cleanpath = Pathname.new(@name).cleanpath
|
||||||
return false unless cleanpath.relative?
|
return false unless cleanpath.relative?
|
||||||
|
|
||||||
root = ::File::SEPARATOR
|
root = ::File::SEPARATOR
|
||||||
naive_expanded_path = ::File.join(root, cleanpath.to_s)
|
naive_expanded_path = ::File.join(root, cleanpath.to_s)
|
||||||
::File.absolute_path(cleanpath.to_s, root) == naive_expanded_path
|
::File.absolute_path(cleanpath.to_s, root) == naive_expanded_path
|
||||||
|
@ -153,6 +156,7 @@ module Zip
|
||||||
# that we didn't change the header size (and thus clobber file data or something)
|
# that we didn't change the header size (and thus clobber file data or something)
|
||||||
def verify_local_header_size!
|
def verify_local_header_size!
|
||||||
return if @local_header_size.nil?
|
return if @local_header_size.nil?
|
||||||
|
|
||||||
new_size = calculate_local_header_size
|
new_size = calculate_local_header_size
|
||||||
raise Error, "local header size changed (#{@local_header_size} -> #{new_size})" if @local_header_size != new_size
|
raise Error, "local header size changed (#{@local_header_size} -> #{new_size})" if @local_header_size != new_size
|
||||||
end
|
end
|
||||||
|
@ -255,6 +259,7 @@ module Zip
|
||||||
unless @header_signature == ::Zip::LOCAL_ENTRY_SIGNATURE
|
unless @header_signature == ::Zip::LOCAL_ENTRY_SIGNATURE
|
||||||
raise ::Zip::Error, "Zip local header magic not found at location '#{local_header_offset}'"
|
raise ::Zip::Error, "Zip local header magic not found at location '#{local_header_offset}'"
|
||||||
end
|
end
|
||||||
|
|
||||||
set_time(@last_mod_date, @last_mod_time)
|
set_time(@last_mod_date, @last_mod_time)
|
||||||
|
|
||||||
@name = io.read(@name_length)
|
@name = io.read(@name_length)
|
||||||
|
@ -274,6 +279,7 @@ module Zip
|
||||||
@extra = ::Zip::ExtraField.new(extra)
|
@extra = ::Zip::ExtraField.new(extra)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
parse_zip64_extra(true)
|
parse_zip64_extra(true)
|
||||||
@local_header_size = calculate_local_header_size
|
@local_header_size = calculate_local_header_size
|
||||||
end
|
end
|
||||||
|
@ -360,16 +366,19 @@ module Zip
|
||||||
|
|
||||||
def check_c_dir_entry_static_header_length(buf)
|
def check_c_dir_entry_static_header_length(buf)
|
||||||
return if 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
|
||||||
|
|
||||||
def check_c_dir_entry_signature
|
def check_c_dir_entry_signature
|
||||||
return if 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
|
||||||
|
|
||||||
def check_c_dir_entry_comment_size
|
def check_c_dir_entry_comment_size
|
||||||
return if @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
|
||||||
|
|
||||||
|
@ -408,6 +417,7 @@ module Zip
|
||||||
|
|
||||||
def get_extra_attributes_from_path(path) # :nodoc:
|
def get_extra_attributes_from_path(path) # :nodoc:
|
||||||
return if 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
|
||||||
|
@ -494,6 +504,7 @@ module Zip
|
||||||
|
|
||||||
def ==(other)
|
def ==(other)
|
||||||
return false unless other.class == self.class
|
return false unless other.class == self.class
|
||||||
|
|
||||||
# Compares contents of local entry and exposed fields
|
# Compares contents of local entry and exposed fields
|
||||||
keys_equal = %w[compression_method crc compressed_size size name extra filepath].all? do |k|
|
keys_equal = %w[compression_method crc compressed_size size name extra filepath].all? do |k|
|
||||||
other.__send__(k.to_sym) == __send__(k.to_sym)
|
other.__send__(k.to_sym) == __send__(k.to_sym)
|
||||||
|
@ -635,6 +646,7 @@ module Zip
|
||||||
|
|
||||||
def create_directory(dest_path)
|
def create_directory(dest_path)
|
||||||
return if ::File.directory?(dest_path)
|
return if ::File.directory?(dest_path)
|
||||||
|
|
||||||
if ::File.exist?(dest_path)
|
if ::File.exist?(dest_path)
|
||||||
if block_given? && yield(self, dest_path)
|
if block_given? && yield(self, dest_path)
|
||||||
::FileUtils.rm_f dest_path
|
::FileUtils.rm_f dest_path
|
||||||
|
@ -659,6 +671,7 @@ module Zip
|
||||||
# (required when file sizes exceed 2**32, but can be used for all files)
|
# (required when file sizes exceed 2**32, but can be used for all files)
|
||||||
def parse_zip64_extra(for_local_header) #:nodoc:all
|
def parse_zip64_extra(for_local_header) #:nodoc:all
|
||||||
return if @extra['Zip64'].nil?
|
return if @extra['Zip64'].nil?
|
||||||
|
|
||||||
if for_local_header
|
if for_local_header
|
||||||
@size, @compressed_size = @extra['Zip64'].parse(@size, @compressed_size)
|
@size, @compressed_size = @extra['Zip64'].parse(@size, @compressed_size)
|
||||||
else
|
else
|
||||||
|
@ -673,6 +686,7 @@ module Zip
|
||||||
# create a zip64 extra information field if we need one
|
# create a zip64 extra information field if we need one
|
||||||
def prep_zip64_extra(for_local_header) #:nodoc:all
|
def prep_zip64_extra(for_local_header) #:nodoc:all
|
||||||
return unless ::Zip.write_zip64_support
|
return unless ::Zip.write_zip64_support
|
||||||
|
|
||||||
need_zip64 = @size >= 0xFFFFFFFF || @compressed_size >= 0xFFFFFFFF
|
need_zip64 = @size >= 0xFFFFFFFF || @compressed_size >= 0xFFFFFFFF
|
||||||
need_zip64 ||= @local_header_offset >= 0xFFFFFFFF unless for_local_header
|
need_zip64 ||= @local_header_offset >= 0xFFFFFFFF unless for_local_header
|
||||||
if need_zip64
|
if need_zip64
|
||||||
|
|
|
@ -50,6 +50,7 @@ module Zip
|
||||||
|
|
||||||
def ==(other)
|
def ==(other)
|
||||||
return false unless other.kind_of?(EntrySet)
|
return false unless other.kind_of?(EntrySet)
|
||||||
|
|
||||||
@entry_set.values == other.entry_set.values
|
@entry_set.values == other.entry_set.values
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -60,6 +61,7 @@ module Zip
|
||||||
def glob(pattern, flags = ::File::FNM_PATHNAME | ::File::FNM_DOTMATCH | ::File::FNM_EXTGLOB)
|
def glob(pattern, flags = ::File::FNM_PATHNAME | ::File::FNM_DOTMATCH | ::File::FNM_EXTGLOB)
|
||||||
entries.map do |entry|
|
entries.map do |entry|
|
||||||
next nil unless ::File.fnmatch(pattern, entry.name.chomp('/'), flags)
|
next nil unless ::File.fnmatch(pattern, entry.name.chomp('/'), flags)
|
||||||
|
|
||||||
yield(entry) if block_given?
|
yield(entry) if block_given?
|
||||||
entry
|
entry
|
||||||
end.compact
|
end.compact
|
||||||
|
|
|
@ -36,6 +36,7 @@ module Zip
|
||||||
|
|
||||||
def merge(binstr)
|
def merge(binstr)
|
||||||
return if binstr.empty?
|
return if binstr.empty?
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
while i < binstr.bytesize
|
while i < binstr.bytesize
|
||||||
id = binstr[i, 2]
|
id = binstr[i, 2]
|
||||||
|
@ -54,6 +55,7 @@ module Zip
|
||||||
unless (field_class = ID_MAP.values.find { |k| k.name == name })
|
unless (field_class = ID_MAP.values.find { |k| k.name == name })
|
||||||
raise Error, "Unknown extra field '#{name}'"
|
raise Error, "Unknown extra field '#{name}'"
|
||||||
end
|
end
|
||||||
|
|
||||||
self[name] = field_class.new
|
self[name] = field_class.new
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -19,11 +19,13 @@ module Zip
|
||||||
warn 'WARNING: weird extra field header ID. Skip parsing it.'
|
warn 'WARNING: weird extra field header ID. Skip parsing it.'
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
[binstr[2, 2].unpack('v')[0], binstr[4..-1]]
|
[binstr[2, 2].unpack('v')[0], binstr[4..-1]]
|
||||||
end
|
end
|
||||||
|
|
||||||
def ==(other)
|
def ==(other)
|
||||||
return false if self.class != other.class
|
return false if self.class != other.class
|
||||||
|
|
||||||
each do |k, v|
|
each do |k, v|
|
||||||
return false if v != other[k]
|
return false if v != other[k]
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,6 +19,7 @@ module Zip
|
||||||
|
|
||||||
def merge(binstr)
|
def merge(binstr)
|
||||||
return if binstr.empty?
|
return if binstr.empty?
|
||||||
|
|
||||||
size, content = initial_parse(binstr)
|
size, content = initial_parse(binstr)
|
||||||
(size && content) || return
|
(size && content) || return
|
||||||
|
|
||||||
|
@ -27,6 +28,7 @@ module Zip
|
||||||
|
|
||||||
tag1 = tags[1]
|
tag1 = tags[1]
|
||||||
return unless 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)
|
||||||
|
@ -65,12 +67,14 @@ module Zip
|
||||||
|
|
||||||
def parse_tags(content)
|
def parse_tags(content)
|
||||||
return {} if content.nil?
|
return {} if content.nil?
|
||||||
|
|
||||||
tags = {}
|
tags = {}
|
||||||
i = 0
|
i = 0
|
||||||
while i < content.bytesize
|
while i < content.bytesize
|
||||||
tag, size = content[i, 4].unpack('vv')
|
tag, size = content[i, 4].unpack('vv')
|
||||||
i += 4
|
i += 4
|
||||||
break unless tag && size
|
break unless tag && size
|
||||||
|
|
||||||
value = content[i, size]
|
value = content[i, size]
|
||||||
i += size
|
i += size
|
||||||
tags[tag] = value
|
tags[tag] = value
|
||||||
|
|
|
@ -16,9 +16,11 @@ module Zip
|
||||||
|
|
||||||
def merge(binstr)
|
def merge(binstr)
|
||||||
return if binstr.empty?
|
return if binstr.empty?
|
||||||
|
|
||||||
size, content = initial_parse(binstr)
|
size, content = initial_parse(binstr)
|
||||||
# size: 0 for central directory. 4 for local header
|
# size: 0 for central directory. 4 for local header
|
||||||
return if !size || size == 0
|
return if !size || size == 0
|
||||||
|
|
||||||
atime, mtime, uid, gid = content.unpack('VVvv')
|
atime, mtime, uid, gid = content.unpack('VVvv')
|
||||||
@uid ||= uid
|
@uid ||= uid
|
||||||
@gid ||= gid
|
@gid ||= gid
|
||||||
|
|
|
@ -44,10 +44,13 @@ module Zip
|
||||||
|
|
||||||
# Parse the timestamps, in order, based on which flags are set.
|
# Parse the timestamps, in order, based on which flags are set.
|
||||||
return if times[0].nil?
|
return if times[0].nil?
|
||||||
|
|
||||||
@mtime ||= ::Zip::DOSTime.at(times.shift) unless @flag & MTIME_MASK == 0
|
@mtime ||= ::Zip::DOSTime.at(times.shift) unless @flag & MTIME_MASK == 0
|
||||||
return if times[0].nil?
|
return if times[0].nil?
|
||||||
|
|
||||||
@atime ||= ::Zip::DOSTime.at(times.shift) unless @flag & ATIME_MASK == 0
|
@atime ||= ::Zip::DOSTime.at(times.shift) unless @flag & ATIME_MASK == 0
|
||||||
return if times[0].nil?
|
return if times[0].nil?
|
||||||
|
|
||||||
@ctime ||= ::Zip::DOSTime.at(times.shift) unless @flag & CTIME_MASK == 0
|
@ctime ||= ::Zip::DOSTime.at(times.shift) unless @flag & CTIME_MASK == 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -14,9 +14,11 @@ module Zip
|
||||||
|
|
||||||
def merge(binstr)
|
def merge(binstr)
|
||||||
return if binstr.empty?
|
return if binstr.empty?
|
||||||
|
|
||||||
size, content = initial_parse(binstr)
|
size, content = initial_parse(binstr)
|
||||||
# size: 0 for central directory. 4 for local header
|
# size: 0 for central directory. 4 for local header
|
||||||
return if !size || size == 0
|
return if !size || size == 0
|
||||||
|
|
||||||
uid, gid = content.unpack('vv')
|
uid, gid = content.unpack('vv')
|
||||||
@uid ||= uid
|
@uid ||= uid
|
||||||
@gid ||= gid
|
@gid ||= gid
|
||||||
|
|
|
@ -26,6 +26,7 @@ module Zip
|
||||||
|
|
||||||
def merge(binstr)
|
def merge(binstr)
|
||||||
return if binstr.empty?
|
return if binstr.empty?
|
||||||
|
|
||||||
_, @content = initial_parse(binstr)
|
_, @content = initial_parse(binstr)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -52,6 +53,7 @@ module Zip
|
||||||
def pack_for_local
|
def pack_for_local
|
||||||
# local header entries must contain original size and compressed size; other fields do not apply
|
# local header entries must contain original size and compressed size; other fields do not apply
|
||||||
return '' unless @original_size && @compressed_size
|
return '' unless @original_size && @compressed_size
|
||||||
|
|
||||||
[@original_size, @compressed_size].pack('Q<Q<')
|
[@original_size, @compressed_size].pack('Q<Q<')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -120,6 +120,7 @@ module Zip
|
||||||
def open(file_name, create = false, options = {})
|
def open(file_name, create = false, options = {})
|
||||||
zf = ::Zip::File.new(file_name, create, false, options)
|
zf = ::Zip::File.new(file_name, create, false, options)
|
||||||
return zf unless block_given?
|
return zf unless block_given?
|
||||||
|
|
||||||
begin
|
begin
|
||||||
yield zf
|
yield zf
|
||||||
ensure
|
ensure
|
||||||
|
@ -151,6 +152,7 @@ module Zip
|
||||||
|
|
||||||
zf = ::Zip::File.new(io, true, true, options)
|
zf = ::Zip::File.new(io, true, true, options)
|
||||||
return zf unless block_given?
|
return zf unless block_given?
|
||||||
|
|
||||||
yield zf
|
yield zf
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
@ -229,9 +231,11 @@ module Zip
|
||||||
def split(zip_file_name, segment_size = MAX_SEGMENT_SIZE, delete_zip_file = true, partial_zip_file_name = nil)
|
def split(zip_file_name, segment_size = MAX_SEGMENT_SIZE, delete_zip_file = true, partial_zip_file_name = nil)
|
||||||
raise Error, "File #{zip_file_name} not found" unless ::File.exist?(zip_file_name)
|
raise Error, "File #{zip_file_name} not found" unless ::File.exist?(zip_file_name)
|
||||||
raise Errno::ENOENT, zip_file_name unless ::File.readable?(zip_file_name)
|
raise Errno::ENOENT, zip_file_name unless ::File.readable?(zip_file_name)
|
||||||
|
|
||||||
zip_file_size = ::File.size(zip_file_name)
|
zip_file_size = ::File.size(zip_file_name)
|
||||||
segment_size = get_segment_size_for_split(segment_size)
|
segment_size = get_segment_size_for_split(segment_size)
|
||||||
return if zip_file_size <= segment_size
|
return if zip_file_size <= segment_size
|
||||||
|
|
||||||
segment_count = get_segment_count_for_split(zip_file_size, segment_size)
|
segment_count = get_segment_count_for_split(zip_file_size, segment_size)
|
||||||
# Checking for correct zip structure
|
# Checking for correct zip structure
|
||||||
::Zip::File.open(zip_file_name) {}
|
::Zip::File.open(zip_file_name) {}
|
||||||
|
@ -337,6 +341,7 @@ module Zip
|
||||||
# the zip archive.
|
# the zip archive.
|
||||||
def commit
|
def commit
|
||||||
return if name.is_a?(StringIO) || !commit_required?
|
return if name.is_a?(StringIO) || !commit_required?
|
||||||
|
|
||||||
on_success_replace do |tmp_file|
|
on_success_replace do |tmp_file|
|
||||||
::Zip::OutputStream.open(tmp_file) do |zos|
|
::Zip::OutputStream.open(tmp_file) do |zos|
|
||||||
@entry_set.each do |e|
|
@entry_set.each do |e|
|
||||||
|
@ -402,6 +407,7 @@ module Zip
|
||||||
# Creates a directory
|
# Creates a directory
|
||||||
def mkdir(entryName, permissionInt = 0o755)
|
def mkdir(entryName, permissionInt = 0o755)
|
||||||
raise Errno::EEXIST, "File exists - #{entryName}" if find_entry(entryName)
|
raise Errno::EEXIST, "File exists - #{entryName}" if find_entry(entryName)
|
||||||
|
|
||||||
entryName = entryName.dup.to_s
|
entryName = entryName.dup.to_s
|
||||||
entryName << '/' unless entryName.end_with?('/')
|
entryName << '/' unless entryName.end_with?('/')
|
||||||
@entry_set << ::Zip::StreamableDirectory.new(@name, entryName, nil, permissionInt)
|
@entry_set << ::Zip::StreamableDirectory.new(@name, entryName, nil, permissionInt)
|
||||||
|
@ -424,6 +430,7 @@ 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 }
|
||||||
return unless @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
|
||||||
|
|
|
@ -176,6 +176,7 @@ module Zip
|
||||||
unless exists?(fileName)
|
unless exists?(fileName)
|
||||||
raise Errno::ENOENT, "No such file or directory - #{fileName}"
|
raise Errno::ENOENT, "No such file or directory - #{fileName}"
|
||||||
end
|
end
|
||||||
|
|
||||||
@mappedZip.find_entry(fileName)
|
@mappedZip.find_entry(fileName)
|
||||||
end
|
end
|
||||||
private :get_entry
|
private :get_entry
|
||||||
|
@ -382,6 +383,7 @@ module Zip
|
||||||
|
|
||||||
def stat(fileName)
|
def stat(fileName)
|
||||||
raise Errno::ENOENT, fileName unless exists?(fileName)
|
raise Errno::ENOENT, fileName unless exists?(fileName)
|
||||||
|
|
||||||
ZipFsStat.new(self, fileName)
|
ZipFsStat.new(self, fileName)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -408,6 +410,7 @@ module Zip
|
||||||
if directory?(fileName)
|
if directory?(fileName)
|
||||||
raise Errno::EISDIR, "Is a directory - \"#{fileName}\""
|
raise Errno::EISDIR, "Is a directory - \"#{fileName}\""
|
||||||
end
|
end
|
||||||
|
|
||||||
@mappedZip.remove(fileName)
|
@mappedZip.remove(fileName)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -462,6 +465,7 @@ module Zip
|
||||||
unless @file.stat(aDirectoryName).directory?
|
unless @file.stat(aDirectoryName).directory?
|
||||||
raise Errno::EINVAL, "Invalid argument - #{aDirectoryName}"
|
raise Errno::EINVAL, "Invalid argument - #{aDirectoryName}"
|
||||||
end
|
end
|
||||||
|
|
||||||
@mappedZip.pwd = @file.expand_path(aDirectoryName)
|
@mappedZip.pwd = @file.expand_path(aDirectoryName)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -479,6 +483,7 @@ module Zip
|
||||||
unless @file.stat(aDirectoryName).directory?
|
unless @file.stat(aDirectoryName).directory?
|
||||||
raise Errno::ENOTDIR, aDirectoryName
|
raise Errno::ENOTDIR, aDirectoryName
|
||||||
end
|
end
|
||||||
|
|
||||||
path = @file.expand_path(aDirectoryName)
|
path = @file.expand_path(aDirectoryName)
|
||||||
path << '/' unless path.end_with?('/')
|
path << '/' unless path.end_with?('/')
|
||||||
path = Regexp.escape(path)
|
path = Regexp.escape(path)
|
||||||
|
@ -493,6 +498,7 @@ module Zip
|
||||||
unless @file.stat(entryName).directory?
|
unless @file.stat(entryName).directory?
|
||||||
raise Errno::EINVAL, "Invalid argument - #{entryName}"
|
raise Errno::EINVAL, "Invalid argument - #{entryName}"
|
||||||
end
|
end
|
||||||
|
|
||||||
@mappedZip.remove(entryName)
|
@mappedZip.remove(entryName)
|
||||||
end
|
end
|
||||||
alias rmdir delete
|
alias rmdir delete
|
||||||
|
@ -521,26 +527,31 @@ module Zip
|
||||||
|
|
||||||
def each(&aProc)
|
def each(&aProc)
|
||||||
raise IOError, 'closed directory' if @fileNames.nil?
|
raise IOError, 'closed directory' if @fileNames.nil?
|
||||||
|
|
||||||
@fileNames.each(&aProc)
|
@fileNames.each(&aProc)
|
||||||
end
|
end
|
||||||
|
|
||||||
def read
|
def read
|
||||||
raise IOError, 'closed directory' if @fileNames.nil?
|
raise IOError, 'closed directory' if @fileNames.nil?
|
||||||
|
|
||||||
@fileNames[(@index += 1) - 1]
|
@fileNames[(@index += 1) - 1]
|
||||||
end
|
end
|
||||||
|
|
||||||
def rewind
|
def rewind
|
||||||
raise IOError, 'closed directory' if @fileNames.nil?
|
raise IOError, 'closed directory' if @fileNames.nil?
|
||||||
|
|
||||||
@index = 0
|
@index = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
def seek(anIntegerPosition)
|
def seek(anIntegerPosition)
|
||||||
raise IOError, 'closed directory' if @fileNames.nil?
|
raise IOError, 'closed directory' if @fileNames.nil?
|
||||||
|
|
||||||
@index = anIntegerPosition
|
@index = anIntegerPosition
|
||||||
end
|
end
|
||||||
|
|
||||||
def tell
|
def tell
|
||||||
raise IOError, 'closed directory' if @fileNames.nil?
|
raise IOError, 'closed directory' if @fileNames.nil?
|
||||||
|
|
||||||
@index
|
@index
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,6 +12,7 @@ module Zip
|
||||||
|
|
||||||
while length.nil? || (@buffer.bytesize < length)
|
while length.nil? || (@buffer.bytesize < length)
|
||||||
break if input_finished?
|
break if input_finished?
|
||||||
|
|
||||||
@buffer << produce_input
|
@buffer << produce_input
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -32,6 +33,7 @@ module Zip
|
||||||
@zlib_inflater.inflate(input_stream.read(Decompressor::CHUNK_SIZE))
|
@zlib_inflater.inflate(input_stream.read(Decompressor::CHUNK_SIZE))
|
||||||
rescue Zlib::BufError
|
rescue Zlib::BufError
|
||||||
raise if retried >= 5 # how many times should we retry?
|
raise if retried >= 5 # how many times should we retry?
|
||||||
|
|
||||||
retried += 1
|
retried += 1
|
||||||
retry
|
retry
|
||||||
end
|
end
|
||||||
|
|
|
@ -73,6 +73,7 @@ module Zip
|
||||||
# Rewinds the stream to the beginning of the current entry
|
# Rewinds the stream to the beginning of the current entry
|
||||||
def rewind
|
def rewind
|
||||||
return if @current_entry.nil?
|
return if @current_entry.nil?
|
||||||
|
|
||||||
@lineno = 0
|
@lineno = 0
|
||||||
@pos = 0
|
@pos = 0
|
||||||
@archive_io.seek(@current_entry.local_header_offset, IO::SEEK_SET)
|
@archive_io.seek(@current_entry.local_header_offset, IO::SEEK_SET)
|
||||||
|
@ -91,6 +92,7 @@ module Zip
|
||||||
def open(filename_or_io, offset = 0, decrypter = nil)
|
def open(filename_or_io, offset = 0, decrypter = nil)
|
||||||
zio = new(filename_or_io, offset, decrypter)
|
zio = new(filename_or_io, offset, decrypter)
|
||||||
return zio unless block_given?
|
return zio unless block_given?
|
||||||
|
|
||||||
begin
|
begin
|
||||||
yield zio
|
yield zio
|
||||||
ensure
|
ensure
|
||||||
|
@ -123,6 +125,7 @@ module Zip
|
||||||
if @current_entry && @current_entry.encrypted? && @decrypter.is_a?(NullEncrypter)
|
if @current_entry && @current_entry.encrypted? && @decrypter.is_a?(NullEncrypter)
|
||||||
raise Error, 'password required to decode zip file'
|
raise Error, 'password required to decode zip file'
|
||||||
end
|
end
|
||||||
|
|
||||||
if @current_entry && @current_entry.incomplete? && @current_entry.crc == 0 \
|
if @current_entry && @current_entry.incomplete? && @current_entry.crc == 0 \
|
||||||
&& @current_entry.compressed_size == 0 \
|
&& @current_entry.compressed_size == 0 \
|
||||||
&& @current_entry.size == 0 && !@complete_entry
|
&& @current_entry.size == 0 && !@complete_entry
|
||||||
|
|
|
@ -35,6 +35,7 @@ module Zip
|
||||||
|
|
||||||
if tbuf.nil? || tbuf.empty?
|
if tbuf.nil? || tbuf.empty?
|
||||||
return nil if number_of_bytes
|
return nil if number_of_bytes
|
||||||
|
|
||||||
return ''
|
return ''
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -69,6 +70,7 @@ module Zip
|
||||||
end
|
end
|
||||||
|
|
||||||
return read(number_of_bytes) if a_sep_string.nil?
|
return read(number_of_bytes) if a_sep_string.nil?
|
||||||
|
|
||||||
a_sep_string = "#{$/}#{$/}" if a_sep_string.empty?
|
a_sep_string = "#{$/}#{$/}" if a_sep_string.empty?
|
||||||
|
|
||||||
buffer_index = 0
|
buffer_index = 0
|
||||||
|
@ -76,6 +78,7 @@ module Zip
|
||||||
while (match_index = @output_buffer.index(a_sep_string, buffer_index)).nil? && !over_limit
|
while (match_index = @output_buffer.index(a_sep_string, buffer_index)).nil? && !over_limit
|
||||||
buffer_index = [buffer_index, @output_buffer.bytesize - a_sep_string.bytesize].max
|
buffer_index = [buffer_index, @output_buffer.bytesize - a_sep_string.bytesize].max
|
||||||
return @output_buffer.empty? ? nil : flush if input_finished?
|
return @output_buffer.empty? ? nil : flush if input_finished?
|
||||||
|
|
||||||
@output_buffer << produce_input
|
@output_buffer << produce_input
|
||||||
over_limit = (number_of_bytes && @output_buffer.bytesize >= number_of_bytes)
|
over_limit = (number_of_bytes && @output_buffer.bytesize >= number_of_bytes)
|
||||||
end
|
end
|
||||||
|
@ -97,6 +100,7 @@ module Zip
|
||||||
def readline(a_sep_string = $/)
|
def readline(a_sep_string = $/)
|
||||||
ret_val = gets(a_sep_string)
|
ret_val = gets(a_sep_string)
|
||||||
raise EOFError unless ret_val
|
raise EOFError unless ret_val
|
||||||
|
|
||||||
ret_val
|
ret_val
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,7 @@ module Zip
|
||||||
class << self
|
class << self
|
||||||
def open(file_name, encrypter = nil)
|
def open(file_name, encrypter = nil)
|
||||||
return new(file_name) unless block_given?
|
return new(file_name) unless block_given?
|
||||||
|
|
||||||
zos = new(file_name, false, encrypter)
|
zos = new(file_name, false, encrypter)
|
||||||
yield zos
|
yield zos
|
||||||
ensure
|
ensure
|
||||||
|
@ -66,6 +67,7 @@ module Zip
|
||||||
# Closes the stream and writes the central directory to the zip file
|
# Closes the stream and writes the central directory to the zip file
|
||||||
def close
|
def close
|
||||||
return if @closed
|
return if @closed
|
||||||
|
|
||||||
finalize_current_entry
|
finalize_current_entry
|
||||||
update_local_headers
|
update_local_headers
|
||||||
write_central_directory
|
write_central_directory
|
||||||
|
@ -76,6 +78,7 @@ module Zip
|
||||||
# Closes the stream and writes the central directory to the zip file
|
# Closes the stream and writes the central directory to the zip file
|
||||||
def close_buffer
|
def close_buffer
|
||||||
return @output_stream if @closed
|
return @output_stream if @closed
|
||||||
|
|
||||||
finalize_current_entry
|
finalize_current_entry
|
||||||
update_local_headers
|
update_local_headers
|
||||||
write_central_directory
|
write_central_directory
|
||||||
|
@ -87,6 +90,7 @@ module Zip
|
||||||
# +entry+ can be a ZipEntry object or a string.
|
# +entry+ can be a ZipEntry object or a string.
|
||||||
def put_next_entry(entry_name, comment = nil, extra = nil, compression_method = Entry::DEFLATED, level = Zip.default_compression)
|
def put_next_entry(entry_name, comment = nil, extra = nil, compression_method = Entry::DEFLATED, level = Zip.default_compression)
|
||||||
raise Error, 'zip stream is closed' if @closed
|
raise Error, 'zip stream is closed' if @closed
|
||||||
|
|
||||||
new_entry = if entry_name.kind_of?(Entry)
|
new_entry = if entry_name.kind_of?(Entry)
|
||||||
entry_name
|
entry_name
|
||||||
else
|
else
|
||||||
|
@ -105,6 +109,7 @@ module Zip
|
||||||
entry = entry.dup
|
entry = entry.dup
|
||||||
raise Error, 'zip stream is closed' if @closed
|
raise Error, 'zip stream is closed' if @closed
|
||||||
raise Error, 'entry is not a ZipEntry' unless entry.is_a?(Entry)
|
raise Error, 'entry is not a ZipEntry' unless entry.is_a?(Entry)
|
||||||
|
|
||||||
finalize_current_entry
|
finalize_current_entry
|
||||||
@entry_set << entry
|
@entry_set << entry
|
||||||
src_pos = entry.local_header_offset
|
src_pos = entry.local_header_offset
|
||||||
|
@ -123,6 +128,7 @@ module Zip
|
||||||
|
|
||||||
def finalize_current_entry
|
def finalize_current_entry
|
||||||
return unless @current_entry
|
return unless @current_entry
|
||||||
|
|
||||||
finish
|
finish
|
||||||
@current_entry.compressed_size = @output_stream.tell - @current_entry.local_header_offset - @current_entry.calculate_local_header_size
|
@current_entry.compressed_size = @output_stream.tell - @current_entry.local_header_offset - @current_entry.calculate_local_header_size
|
||||||
@current_entry.size = @compressor.size
|
@current_entry.size = @compressor.size
|
||||||
|
|
|
@ -22,6 +22,7 @@ module Zip
|
||||||
unless @temp_file.closed?
|
unless @temp_file.closed?
|
||||||
raise StandardError, "cannot open entry for reading while its open for writing - #{name}"
|
raise StandardError, "cannot open entry for reading while its open for writing - #{name}"
|
||||||
end
|
end
|
||||||
|
|
||||||
@temp_file.open # reopens tempfile from top
|
@temp_file.open # reopens tempfile from top
|
||||||
@temp_file.binmode
|
@temp_file.binmode
|
||||||
if block_given?
|
if block_given?
|
||||||
|
|
|
@ -13,6 +13,7 @@ module Zip
|
||||||
Find.find(path) do |fileName|
|
Find.find(path) do |fileName|
|
||||||
yield(fileName)
|
yield(fileName)
|
||||||
next unless zipFilePattern.match(fileName) && File.file?(fileName)
|
next unless zipFilePattern.match(fileName) && File.file?(fileName)
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Zip::File.foreach(fileName) do |zipEntry|
|
Zip::File.foreach(fileName) do |zipEntry|
|
||||||
yield(fileName + File::SEPARATOR + zipEntry.to_s)
|
yield(fileName + File::SEPARATOR + zipEntry.to_s)
|
||||||
|
|
|
@ -28,6 +28,7 @@ class ZipFileSplitTest < MiniTest::Test
|
||||||
result = ::Zip::File.split(TEST_ZIP.zip_name, 65_536, false)
|
result = ::Zip::File.split(TEST_ZIP.zip_name, 65_536, false)
|
||||||
|
|
||||||
return if 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
|
||||||
|
|
|
@ -623,6 +623,7 @@ class ZipFileTest < MiniTest::Test
|
||||||
Zip::File.open_buffer(f) do |zipfile|
|
Zip::File.open_buffer(f) do |zipfile|
|
||||||
zipfile.each do |entry|
|
zipfile.each do |entry|
|
||||||
next unless entry.name =~ /README.md/
|
next unless entry.name =~ /README.md/
|
||||||
|
|
||||||
data = zipfile.read(entry)
|
data = zipfile.read(entry)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -52,6 +52,7 @@ class TestFiles
|
||||||
def ensure_dir(name)
|
def ensure_dir(name)
|
||||||
if File.exist?(name)
|
if File.exist?(name)
|
||||||
return if File.stat(name).directory?
|
return if File.stat(name).directory?
|
||||||
|
|
||||||
File.delete(name)
|
File.delete(name)
|
||||||
end
|
end
|
||||||
Dir.mkdir(name)
|
Dir.mkdir(name)
|
||||||
|
|
Loading…
Reference in New Issue