Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update RuboCop settings and apply automatic corrections #332

Merged
merged 3 commits into from Aug 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion .rubocop.yml
@@ -1,2 +1,6 @@
inherit_from:
- .rubocop_rubyzip.yml
- .rubocop_rubyzip.yml
AllCops:
TargetRubyVersion: 1.9
Style/MutableConstant:
Enabled: false # Because some existent code relies on mutable constant
6 changes: 3 additions & 3 deletions lib/zip/central_directory.rb
Expand Up @@ -96,7 +96,7 @@ def read_64_e_o_c_d(buf) #:nodoc:
@size_in_bytes = Entry.read_zip_64_long(buf)
@cdir_offset = Entry.read_zip_64_long(buf)
@zip_64_extensible = buf.slice!(0, buf.bytesize)
raise Error, 'Zip consistency problem while reading eocd structure' unless buf.size == 0
raise Error, 'Zip consistency problem while reading eocd structure' unless buf.empty?
end

def read_e_o_c_d(buf) #:nodoc:
Expand All @@ -113,7 +113,7 @@ def read_e_o_c_d(buf) #:nodoc:
else
buf.read(comment_length)
end
raise Error, 'Zip consistency problem while reading eocd structure' unless buf.size == 0
raise Error, 'Zip consistency problem while reading eocd structure' unless buf.empty?
end

def read_central_directory_entries(io) #:nodoc:
Expand All @@ -130,7 +130,7 @@ def read_central_directory_entries(io) #:nodoc:

def read_from_stream(io) #:nodoc:
buf = start_buf(io)
if self.zip64_file?(buf)
if zip64_file?(buf)
read_64_e_o_c_d(buf)
else
read_e_o_c_d(buf)
Expand Down
3 changes: 1 addition & 2 deletions lib/zip/compressor.rb
@@ -1,7 +1,6 @@
module Zip
class Compressor #:nodoc:all
def finish
end
def finish; end
end
end

Expand Down
6 changes: 3 additions & 3 deletions lib/zip/constants.rb
Expand Up @@ -11,9 +11,9 @@ module Zip
VERSION_NEEDED_TO_EXTRACT = 20
VERSION_NEEDED_TO_EXTRACT_ZIP64 = 45

FILE_TYPE_FILE = 010
FILE_TYPE_DIR = 004
FILE_TYPE_SYMLINK = 012
FILE_TYPE_FILE = 0o10
FILE_TYPE_DIR = 0o04
FILE_TYPE_SYMLINK = 0o12

FSTYPE_FAT = 0
FSTYPE_AMIGA = 1
Expand Down
6 changes: 2 additions & 4 deletions lib/zip/crypto/null_encryption.rb
Expand Up @@ -24,8 +24,7 @@ def data_descriptor(_crc32, _compressed_size, _uncomprssed_size)
''
end

def reset!
end
def reset!; end
end

class NullDecrypter < Decrypter
Expand All @@ -35,8 +34,7 @@ def decrypt(data)
data
end

def reset!(_header)
end
def reset!(_header); end
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/zip/decompressor.rb
@@ -1,5 +1,5 @@
module Zip
class Decompressor #:nodoc:all
class Decompressor #:nodoc:all
CHUNK_SIZE = 32_768
def initialize(input_stream)
super()
Expand Down
2 changes: 1 addition & 1 deletion lib/zip/dos_time.rb
Expand Up @@ -19,7 +19,7 @@ def to_binary_dos_time
end

def to_binary_dos_date
(day) +
day +
(month << 5) +
((year - 1980) << 9)
end
Expand Down
34 changes: 17 additions & 17 deletions lib/zip/entry.rb
Expand Up @@ -99,7 +99,7 @@ def file_type_is?(type)
end

# Dynamic checkers
%w(directory file symlink).each do |k|
%w[directory file symlink].each do |k|
define_method "#{k}?" do
file_type_is?(k.to_sym)
end
Expand Down Expand Up @@ -239,7 +239,7 @@ def read_local_entry(io) #:nodoc:all
@name = io.read(@name_length)
extra = io.read(@extra_length)

@name.gsub!('\\', '/')
@name.tr!('\\', '/')

