Fix Naming/MethodParameterName cop in the library code.
This commit is contained in:
parent
b09f05d8d3
commit
aa6ea05d45
|
@ -38,13 +38,6 @@ Naming/AccessorMethodName:
|
|||
- 'lib/zip/streamable_stream.rb'
|
||||
- 'test/file_permissions_test.rb'
|
||||
|
||||
# Offense count: 140
|
||||
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
|
||||
# AllowedNames: io, id, to, by, on, in, at, ip, db, os
|
||||
Naming/MethodParameterName:
|
||||
Exclude:
|
||||
- 'lib/**/*.rb'
|
||||
|
||||
# Offense count: 721
|
||||
# Configuration parameters: EnforcedStyle.
|
||||
# SupportedStyles: snake_case, camelCase
|
||||
|
|
|
@ -181,8 +181,8 @@ module Zip
|
|||
end
|
||||
|
||||
# For iterating over the entries.
|
||||
def each(&proc)
|
||||
@entry_set.each(&proc)
|
||||
def each(&a_proc)
|
||||
@entry_set.each(&a_proc)
|
||||
end
|
||||
|
||||
# Returns the number of entries in the central directory (and
|
||||
|
|
|
@ -24,8 +24,8 @@ module Zip
|
|||
end
|
||||
end
|
||||
|
||||
def update_keys(n)
|
||||
@key0 = ~Zlib.crc32(n, ~@key0)
|
||||
def update_keys(num)
|
||||
@key0 = ~Zlib.crc32(num, ~@key0)
|
||||
@key1 = ((@key1 + (@key0 & 0xff)) * 134_775_813 + 1) & 0xffffffff
|
||||
@key2 = ~Zlib.crc32((@key1 >> 24).chr, ~@key2)
|
||||
end
|
||||
|
@ -63,10 +63,10 @@ module Zip
|
|||
|
||||
private
|
||||
|
||||
def encode(n)
|
||||
def encode(num)
|
||||
t = decrypt_byte
|
||||
update_keys(n.chr)
|
||||
t ^ n
|
||||
update_keys(num.chr)
|
||||
t ^ num
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -86,10 +86,10 @@ module Zip
|
|||
|
||||
private
|
||||
|
||||
def decode(n)
|
||||
n ^= decrypt_byte
|
||||
update_keys(n.chr)
|
||||
n
|
||||
def decode(num)
|
||||
num ^= decrypt_byte
|
||||
update_keys(num.chr)
|
||||
num
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -34,13 +34,13 @@ module Zip
|
|||
local(time.year, time.month, time.day, time.hour, time.min, time.sec)
|
||||
end
|
||||
|
||||
def self.parse_binary_dos_format(binaryDosDate, binaryDosTime)
|
||||
second = 2 * (0b11111 & binaryDosTime)
|
||||
minute = (0b11111100000 & binaryDosTime) >> 5
|
||||
hour = (0b1111100000000000 & binaryDosTime) >> 11
|
||||
day = (0b11111 & binaryDosDate)
|
||||
month = (0b111100000 & binaryDosDate) >> 5
|
||||
year = ((0b1111111000000000 & binaryDosDate) >> 9) + 1980
|
||||
def self.parse_binary_dos_format(bin_dos_date, bin_dos_time)
|
||||
second = 2 * (0b11111 & bin_dos_time)
|
||||
minute = (0b11111100000 & bin_dos_time) >> 5
|
||||
hour = (0b1111100000000000 & bin_dos_time) >> 11
|
||||
day = (0b11111 & bin_dos_date)
|
||||
month = (0b111100000 & bin_dos_date) >> 5
|
||||
year = ((0b1111111000000000 & bin_dos_date) >> 9) + 1980
|
||||
begin
|
||||
local(year, month, day, hour, minute, second)
|
||||
end
|
||||
|
|
|
@ -6,23 +6,23 @@ module Zip
|
|||
merge(binstr) if binstr
|
||||
end
|
||||
|
||||
def extra_field_type_exist(binstr, id, len, i)
|
||||
def extra_field_type_exist(binstr, id, len, index)
|
||||
field_name = ID_MAP[id].name
|
||||
if member?(field_name)
|
||||
self[field_name].merge(binstr[i, len + 4])
|
||||
self[field_name].merge(binstr[index, len + 4])
|
||||
else
|
||||
field_obj = ID_MAP[id].new(binstr[i, len + 4])
|
||||
field_obj = ID_MAP[id].new(binstr[index, len + 4])
|
||||
self[field_name] = field_obj
|
||||
end
|
||||
end
|
||||
|
||||
def extra_field_type_unknown(binstr, len, i)
|
||||
def extra_field_type_unknown(binstr, len, index)
|
||||
create_unknown_item unless self['Unknown']
|
||||
if !len || len + 4 > binstr[i..-1].bytesize
|
||||
self['Unknown'] << binstr[i..-1]
|
||||
if !len || len + 4 > binstr[index..-1].bytesize
|
||||
self['Unknown'] << binstr[index..-1]
|
||||
return
|
||||
end
|
||||
self['Unknown'] << binstr[i, len + 4]
|
||||
self['Unknown'] << binstr[index, len + 4]
|
||||
end
|
||||
|
||||
def create_unknown_item
|
||||
|
|
|
@ -168,8 +168,8 @@ module Zip
|
|||
# whereas ZipInputStream jumps through the entire archive accessing the
|
||||
# local entry headers (which contain the same information as the
|
||||
# central directory).
|
||||
def foreach(aZipFileName, &block)
|
||||
::Zip::File.open(aZipFileName) do |zip_file|
|
||||
def foreach(zip_file_name, &block)
|
||||
::Zip::File.open(zip_file_name) do |zip_file|
|
||||
zip_file.each(&block)
|
||||
end
|
||||
end
|
||||
|
@ -255,8 +255,8 @@ module Zip
|
|||
# Returns an input stream to the specified entry. 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_input_stream(entry, &aProc)
|
||||
get_entry(entry).get_input_stream(&aProc)
|
||||
def get_input_stream(entry, &a_proc)
|
||||
get_entry(entry).get_input_stream(&a_proc)
|
||||
end
|
||||
|
||||
# Returns an output stream to the specified entry. If entry is not an instance
|
||||
|
@ -267,7 +267,7 @@ module Zip
|
|||
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)
|
||||
&a_proc)
|
||||
|
||||
new_entry =
|
||||
if entry.kind_of?(Entry)
|
||||
|
@ -282,7 +282,7 @@ module Zip
|
|||
new_entry.unix_perms = permission_int
|
||||
zip_streamable_entry = StreamableStream.new(new_entry)
|
||||
@entry_set << zip_streamable_entry
|
||||
zip_streamable_entry.get_output_stream(&aProc)
|
||||
zip_streamable_entry.get_output_stream(&a_proc)
|
||||
end
|
||||
|
||||
# Returns the name of the zip archive
|
||||
|
@ -326,12 +326,12 @@ module Zip
|
|||
@entry_set << foundEntry
|
||||
end
|
||||
|
||||
# Replaces the specified entry with the contents of srcPath (from
|
||||
# Replaces the specified entry with the contents of src_path (from
|
||||
# the file system).
|
||||
def replace(entry, srcPath)
|
||||
check_file(srcPath)
|
||||
def replace(entry, src_path)
|
||||
check_file(src_path)
|
||||
remove(entry)
|
||||
add(entry, srcPath)
|
||||
add(entry, src_path)
|
||||
end
|
||||
|
||||
# Extracts entry to file dest_path.
|
||||
|
@ -409,37 +409,37 @@ module Zip
|
|||
end
|
||||
|
||||
# Creates a directory
|
||||
def mkdir(entryName, permissionInt = 0o755)
|
||||
raise Errno::EEXIST, "File exists - #{entryName}" if find_entry(entryName)
|
||||
def mkdir(entry_name, permission = 0o755)
|
||||
raise Errno::EEXIST, "File exists - #{entry_name}" if find_entry(entry_name)
|
||||
|
||||
entryName = entryName.dup.to_s
|
||||
entryName << '/' unless entryName.end_with?('/')
|
||||
@entry_set << ::Zip::StreamableDirectory.new(@name, entryName, nil, permissionInt)
|
||||
entry_name = entry_name.dup.to_s
|
||||
entry_name << '/' unless entry_name.end_with?('/')
|
||||
@entry_set << ::Zip::StreamableDirectory.new(@name, entry_name, nil, permission)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def directory?(newEntry, srcPath)
|
||||
srcPathIsDirectory = ::File.directory?(srcPath)
|
||||
if newEntry.directory? && !srcPathIsDirectory
|
||||
def directory?(new_entry, src_path)
|
||||
srcPathIsDirectory = ::File.directory?(src_path)
|
||||
if new_entry.directory? && !srcPathIsDirectory
|
||||
raise ArgumentError,
|
||||
"entry name '#{newEntry}' indicates directory entry, but " \
|
||||
"'#{srcPath}' is not a directory"
|
||||
elsif !newEntry.directory? && srcPathIsDirectory
|
||||
newEntry.name += '/'
|
||||
"entry name '#{new_entry}' indicates directory entry, but " \
|
||||
"'#{src_path}' is not a directory"
|
||||
elsif !new_entry.directory? && srcPathIsDirectory
|
||||
new_entry.name += '/'
|
||||
end
|
||||
newEntry.directory? && srcPathIsDirectory
|
||||
new_entry.directory? && srcPathIsDirectory
|
||||
end
|
||||
|
||||
def check_entry_exists(entryName, continue_on_exists_proc, procedureName)
|
||||
def check_entry_exists(entry_name, continue_on_exists_proc, proc_name)
|
||||
continue_on_exists_proc ||= proc { Zip.continue_on_exists_proc }
|
||||
return unless @entry_set.include?(entryName)
|
||||
return unless @entry_set.include?(entry_name)
|
||||
|
||||
if continue_on_exists_proc.call
|
||||
remove get_entry(entryName)
|
||||
remove get_entry(entry_name)
|
||||
else
|
||||
raise ::Zip::EntryExistsError,
|
||||
procedureName + " failed. Entry #{entryName} already exists"
|
||||
proc_name + " failed. Entry #{entry_name} already exists"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -35,25 +35,25 @@ module Zip
|
|||
|
||||
module FileSystem
|
||||
def initialize # :nodoc:
|
||||
mappedZip = ZipFileNameMapper.new(self)
|
||||
@zipFsDir = ZipFsDir.new(mappedZip)
|
||||
@zipFsFile = ZipFsFile.new(mappedZip)
|
||||
@zipFsDir.file = @zipFsFile
|
||||
@zipFsFile.dir = @zipFsDir
|
||||
mapped_zip = ZipFileNameMapper.new(self)
|
||||
@zip_fs_dir = ZipFsDir.new(mapped_zip)
|
||||
@zip_fs_file = ZipFsFile.new(mapped_zip)
|
||||
@zip_fs_dir.file = @zip_fs_file
|
||||
@zip_fs_file.dir = @zip_fs_dir
|
||||
end
|
||||
|
||||
# Returns a ZipFsDir which is much like ruby's builtin Dir (class)
|
||||
# object, except it works on the Zip::File on which this method is
|
||||
# invoked
|
||||
def dir
|
||||
@zipFsDir
|
||||
@zip_fs_dir
|
||||
end
|
||||
|
||||
# Returns a ZipFsFile which is much like ruby's builtin File (class)
|
||||
# object, except it works on the Zip::File on which this method is
|
||||
# invoked
|
||||
def file
|
||||
@zipFsFile
|
||||
@zip_fs_file
|
||||
end
|
||||
|
||||
# Instances of this class are normally accessed via the accessor
|
||||
|
@ -72,20 +72,20 @@ module Zip
|
|||
methods.each do |method|
|
||||
class_eval <<-END_EVAL, __FILE__, __LINE__ + 1
|
||||
def #{method} # def file?
|
||||
@zipFsFile.#{method}(@entryName) # @zipFsFile.file?(@entryName)
|
||||
@zip_fs_file.#{method}(@entry_name) # @zip_fs_file.file?(@entry_name)
|
||||
end # end
|
||||
END_EVAL
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def initialize(zipFsFile, entryName)
|
||||
@zipFsFile = zipFsFile
|
||||
@entryName = entryName
|
||||
def initialize(zip_fs_file, entry_name)
|
||||
@zip_fs_file = zip_fs_file
|
||||
@entry_name = entry_name
|
||||
end
|
||||
|
||||
def kind_of?(t)
|
||||
super || t == ::File::Stat
|
||||
def kind_of?(type)
|
||||
super || type == ::File::Stat
|
||||
end
|
||||
|
||||
delegate_to_fs_file :file?, :directory?, :pipe?, :chardev?, :symlink?,
|
||||
|
@ -98,7 +98,7 @@ module Zip
|
|||
end
|
||||
|
||||
def get_entry
|
||||
@zipFsFile.__send__(:get_entry, @entryName)
|
||||
@zip_fs_file.__send__(:get_entry, @entry_name)
|
||||
end
|
||||
private :get_entry
|
||||
|
||||
|
@ -168,29 +168,29 @@ module Zip
|
|||
end
|
||||
end
|
||||
|
||||
def initialize(mappedZip)
|
||||
@mappedZip = mappedZip
|
||||
def initialize(mapped_zip)
|
||||
@mapped_zip = mapped_zip
|
||||
end
|
||||
|
||||
def get_entry(fileName)
|
||||
unless exists?(fileName)
|
||||
raise Errno::ENOENT, "No such file or directory - #{fileName}"
|
||||
def get_entry(filename)
|
||||
unless exists?(filename)
|
||||
raise Errno::ENOENT, "No such file or directory - #{filename}"
|
||||
end
|
||||
|
||||
@mappedZip.find_entry(fileName)
|
||||
@mapped_zip.find_entry(filename)
|
||||
end
|
||||
private :get_entry
|
||||
|
||||
def unix_mode_cmp(fileName, mode)
|
||||
e = get_entry(fileName)
|
||||
def unix_mode_cmp(filename, mode)
|
||||
e = get_entry(filename)
|
||||
e.fstype == 3 && ((e.external_file_attributes >> 16) & mode) != 0
|
||||
rescue Errno::ENOENT
|
||||
false
|
||||
end
|
||||
private :unix_mode_cmp
|
||||
|
||||
def exists?(fileName)
|
||||
expand_path(fileName) == '/' || !@mappedZip.find_entry(fileName).nil?
|
||||
def exists?(filename)
|
||||
expand_path(filename) == '/' || !@mapped_zip.find_entry(filename).nil?
|
||||
end
|
||||
alias exist? exists?
|
||||
|
||||
|
@ -198,133 +198,133 @@ module Zip
|
|||
alias owned? exists?
|
||||
alias grpowned? exists?
|
||||
|
||||
def readable?(fileName)
|
||||
unix_mode_cmp(fileName, 0o444)
|
||||
def readable?(filename)
|
||||
unix_mode_cmp(filename, 0o444)
|
||||
end
|
||||
alias readable_real? readable?
|
||||
|
||||
def writable?(fileName)
|
||||
unix_mode_cmp(fileName, 0o222)
|
||||
def writable?(filename)
|
||||
unix_mode_cmp(filename, 0o222)
|
||||
end
|
||||
alias writable_real? writable?
|
||||
|
||||
def executable?(fileName)
|
||||
unix_mode_cmp(fileName, 0o111)
|
||||
def executable?(filename)
|
||||
unix_mode_cmp(filename, 0o111)
|
||||
end
|
||||
alias executable_real? executable?
|
||||
|
||||
def setuid?(fileName)
|
||||
unix_mode_cmp(fileName, 0o4000)
|
||||
def setuid?(filename)
|
||||
unix_mode_cmp(filename, 0o4000)
|
||||
end
|
||||
|
||||
def setgid?(fileName)
|
||||
unix_mode_cmp(fileName, 0o2000)
|
||||
def setgid?(filename)
|
||||
unix_mode_cmp(filename, 0o2000)
|
||||
end
|
||||
|
||||
def sticky?(fileName)
|
||||
unix_mode_cmp(fileName, 0o1000)
|
||||
def sticky?(filename)
|
||||
unix_mode_cmp(filename, 0o1000)
|
||||
end
|
||||
|
||||
def umask(*args)
|
||||
::File.umask(*args)
|
||||
end
|
||||
|
||||
def truncate(_fileName, _len)
|
||||
def truncate(_filename, _len)
|
||||
raise StandardError, 'truncate not supported'
|
||||
end
|
||||
|
||||
def directory?(fileName)
|
||||
entry = @mappedZip.find_entry(fileName)
|
||||
expand_path(fileName) == '/' || (!entry.nil? && entry.directory?)
|
||||
def directory?(filename)
|
||||
entry = @mapped_zip.find_entry(filename)
|
||||
expand_path(filename) == '/' || (!entry.nil? && entry.directory?)
|
||||
end
|
||||
|
||||
def open(fileName, openMode = 'r', permissionInt = 0o644, &block)
|
||||
openMode.delete!('b') # ignore b option
|
||||
case openMode
|
||||
def open(filename, mode = 'r', permissions = 0o644, &block)
|
||||
mode.delete!('b') # ignore b option
|
||||
case mode
|
||||
when 'r'
|
||||
@mappedZip.get_input_stream(fileName, &block)
|
||||
@mapped_zip.get_input_stream(filename, &block)
|
||||
when 'w'
|
||||
@mappedZip.get_output_stream(fileName, permissionInt, &block)
|
||||
@mapped_zip.get_output_stream(filename, permissions, &block)
|
||||
else
|
||||
raise StandardError, "openmode '#{openMode} not supported" unless openMode == 'r'
|
||||
raise StandardError, "openmode '#{mode} not supported" unless mode == 'r'
|
||||
end
|
||||
end
|
||||
|
||||
def new(fileName, openMode = 'r')
|
||||
self.open(fileName, openMode)
|
||||
def new(filename, mode = 'r')
|
||||
self.open(filename, mode)
|
||||
end
|
||||
|
||||
def size(fileName)
|
||||
@mappedZip.get_entry(fileName).size
|
||||
def size(filename)
|
||||
@mapped_zip.get_entry(filename).size
|
||||
end
|
||||
|
||||
# Returns nil for not found and nil for directories
|
||||
def size?(fileName)
|
||||
entry = @mappedZip.find_entry(fileName)
|
||||
def size?(filename)
|
||||
entry = @mapped_zip.find_entry(filename)
|
||||
entry.nil? || entry.directory? ? nil : entry.size
|
||||
end
|
||||
|
||||
def chown(ownerInt, groupInt, *filenames)
|
||||
def chown(owner, group, *filenames)
|
||||
filenames.each do |filename|
|
||||
e = get_entry(filename)
|
||||
e.extra.create('IUnix') unless e.extra.member?('IUnix')
|
||||
e.extra['IUnix'].uid = ownerInt
|
||||
e.extra['IUnix'].gid = groupInt
|
||||
e.extra['IUnix'].uid = owner
|
||||
e.extra['IUnix'].gid = group
|
||||
end
|
||||
filenames.size
|
||||
end
|
||||
|
||||
def chmod(modeInt, *filenames)
|
||||
def chmod(mode, *filenames)
|
||||
filenames.each do |filename|
|
||||
e = get_entry(filename)
|
||||
e.fstype = 3 # force convertion filesystem type to unix
|
||||
e.unix_perms = modeInt
|
||||
e.external_file_attributes = modeInt << 16
|
||||
e.unix_perms = mode
|
||||
e.external_file_attributes = mode << 16
|
||||
e.dirty = true
|
||||
end
|
||||
filenames.size
|
||||
end
|
||||
|
||||
def zero?(fileName)
|
||||
sz = size(fileName)
|
||||
def zero?(filename)
|
||||
sz = size(filename)
|
||||
sz.nil? || sz == 0
|
||||
rescue Errno::ENOENT
|
||||
false
|
||||
end
|
||||
|
||||
def file?(fileName)
|
||||
entry = @mappedZip.find_entry(fileName)
|
||||
def file?(filename)
|
||||
entry = @mapped_zip.find_entry(filename)
|
||||
!entry.nil? && entry.file?
|
||||
end
|
||||
|
||||
def dirname(fileName)
|
||||
::File.dirname(fileName)
|
||||
def dirname(filename)
|
||||
::File.dirname(filename)
|
||||
end
|
||||
|
||||
def basename(fileName)
|
||||
::File.basename(fileName)
|
||||
def basename(filename)
|
||||
::File.basename(filename)
|
||||
end
|
||||
|
||||
def split(fileName)
|
||||
::File.split(fileName)
|
||||
def split(filename)
|
||||
::File.split(filename)
|
||||
end
|
||||
|
||||
def join(*fragments)
|
||||
::File.join(*fragments)
|
||||
end
|
||||
|
||||
def utime(modifiedTime, *fileNames)
|
||||
fileNames.each do |filename|
|
||||
get_entry(filename).time = modifiedTime
|
||||
def utime(modified_time, *filenames)
|
||||
filenames.each do |filename|
|
||||
get_entry(filename).time = modified_time
|
||||
end
|
||||
end
|
||||
|
||||
def mtime(fileName)
|
||||
@mappedZip.get_entry(fileName).mtime
|
||||
def mtime(filename)
|
||||
@mapped_zip.get_entry(filename).mtime
|
||||
end
|
||||
|
||||
def atime(fileName)
|
||||
e = get_entry(fileName)
|
||||
def atime(filename)
|
||||
e = get_entry(filename)
|
||||
if e.extra.member? 'UniversalTime'
|
||||
e.extra['UniversalTime'].atime
|
||||
elsif e.extra.member? 'NTFS'
|
||||
|
@ -332,8 +332,8 @@ module Zip
|
|||
end
|
||||
end
|
||||
|
||||
def ctime(fileName)
|
||||
e = get_entry(fileName)
|
||||
def ctime(filename)
|
||||
e = get_entry(filename)
|
||||
if e.extra.member? 'UniversalTime'
|
||||
e.extra['UniversalTime'].ctime
|
||||
elsif e.extra.member? 'NTFS'
|
||||
|
@ -353,27 +353,27 @@ module Zip
|
|||
false
|
||||
end
|
||||
|
||||
def symlink?(_fileName)
|
||||
def symlink?(_filename)
|
||||
false
|
||||
end
|
||||
|
||||
def socket?(_fileName)
|
||||
def socket?(_filename)
|
||||
false
|
||||
end
|
||||
|
||||
def ftype(fileName)
|
||||
@mappedZip.get_entry(fileName).directory? ? 'directory' : 'file'
|
||||
def ftype(filename)
|
||||
@mapped_zip.get_entry(filename).directory? ? 'directory' : 'file'
|
||||
end
|
||||
|
||||
def readlink(_fileName)
|
||||
def readlink(_filename)
|
||||
raise NotImplementedError, 'The readlink() function is not implemented'
|
||||
end
|
||||
|
||||
def symlink(_fileName, _symlinkName)
|
||||
def symlink(_filename, _symlink_name)
|
||||
raise NotImplementedError, 'The symlink() function is not implemented'
|
||||
end
|
||||
|
||||
def link(_fileName, _symlinkName)
|
||||
def link(_filename, _symlink_name)
|
||||
raise NotImplementedError, 'The link() function is not implemented'
|
||||
end
|
||||
|
||||
|
@ -381,28 +381,28 @@ module Zip
|
|||
raise NotImplementedError, 'The pipe() function is not implemented'
|
||||
end
|
||||
|
||||
def stat(fileName)
|
||||
raise Errno::ENOENT, fileName unless exists?(fileName)
|
||||
def stat(filename)
|
||||
raise Errno::ENOENT, filename unless exists?(filename)
|
||||
|
||||
ZipFsStat.new(self, fileName)
|
||||
ZipFsStat.new(self, filename)
|
||||
end
|
||||
|
||||
alias lstat stat
|
||||
|
||||
def readlines(fileName)
|
||||
self.open(fileName, &:readlines)
|
||||
def readlines(filename)
|
||||
self.open(filename, &:readlines)
|
||||
end
|
||||
|
||||
def read(fileName)
|
||||
@mappedZip.read(fileName)
|
||||
def read(filename)
|
||||
@mapped_zip.read(filename)
|
||||
end
|
||||
|
||||
def popen(*args, &aProc)
|
||||
::File.popen(*args, &aProc)
|
||||
def popen(*args, &a_proc)
|
||||
::File.popen(*args, &a_proc)
|
||||
end
|
||||
|
||||
def foreach(fileName, aSep = $INPUT_RECORD_SEPARATOR, &aProc)
|
||||
self.open(fileName) { |is| is.each_line(aSep, &aProc) }
|
||||
def foreach(filename, sep = $INPUT_RECORD_SEPARATOR, &a_proc)
|
||||
self.open(filename) { |is| is.each_line(sep, &a_proc) }
|
||||
end
|
||||
|
||||
def delete(*args)
|
||||
|
@ -411,18 +411,18 @@ module Zip
|
|||
raise Errno::EISDIR, "Is a directory - \"#{filename}\""
|
||||
end
|
||||
|
||||
@mappedZip.remove(filename)
|
||||
@mapped_zip.remove(filename)
|
||||
end
|
||||
end
|
||||
|
||||
def rename(fileToRename, newName)
|
||||
@mappedZip.rename(fileToRename, newName) { true }
|
||||
def rename(file_to_rename, new_name)
|
||||
@mapped_zip.rename(file_to_rename, new_name) { true }
|
||||
end
|
||||
|
||||
alias unlink delete
|
||||
|
||||
def expand_path(aPath)
|
||||
@mappedZip.expand_path(aPath)
|
||||
def expand_path(path)
|
||||
@mapped_zip.expand_path(path)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -433,18 +433,18 @@ module Zip
|
|||
# The individual methods are not documented due to their
|
||||
# similarity with the methods in Dir
|
||||
class ZipFsDir
|
||||
def initialize(mappedZip)
|
||||
@mappedZip = mappedZip
|
||||
def initialize(mapped_zip)
|
||||
@mapped_zip = mapped_zip
|
||||
end
|
||||
|
||||
attr_writer :file
|
||||
|
||||
def new(aDirectoryName)
|
||||
ZipFsDirIterator.new(entries(aDirectoryName))
|
||||
def new(directory_name)
|
||||
ZipFsDirIterator.new(entries(directory_name))
|
||||
end
|
||||
|
||||
def open(aDirectoryName)
|
||||
dirIt = new(aDirectoryName)
|
||||
def open(directory_name)
|
||||
dirIt = new(directory_name)
|
||||
if block_given?
|
||||
begin
|
||||
yield(dirIt)
|
||||
|
@ -457,55 +457,55 @@ module Zip
|
|||
end
|
||||
|
||||
def pwd
|
||||
@mappedZip.pwd
|
||||
@mapped_zip.pwd
|
||||
end
|
||||
alias getwd pwd
|
||||
|
||||
def chdir(aDirectoryName)
|
||||
unless @file.stat(aDirectoryName).directory?
|
||||
raise Errno::EINVAL, "Invalid argument - #{aDirectoryName}"
|
||||
def chdir(directory_name)
|
||||
unless @file.stat(directory_name).directory?
|
||||
raise Errno::EINVAL, "Invalid argument - #{directory_name}"
|
||||
end
|
||||
|
||||
@mappedZip.pwd = @file.expand_path(aDirectoryName)
|
||||
@mapped_zip.pwd = @file.expand_path(directory_name)
|
||||
end
|
||||
|
||||
def entries(aDirectoryName)
|
||||
def entries(directory_name)
|
||||
entries = []
|
||||
foreach(aDirectoryName) { |e| entries << e }
|
||||
foreach(directory_name) { |e| entries << e }
|
||||
entries
|
||||
end
|
||||
|
||||
def glob(*args, &block)
|
||||
@mappedZip.glob(*args, &block)
|
||||
@mapped_zip.glob(*args, &block)
|
||||
end
|
||||
|
||||
def foreach(aDirectoryName)
|
||||
unless @file.stat(aDirectoryName).directory?
|
||||
raise Errno::ENOTDIR, aDirectoryName
|
||||
def foreach(directory_name)
|
||||
unless @file.stat(directory_name).directory?
|
||||
raise Errno::ENOTDIR, directory_name
|
||||
end
|
||||
|
||||
path = @file.expand_path(aDirectoryName)
|
||||
path = @file.expand_path(directory_name)
|
||||
path << '/' unless path.end_with?('/')
|
||||
path = Regexp.escape(path)
|
||||
subDirEntriesRegex = Regexp.new("^#{path}([^/]+)$")
|
||||
@mappedZip.each do |filename|
|
||||
@mapped_zip.each do |filename|
|
||||
match = subDirEntriesRegex.match(filename)
|
||||
yield(match[1]) unless match.nil?
|
||||
end
|
||||
end
|
||||
|
||||
def delete(entryName)
|
||||
unless @file.stat(entryName).directory?
|
||||
raise Errno::EINVAL, "Invalid argument - #{entryName}"
|
||||
def delete(entry_name)
|
||||
unless @file.stat(entry_name).directory?
|
||||
raise Errno::EINVAL, "Invalid argument - #{entry_name}"
|
||||
end
|
||||
|
||||
@mappedZip.remove(entryName)
|
||||
@mapped_zip.remove(entry_name)
|
||||
end
|
||||
alias rmdir delete
|
||||
alias unlink delete
|
||||
|
||||
def mkdir(entryName, permissionInt = 0o755)
|
||||
@mappedZip.mkdir(entryName, permissionInt)
|
||||
def mkdir(entry_name, permissions = 0o755)
|
||||
@mapped_zip.mkdir(entry_name, permissions)
|
||||
end
|
||||
|
||||
def chroot(*_args)
|
||||
|
@ -516,41 +516,41 @@ module Zip
|
|||
class ZipFsDirIterator # :nodoc:all
|
||||
include Enumerable
|
||||
|
||||
def initialize(arrayOfFileNames)
|
||||
@fileNames = arrayOfFileNames
|
||||
def initialize(filenames)
|
||||
@filenames = filenames
|
||||
@index = 0
|
||||
end
|
||||
|
||||
def close
|
||||
@fileNames = nil
|
||||
@filenames = nil
|
||||
end
|
||||
|
||||
def each(&aProc)
|
||||
raise IOError, 'closed directory' if @fileNames.nil?
|
||||
def each(&a_proc)
|
||||
raise IOError, 'closed directory' if @filenames.nil?
|
||||
|
||||
@fileNames.each(&aProc)
|
||||
@filenames.each(&a_proc)
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
def rewind
|
||||
raise IOError, 'closed directory' if @fileNames.nil?
|
||||
raise IOError, 'closed directory' if @filenames.nil?
|
||||
|
||||
@index = 0
|
||||
end
|
||||
|
||||
def seek(anIntegerPosition)
|
||||
raise IOError, 'closed directory' if @fileNames.nil?
|
||||
def seek(position)
|
||||
raise IOError, 'closed directory' if @filenames.nil?
|
||||
|
||||
@index = anIntegerPosition
|
||||
@index = position
|
||||
end
|
||||
|
||||
def tell
|
||||
raise IOError, 'closed directory' if @fileNames.nil?
|
||||
raise IOError, 'closed directory' if @filenames.nil?
|
||||
|
||||
@index
|
||||
end
|
||||
|
@ -561,60 +561,65 @@ module Zip
|
|||
class ZipFileNameMapper # :nodoc:all
|
||||
include Enumerable
|
||||
|
||||
def initialize(zipFile)
|
||||
@zipFile = zipFile
|
||||
def initialize(zip_file)
|
||||
@zip_file = zip_file
|
||||
@pwd = '/'
|
||||
end
|
||||
|
||||
attr_accessor :pwd
|
||||
|
||||
def find_entry(fileName)
|
||||
@zipFile.find_entry(expand_to_entry(fileName))
|
||||
def find_entry(filename)
|
||||
@zip_file.find_entry(expand_to_entry(filename))
|
||||
end
|
||||
|
||||
def get_entry(fileName)
|
||||
@zipFile.get_entry(expand_to_entry(fileName))
|
||||
def get_entry(filename)
|
||||
@zip_file.get_entry(expand_to_entry(filename))
|
||||
end
|
||||
|
||||
def get_input_stream(fileName, &aProc)
|
||||
@zipFile.get_input_stream(expand_to_entry(fileName), &aProc)
|
||||
def get_input_stream(filename, &a_proc)
|
||||
@zip_file.get_input_stream(expand_to_entry(filename), &a_proc)
|
||||
end
|
||||
|
||||
def get_output_stream(fileName, permissionInt = nil, &aProc)
|
||||
@zipFile.get_output_stream(expand_to_entry(fileName), permissionInt, &aProc)
|
||||
def get_output_stream(filename, permissions = nil, &a_proc)
|
||||
@zip_file.get_output_stream(
|
||||
expand_to_entry(filename), permissions, &a_proc
|
||||
)
|
||||
end
|
||||
|
||||
def glob(pattern, *flags, &block)
|
||||
@zipFile.glob(expand_to_entry(pattern), *flags, &block)
|
||||
@zip_file.glob(expand_to_entry(pattern), *flags, &block)
|
||||
end
|
||||
|
||||
def read(fileName)
|
||||
@zipFile.read(expand_to_entry(fileName))
|
||||
def read(filename)
|
||||
@zip_file.read(expand_to_entry(filename))
|
||||
end
|
||||
|
||||
def remove(fileName)
|
||||
@zipFile.remove(expand_to_entry(fileName))
|
||||
def remove(filename)
|
||||
@zip_file.remove(expand_to_entry(filename))
|
||||
end
|
||||
|
||||
def rename(fileName, newName, &continueOnExistsProc)
|
||||
@zipFile.rename(expand_to_entry(fileName), expand_to_entry(newName),
|
||||
&continueOnExistsProc)
|
||||
def rename(filename, new_name, &continue_on_exists_proc)
|
||||
@zip_file.rename(
|
||||
expand_to_entry(filename),
|
||||
expand_to_entry(new_name),
|
||||
&continue_on_exists_proc
|
||||
)
|
||||
end
|
||||
|
||||
def mkdir(fileName, permissionInt = 0o755)
|
||||
@zipFile.mkdir(expand_to_entry(fileName), permissionInt)
|
||||
def mkdir(filename, permissions = 0o755)
|
||||
@zip_file.mkdir(expand_to_entry(filename), permissions)
|
||||
end
|
||||
|
||||
# Turns entries into strings and adds leading /
|
||||
# and removes trailing slash on directories
|
||||
def each
|
||||
@zipFile.each do |e|
|
||||
@zip_file.each do |e|
|
||||
yield('/' + e.to_s.chomp('/'))
|
||||
end
|
||||
end
|
||||
|
||||
def expand_path(aPath)
|
||||
expanded = aPath.start_with?('/') ? aPath : ::File.join(@pwd, aPath)
|
||||
def expand_path(path)
|
||||
expanded = path.start_with?('/') ? path : ::File.join(@pwd, path)
|
||||
expanded.gsub!(/\/\.(\/|$)/, '')
|
||||
expanded.gsub!(/[^\/]+\/\.\.(\/|$)/, '')
|
||||
expanded.empty? ? '/' : expanded
|
||||
|
@ -622,8 +627,8 @@ module Zip
|
|||
|
||||
private
|
||||
|
||||
def expand_to_entry(aPath)
|
||||
expand_path(aPath)[1..-1]
|
||||
def expand_to_entry(path)
|
||||
expand_path(path)[1..-1]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
module Zip
|
||||
class PassThruCompressor < Compressor #:nodoc:all
|
||||
def initialize(outputStream)
|
||||
def initialize(output_stream)
|
||||
super()
|
||||
@output_stream = outputStream
|
||||
@output_stream = output_stream
|
||||
@crc = Zlib.crc32
|
||||
@size = 0
|
||||
end
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
module Zip
|
||||
class StreamableDirectory < Entry
|
||||
def initialize(zipfile, entry, srcPath = nil, permissionInt = nil)
|
||||
def initialize(zipfile, entry, src_path = nil, permission = nil)
|
||||
super(zipfile, entry)
|
||||
|
||||
@ftype = :directory
|
||||
entry.get_extra_attributes_from_path(srcPath) if srcPath
|
||||
@unix_perms = permissionInt if permissionInt
|
||||
entry.get_extra_attributes_from_path(src_path) if src_path
|
||||
@unix_perms = permission if permission
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -36,9 +36,9 @@ module Zip
|
|||
end
|
||||
end
|
||||
|
||||
def write_to_zip_output_stream(aZipOutputStream)
|
||||
aZipOutputStream.put_next_entry(self)
|
||||
get_input_stream { |is| ::Zip::IOExtras.copy_stream(aZipOutputStream, is) }
|
||||
def write_to_zip_output_stream(output_stream)
|
||||
output_stream.put_next_entry(self)
|
||||
get_input_stream { |is| ::Zip::IOExtras.copy_stream(output_stream, is) }
|
||||
end
|
||||
|
||||
def clean_up
|
||||
|
|
Loading…
Reference in New Issue