ZipFsDir was in the wrong module. ZipFileSystem now has a ctor that creates ZipFsDir and ZipFsFile instances, instead of creating them lazily. It then passes the dir instance to the file instance and vice versa
This commit is contained in:
parent
2f4123429c
commit
a47b107314
|
@ -5,16 +5,26 @@ require 'zip'
|
|||
module Zip
|
||||
module ZipFileSystem
|
||||
|
||||
def initialize
|
||||
@zipFsDir = ZipFsDir.new(self)
|
||||
@zipFsFile = ZipFsFile.new(self)
|
||||
@zipFsDir.file = @zipFsFile
|
||||
@zipFsFile.dir = @zipFsDir
|
||||
end
|
||||
|
||||
def dir
|
||||
@zipFsDir ||= ZipFsDir.new(self)
|
||||
@zipFsDir
|
||||
end
|
||||
|
||||
def file
|
||||
@zipFsFile ||= ZipFsFile.new(self)
|
||||
@zipFsFile
|
||||
end
|
||||
|
||||
class ZipFsFile
|
||||
|
||||
attr_writer :dir
|
||||
# protected :dir
|
||||
|
||||
class ZipFsStat
|
||||
def initialize(zipFsFile, entryName)
|
||||
@zipFsFile = zipFsFile
|
||||
|
@ -78,7 +88,7 @@ module Zip
|
|||
end
|
||||
|
||||
def exists?(fileName)
|
||||
expand_path(fileName) == "/" || @zipFile.find_entry(@zipFile.dir.expand_to_entry(fileName)) != nil
|
||||
expand_path(fileName) == "/" || @zipFile.find_entry(@dir.expand_to_entry(fileName)) != nil
|
||||
end
|
||||
alias :exist? :exists?
|
||||
|
||||
|
@ -113,12 +123,12 @@ module Zip
|
|||
end
|
||||
|
||||
def directory?(fileName)
|
||||
entry = @zipFile.find_entry(@zipFile.dir.expand_to_entry(fileName))
|
||||
entry = @zipFile.find_entry(@dir.expand_to_entry(fileName))
|
||||
expand_path(fileName) == "/" || (entry != nil && entry.directory?)
|
||||
end
|
||||
|
||||
def open(fileName, openMode = "r", &block)
|
||||
entryName = @zipFile.dir.expand_to_entry(fileName)
|
||||
entryName = @dir.expand_to_entry(fileName)
|
||||
case openMode
|
||||
when "r"
|
||||
@zipFile.get_input_stream(entryName, &block)
|
||||
|
@ -285,8 +295,7 @@ module Zip
|
|||
alias :unlink :delete
|
||||
|
||||
def expand_path(aPath)
|
||||
@zipFile.dir.expand_path(aPath)
|
||||
end
|
||||
@dir.expand_path(aPath)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -294,10 +303,12 @@ module Zip
|
|||
|
||||
def initialize(zipFile)
|
||||
@zipFile = zipFile
|
||||
@file = @zipFile.file
|
||||
@pwd = "/"
|
||||
end
|
||||
|
||||
attr_writer :file
|
||||
# protected :file
|
||||
|
||||
attr_reader :pwd
|
||||
alias getwd pwd
|
||||
|
||||
|
@ -322,7 +333,7 @@ module Zip
|
|||
end
|
||||
|
||||
def delete(entryName)
|
||||
unless @zipFile.file.stat(entryName).directory?
|
||||
unless @file.stat(entryName).directory?
|
||||
raise Errno::EINVAL, "Invalid argument - #{entryName}"
|
||||
end
|
||||
@zipFile.remove(entryName)
|
||||
|
@ -345,6 +356,7 @@ module Zip
|
|||
expand_path(aPath).lchop
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class ZipFile
|
||||
include ZipFileSystem
|
||||
|
|
Loading…
Reference in New Issue