if extra && extra.bytesize != @extra_length
raise ::Zip::Error, 'Truncated local zip entry header'
Expand All @@ -263,8 +263,8 @@ def pack_local_entry
@time.to_binary_dos_time, # @last_mod_time ,
@time.to_binary_dos_date, # @last_mod_date ,
@crc,
(zip64 && zip64.compressed_size) ? 0xFFFFFFFF : @compressed_size,
(zip64 && zip64.original_size) ? 0xFFFFFFFF : @size,
zip64 && zip64.compressed_size ? 0xFFFFFFFF : @compressed_size,
zip64 && zip64.original_size ? 0xFFFFFFFF : @size,
name_size,
@extra ? @extra.local_size : 0].pack('VvvvvvVVVvv')
end
Expand Down Expand Up @@ -308,7 +308,7 @@ def unpack_c_dir_entry(buf)
def set_ftype_from_c_dir_entry
@ftype = case @fstype
when ::Zip::FSTYPE_UNIX
@unix_perms = (@external_file_attributes >> 16) & 07777
@unix_perms = (@external_file_attributes >> 16) & 0o7777
case (@external_file_attributes >> 28)
when ::Zip::FILE_TYPE_DIR
:directory
Expand Down Expand Up @@ -384,14 +384,14 @@ def get_extra_attributes_from_path(path) # :nodoc:
stat = file_stat(path)
@unix_uid = stat.uid
@unix_gid = stat.gid
@unix_perms = stat.mode & 07777
@unix_perms = stat.mode & 0o7777
end

def set_unix_permissions_on_path(dest_path)
# BUG: does not update timestamps into account
# ignore setuid/setgid bits by default. honor if @restore_ownership
unix_perms_mask = 01777
unix_perms_mask = 07777 if @restore_ownership
unix_perms_mask = 0o1777
unix_perms_mask = 0o7777 if @restore_ownership
::FileUtils.chmod(@unix_perms & unix_perms_mask, dest_path) if @restore_permissions && @unix_perms
::FileUtils.chown(@unix_uid, @unix_gid, dest_path) if @restore_ownership && @unix_uid && @unix_gid && ::Process.egid == 0
# File::utimes()
Expand All @@ -418,15 +418,15 @@ def pack_c_dir_entry
@time.to_binary_dos_time, # @last_mod_time ,
@time.to_binary_dos_date, # @last_mod_date ,
@crc,
(zip64 && zip64.compressed_size) ? 0xFFFFFFFF : @compressed_size,
(zip64 && zip64.original_size) ? 0xFFFFFFFF : @size,
zip64 && zip64.compressed_size ? 0xFFFFFFFF : @compressed_size,
zip64 && zip64.original_size ? 0xFFFFFFFF : @size,
name_size,
@extra ? @extra.c_dir_size : 0,
comment_size,
(zip64 && zip64.disk_start_number) ? 0xFFFF : 0, # disk number start
zip64 && zip64.disk_start_number ? 0xFFFF : 0, # disk number start
@internal_file_attributes, # file type (binary=0, text=1)
@external_file_attributes, # native filesystem attributes
(zip64 && zip64.relative_header_offset) ? 0xFFFFFFFF : @local_header_offset,
zip64 && zip64.relative_header_offset ? 0xFFFFFFFF : @local_header_offset,
@name,
@extra,
@comment
Expand All @@ -439,18 +439,18 @@ def write_c_dir_entry(io) #:nodoc:all
when ::Zip::FSTYPE_UNIX
ft = case @ftype
when :file
@unix_perms ||= 0644
@unix_perms ||= 0o644
::Zip::FILE_TYPE_FILE
when :directory
@unix_perms ||= 0755
@unix_perms ||= 0o755
::Zip::FILE_TYPE_DIR
when :symlink
@unix_perms ||= 0755
@unix_perms ||= 0o755
::Zip::FILE_TYPE_SYMLINK
end

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

Expand All @@ -464,7 +464,7 @@ def write_c_dir_entry(io) #:nodoc:all
def ==(other)
return false unless other.class == self.class
# 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)
end
keys_equal && time.dos_equals(other.time)
Expand Down
6 changes: 3 additions & 3 deletions lib/zip/entry_set.rb
Expand Up @@ -5,7 +5,7 @@ class EntrySet #:nodoc:all

def initialize(an_enumerable = [])
super()
@entry_set = {}
@entry_set = {}
an_enumerable.each { |o| push(o) }
end

Expand Down Expand Up @@ -33,9 +33,9 @@ def delete(entry)
entry if @entry_set.delete(to_key(entry))
end

