Skip to content

Commit

Permalink
Update minimum ruby version to 3.0.
Browse files Browse the repository at this point in the history
All rubies before 3.0 are EOL and this is a major version bump, so it's
the right time to do this.
  • Loading branch information
hainesr committed Mar 1, 2024
1 parent b1ee5cf commit 1c06454
Show file tree
Hide file tree
Showing 38 changed files with 114 additions and 121 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Install and set up ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '2.6'
ruby-version: '3.0'
bundler-cache: true

- name: Rubocop
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu]
ruby: ['2.5', '2.6', '2.7', '3.0', '3.1', '3.2', '3.3', head, jruby, jruby-head, truffleruby, truffleruby-head]
ruby: ['3.0', '3.1', '3.2', '3.3', head, jruby, jruby-head, truffleruby, truffleruby-head]
include:
- { os: macos , ruby: '2.5' }
- { os: windows, ruby: '2.5' }
- { os: macos , ruby: '3.0' }
- { os: windows, ruby: '3.0' }
# head builds
- { os: windows, ruby: ucrt }
- { os: windows, ruby: mswin }
Expand Down
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ inherit_from: .rubocop_todo.yml
# we get errors if our ruby version doesn't match.
AllCops:
SuggestExtensions: false
TargetRubyVersion: 2.5
TargetRubyVersion: 3.0
NewCops: enable

# Allow this in this file because adding the extra lines is pointless.
Expand Down
3 changes: 3 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

Gemspec/DevelopmentDependencies:
Enabled: false

# Offense count: 7
Lint/MissingSuper:
Exclude:
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ RDoc::Task.new do |rdoc|
rdoc.rdoc_files.include('README.md', 'lib/**/*.rb')
rdoc.options << '--markup=markdown'
rdoc.options << '--tab-width=2'
rdoc.options << "-t Rubyzip version #{::Zip::VERSION}"
rdoc.options << "-t Rubyzip version #{Zip::VERSION}"
end

RuboCop::RakeTask.new
2 changes: 1 addition & 1 deletion lib/zip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def reset!
@on_exists_proc = false
@continue_on_exists_proc = false
@sort_entries = false
@default_compression = ::Zlib::DEFAULT_COMPRESSION
@default_compression = Zlib::DEFAULT_COMPRESSION
@write_zip64_support = true
@warn_invalid_date = true
@case_insensitive_match = false
Expand Down
20 changes: 10 additions & 10 deletions lib/zip/central_directory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class CentralDirectory # :nodoc:

mark_dirty :<<, :comment=, :delete

def initialize(entries = EntrySet.new, comment = '') #:nodoc:
def initialize(entries = EntrySet.new, comment = '') # :nodoc:
super(dirty_on_create: false)
@entry_set = entries.kind_of?(EntrySet) ? entries : EntrySet.new(entries)
@comment = comment
Expand All @@ -39,7 +39,7 @@ def read_from_stream(io)
read_central_directory_entries(io)
end

def write_to_stream(io) #:nodoc:
def write_to_stream(io) # :nodoc:
cdir_offset = io.tell
@entry_set.each { |entry| entry.write_c_dir_entry(io) }
eocd_offset = io.tell
Expand All @@ -61,15 +61,15 @@ def count_entries(io)
@size
end

def ==(other) #:nodoc:
def ==(other) # :nodoc:
return false unless other.kind_of?(CentralDirectory)

@entry_set.entries.sort == other.entries.sort && comment == other.comment
end

private

