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:
thomas 2003-08-20 14:10:20 +00:00
parent 2f4123429c
commit a47b107314
1 changed files with 70 additions and 58 deletions

View File

@ -5,16 +5,26 @@ require 'zip'
module Zip module Zip
module ZipFileSystem module ZipFileSystem
def initialize
@zipFsDir = ZipFsDir.new(self)
@zipFsFile = ZipFsFile.new(self)
@zipFsDir.file = @zipFsFile
@zipFsFile.dir = @zipFsDir
end
def dir def dir
@zipFsDir ||= ZipFsDir.new(self) @zipFsDir
end end
def file def file
@zipFsFile ||= ZipFsFile.new(self) @zipFsFile
end end
class ZipFsFile class ZipFsFile
attr_writer :dir
# protected :dir
class ZipFsStat class ZipFsStat
def initialize(zipFsFile, entryName) def initialize(zipFsFile, entryName)
@zipFsFile = zipFsFile @zipFsFile = zipFsFile
@ -78,7 +88,7 @@ module Zip
end end
def exists?(fileName) 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 end
alias :exist? :exists? alias :exist? :exists?
@ -113,12 +123,12 @@ module Zip
end end
def directory?(fileName) 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?) expand_path(fileName) == "/" || (entry != nil && entry.directory?)
end end
def open(fileName, openMode = "r", &block) def open(fileName, openMode = "r", &block)
entryName = @zipFile.dir.expand_to_entry(fileName) entryName = @dir.expand_to_entry(fileName)
case openMode case openMode
when "r" when "r"
@zipFile.get_input_stream(entryName, &block) @zipFile.get_input_stream(entryName, &block)
@ -285,8 +295,7 @@ module Zip
alias :unlink :delete alias :unlink :delete
def expand_path(aPath) def expand_path(aPath)
@zipFile.dir.expand_path(aPath) @dir.expand_path(aPath)
end
end end
end end
@ -294,10 +303,12 @@ module Zip
def initialize(zipFile) def initialize(zipFile)
@zipFile = zipFile @zipFile = zipFile
@file = @zipFile.file
@pwd = "/" @pwd = "/"
end end
attr_writer :file
# protected :file
attr_reader :pwd attr_reader :pwd
alias getwd pwd alias getwd pwd
@ -322,7 +333,7 @@ module Zip
end end
def delete(entryName) def delete(entryName)
unless @zipFile.file.stat(entryName).directory? unless @file.stat(entryName).directory?
raise Errno::EINVAL, "Invalid argument - #{entryName}" raise Errno::EINVAL, "Invalid argument - #{entryName}"
end end
@zipFile.remove(entryName) @zipFile.remove(entryName)
@ -345,6 +356,7 @@ module Zip
expand_path(aPath).lchop expand_path(aPath).lchop
end end
end end
end
class ZipFile class ZipFile
include ZipFileSystem include ZipFileSystem