def each(&block)
def each
@entry_set = sorted_entries.dup.each do |_, value|
block.call(value)
yield(value)
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/zip/extra_field.rb
Expand Up @@ -8,7 +8,7 @@ def initialize(binstr = nil)

def extra_field_type_exist(binstr, id, len, i)
field_name = ID_MAP[id].name
if self.member?(field_name)
if member?(field_name)
self[field_name].merge(binstr[i, len + 4])
else
field_obj = ID_MAP[id].new(binstr[i, len + 4])
Expand Down
2 changes: 1 addition & 1 deletion lib/zip/extra_field/generic.rb
@@ -1,7 +1,7 @@
module Zip
class ExtraField::Generic
def self.register_map
if self.const_defined?(:HEADER_ID)
if const_defined?(:HEADER_ID)
::Zip::ExtraField::ID_MAP[const_get(:HEADER_ID)] = self
end
end
Expand Down
3 changes: 1 addition & 2 deletions lib/zip/extra_field/zip64_placeholder.rb
Expand Up @@ -6,8 +6,7 @@ class ExtraField::Zip64Placeholder < ExtraField::Generic
HEADER_ID = ['9999'].pack('H*') # this ID is used by other libraries such as .NET's Ionic.zip
register_map

def initialize(_binstr = nil)
end
def initialize(_binstr = nil); end

def pack_for_local
"\x00" * 16
Expand Down
22 changes: 11 additions & 11 deletions lib/zip/file.rb
Expand Up @@ -69,16 +69,15 @@ def initialize(file_name, create = false, buffer = false, options = {})
@name = file_name
@comment = ''
@create = create ? true : false # allow any truthy value to mean true
case
when !buffer && ::File.size?(file_name)
if !buffer && ::File.size?(file_name)
@create = false
@file_permissions = ::File.stat(file_name).mode
::File.open(name, 'rb') do |f|
read_from_stream(f)
end
when @create
elsif @create
@entry_set = EntrySet.new
when ::File.zero?(file_name)
elsif ::File.zero?(file_name)
raise Error, "File #{file_name} has zero size. Did you mean to pass the create flag?"
else
raise Error, "File #{file_name} not found"
Expand Down Expand Up @@ -151,19 +150,20 @@ def foreach(aZipFileName, &block)
end

def get_segment_size_for_split(segment_size)
case
when MIN_SEGMENT_SIZE > segment_size
if MIN_SEGMENT_SIZE > segment_size
MIN_SEGMENT_SIZE
when MAX_SEGMENT_SIZE < segment_size
elsif MAX_SEGMENT_SIZE < segment_size
MAX_SEGMENT_SIZE
else
segment_size
end
end

def get_partial_zip_file_name(zip_file_name, partial_zip_file_name)
partial_zip_file_name = zip_file_name.sub(/#{::File.basename(zip_file_name)}\z/,
partial_zip_file_name + ::File.extname(zip_file_name)) unless partial_zip_file_name.nil?
unless partial_zip_file_name.nil?
partial_zip_file_name = zip_file_name.sub(/#{::File.basename(zip_file_name)}\z/,
partial_zip_file_name + ::File.extname(zip_file_name))
end
partial_zip_file_name ||= zip_file_name
partial_zip_file_name
end
Expand Down Expand Up @@ -237,7 +237,7 @@ def get_input_stream(entry, &aProc)
# specified. If a block is passed the stream object is passed to the block and
# the stream is automatically closed afterwards just as with ruby's builtin
# File.open method.
def get_output_stream(entry, permission_int = nil, comment = nil, extra = nil, compressed_size = nil, crc = nil, compression_method = nil, size = nil, time = nil, &aProc)
def get_output_stream(entry, permission_int = nil, comment = nil, extra = nil, compressed_size = nil, crc = nil, compression_method = nil, size = nil, time = nil, &aProc)
new_entry =
if entry.kind_of?(Entry)
entry
Expand Down Expand Up @@ -366,7 +366,7 @@ def get_entry(entry)
end

# Creates a directory
def mkdir(entryName, permissionInt = 0755)
def mkdir(entryName, permissionInt = 0o755)
raise Errno::EEXIST, "File exists - #{entryName}" if find_entry(entryName)
entryName = entryName.dup.to_s
entryName << '/' unless entryName.end_with?('/')
Expand Down