def write_e_o_c_d(io, offset, cdir_size) #:nodoc:
def write_e_o_c_d(io, offset, cdir_size) # :nodoc:
tmp = [
END_OF_CD_SIG,
0, # @numberOfThisDisk
Expand All @@ -84,7 +84,7 @@ def write_e_o_c_d(io, offset, cdir_size) #:nodoc:
io << @comment
end

def write_64_e_o_c_d(io, offset, cdir_size) #:nodoc:
def write_64_e_o_c_d(io, offset, cdir_size) # :nodoc:
tmp = [
ZIP64_END_OF_CD_SIG,
44, # size of zip64 end of central directory record (excludes signature and field itself)
Expand All @@ -110,7 +110,7 @@ def write_64_eocd_locator(io, zip64_eocd_offset)
io << tmp.pack('VVQ<V')
end

def unpack_64_e_o_c_d(buffer) #:nodoc:
def unpack_64_e_o_c_d(buffer) # :nodoc:
_, # ZIP64_END_OF_CD_SIG. We know we have this at this point.
@size_of_zip64_e_o_c_d,
@version_made_by,
Expand All @@ -134,14 +134,14 @@ def unpack_64_e_o_c_d(buffer) #:nodoc:
end
end

def unpack_64_eocd_locator(buffer) #:nodoc:
def unpack_64_eocd_locator(buffer) # :nodoc:
_, # ZIP64_EOCD_LOCATOR_SIG. We know we have this at this point.
_, zip64_eocd_offset, = buffer.unpack('VVQ<V')

zip64_eocd_offset
end

def unpack_e_o_c_d(buffer) #:nodoc:
def unpack_e_o_c_d(buffer) # :nodoc:
_, # END_OF_CD_SIG. We know we have this at this point.
num_disk,
num_disk_cdir,
Expand All @@ -165,7 +165,7 @@ def unpack_e_o_c_d(buffer) #:nodoc:
end
end

def read_central_directory_entries(io) #:nodoc:
def read_central_directory_entries(io) # :nodoc:
# `StringIO` doesn't raise `EINVAL` if you seek beyond the current end,
# so we need to catch that *and* query `io#eof?` here.
eof = false
Expand Down Expand Up @@ -209,7 +209,7 @@ def read_local_extra_field(io)
io.read(e_len)
end

def read_eocds(io) #:nodoc:
def read_eocds(io) # :nodoc:
base_location, data = eocd_data(io)

eocd_location = data.rindex([END_OF_CD_SIG].pack('V'))
Expand Down
2 changes: 1 addition & 1 deletion lib/zip/crypto/traditional_encryption.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def reset_keys!

def update_keys(num)
@key0 = ~Zlib.crc32(num, ~@key0)
@key1 = ((@key1 + (@key0 & 0xff)) * 134_775_813 + 1) & 0xffffffff
@key1 = (((@key1 + (@key0 & 0xff)) * 134_775_813) + 1) & 0xffffffff
@key2 = ~Zlib.crc32((@key1 >> 24).chr, ~@key2)
end

Expand Down
34 changes: 17 additions & 17 deletions lib/zip/entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,12 @@ def ftype # :nodoc:

# Dynamic checkers
%w[directory file symlink].each do |k|
define_method "#{k}?" do
define_method :"#{k}?" do
file_type_is?(k.to_sym)
end
end

def name_is_directory? #:nodoc:all
def name_is_directory? # :nodoc:all
@name.end_with?('/')
end

Expand All @@ -207,7 +207,7 @@ def name_safe?
::File.absolute_path(cleanpath.to_s, root).match?(/([A-Z]:)?#{naive}/i)
end

def local_entry_offset #:nodoc:all
def local_entry_offset # :nodoc:all
local_header_offset + @local_header_size
end

Expand All @@ -223,7 +223,7 @@ def comment_size
@comment ? @comment.bytesize : 0
end

def calculate_local_header_size #:nodoc:all
def calculate_local_header_size # :nodoc:all
LOCAL_ENTRY_STATIC_HEADER_LENGTH + name_size + extra_size
end

Expand All @@ -239,12 +239,12 @@ def verify_local_header_size!
"Local header size changed (#{@local_header_size} -> #{new_size})"
end

def cdir_header_size #:nodoc:all
def cdir_header_size # :nodoc:all
CDIR_ENTRY_STATIC_HEADER_LENGTH + name_size +
(@extra ? @extra.c_dir_size : 0) + comment_size
end

def next_header_offset #:nodoc:all
def next_header_offset # :nodoc:all
local_entry_offset + compressed_size
end

Expand All @@ -266,7 +266,7 @@ def extract(entry_path = @name, destination_directory: '.', &block)

raise "unknown file type #{inspect}" unless directory? || file? || symlink?

__send__("create_#{ftype}", extract_path, &block)
__send__(:"create_#{ftype}", extract_path, &block)
self
end

Expand All @@ -275,7 +275,7 @@ def to_s
end

class << self
def read_c_dir_entry(io) #:nodoc:all
def read_c_dir_entry(io) # :nodoc:all
path = if io.respond_to?(:path)
io.path
else
Expand Down Expand Up @@ -314,7 +314,7 @@ def unpack_local_entry(buf)
@extra_length = buf.unpack('VCCvvvvVVVvv')
end

def read_local_entry(io) #:nodoc:all
def read_local_entry(io) # :nodoc:all
@dirty = false # No changes at this point.
@local_header_offset = io.tell

Expand Down Expand Up @@ -371,7 +371,7 @@ def pack_local_entry
@extra ? @extra.local_size : 0].pack('VvvvvvVVVvv')
end

def write_local_entry(io, rewrite: false) #:nodoc:all
def write_local_entry(io, rewrite: false) # :nodoc:all
prep_local_zip64_extra
verify_local_header_size! if rewrite
@local_header_offset = io.tell
Expand Down Expand Up @@ -463,7 +463,7 @@ def read_extra_field(buf, local: false)
end
end

def read_c_dir_entry(io) #:nodoc:all
def read_c_dir_entry(io) # :nodoc:all
@dirty = false # No changes at this point.
static_sized_fields_buf = io.read(::Zip::CDIR_ENTRY_STATIC_HEADER_LENGTH)
check_c_dir_entry_static_header_length(static_sized_fields_buf)
Expand Down Expand Up @@ -556,7 +556,7 @@ def pack_c_dir_entry
].pack('VCCvvvvvVVVvvvvvVV')
end

def write_c_dir_entry(io) #:nodoc:all
def write_c_dir_entry(io) # :nodoc:all
prep_cdir_zip64_extra

case @fstype
Expand All @@ -574,7 +574,7 @@ def write_c_dir_entry(io) #:nodoc:all
end

unless ft.nil?
@external_file_attributes = (ft << 12 | (@unix_perms & 0o7777)) << 16
@external_file_attributes = ((ft << 12) | (@unix_perms & 0o7777)) << 16
end
end

Expand Down Expand Up @@ -639,7 +639,7 @@ def gather_fileinfo_from_srcpath(src_path) # :nodoc:
if name_is_directory?
raise ArgumentError,
"entry name '#{newEntry}' indicates directory entry, but " \
"'#{src_path}' is not a directory"
"'#{src_path}' is not a directory"
end
:file
when 'directory'
Expand All @@ -649,7 +649,7 @@ def gather_fileinfo_from_srcpath(src_path) # :nodoc:
if name_is_directory?
raise ArgumentError,
"entry name '#{newEntry}' indicates directory entry, but " \
"'#{src_path}' is not a directory"
"'#{src_path}' is not a directory"
end
:symlink
else
Expand All @@ -661,7 +661,7 @@ def gather_fileinfo_from_srcpath(src_path) # :nodoc:
get_extra_attributes_from_path(@filepath)
end

def write_to_zip_output_stream(zip_output_stream) #:nodoc:all
def write_to_zip_output_stream(zip_output_stream) # :nodoc:all
if ftype == :directory
zip_output_stream.put_next_entry(self)
elsif @filepath
Expand Down Expand Up @@ -749,7 +749,7 @@ def create_symlink(dest_path)

# apply missing data from the zip64 extra information field, if present
# (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 unless zip64?

if for_local_header
Expand Down
4 changes: 2 additions & 2 deletions lib/zip/entry_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ def parent(entry)
end

def glob(pattern, flags = ::File::FNM_PATHNAME | ::File::FNM_DOTMATCH | ::File::FNM_EXTGLOB)
entries.map do |entry|
entries.filter_map do |entry|
next nil unless ::File.fnmatch(pattern, entry.name.chomp('/'), flags)

yield(entry) if block_given?
entry
end.compact
end
end

protected
Expand Down
6 changes: 3 additions & 3 deletions lib/zip/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def initialize(destination)

def message
"Cannot create file or directory '#{@destination}'. " \
'A file already exists with that name.'
'A file already exists with that name.'
end
end

Expand Down Expand Up @@ -111,8 +111,8 @@ def initialize(entry)

def message
"The local header of this entry ('#{@entry.name}') does not contain " \
'the correct metadata for `Zip::InputStream` to be able to ' \
'uncompress it. Please use `Zip::File` instead of `Zip::InputStream`.'
'the correct metadata for `Zip::InputStream` to be able to ' \
'uncompress it. Please use `Zip::File` instead of `Zip::InputStream`.'
end
end
end
4 changes: 2 additions & 2 deletions lib/zip/extra_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def extra_field_type_exist(binstr, id, len, index)
def extra_field_type_unknown(binstr, len, index, local)
self['Unknown'] ||= Unknown.new

if !len || len + 4 > binstr[index..-1].bytesize
self['Unknown'].merge(binstr[index..-1], local: local)
if !len || len + 4 > binstr[index..].bytesize
self['Unknown'].merge(binstr[index..], local: local)
return
end

Expand Down
6 changes: 3 additions & 3 deletions lib/zip/extra_field/generic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ def initial_parse(binstr)
return false
end

[binstr[2, 2].unpack1('v'), binstr[4..-1]]
[binstr[2, 2].unpack1('v'), binstr[4..]]
end

def to_local_bin
s = pack_for_local
self.class.const_get(:HEADER_ID) + [s.bytesize].pack('v') << s
(self.class.const_get(:HEADER_ID) + [s.bytesize].pack('v')) << s
end

def to_c_dir_bin
s = pack_for_c_dir
self.class.const_get(:HEADER_ID) + [s.bytesize].pack('v') << s
(self.class.const_get(:HEADER_ID) + [s.bytesize].pack('v')) << s
end
end
end
4 changes: 2 additions & 2 deletions lib/zip/extra_field/ntfs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def merge(binstr)
size, content = initial_parse(binstr)
(size && content) || return

content = content[4..-1]
content = content[4..]
tags = parse_tags(content)

tag1 = tags[1]
Expand Down Expand Up @@ -86,7 +86,7 @@ def parse_tags(content)
end

def from_ntfs_time(ntfs_time)
::Zip::DOSTime.at(ntfs_time / WINDOWS_TICK - SEC_TO_UNIX_EPOCH)
::Zip::DOSTime.at((ntfs_time / WINDOWS_TICK) - SEC_TO_UNIX_EPOCH)
end

def to_ntfs_time(time)
Expand Down
2 changes: 1 addition & 1 deletion lib/zip/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ def initialize_cdir(path_or_io, buffer: false)
# This zip is probably a non-empty StringIO.
@create = false
@cdir.read_from_stream(path_or_io)
elsif !@create && ::File.zero?(@name)
elsif !@create && ::File.empty?(@name)
# A file exists, but it is empty, and we've said we're
# NOT creating a new zip.
raise Error, "File #{@name} has zero size. Did you mean to pass the create flag?"
Expand Down

0 comments on commit 1c06454

Please sign in to comment.