zip-container 1.1.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2013 The University of Manchester, UK.
1
+ # Copyright (c) 2013, 2014 The University of Manchester, UK.
2
2
  #
3
3
  # All rights reserved.
4
4
  #
@@ -45,14 +45,13 @@ module ZipContainer
45
45
  # alongside these pages.
46
46
  #
47
47
  # There are code examples available with the source code of this library.
48
- class Container
48
+ class File
49
49
  include ReservedNames
50
50
  include ManagedEntries
51
51
 
52
52
  extend Forwardable
53
53
  def_delegators :@zipfile, :comment, :comment=, :commit_required?, :each,
54
- :entries, :extract, :find_entry, :get_entry, :get_input_stream, :glob,
55
- :name, :read, :size
54
+ :entries, :extract, :get_input_stream, :name, :read, :size
56
55
 
57
56
  private_class_method :new
58
57
 
@@ -87,11 +86,11 @@ module ZipContainer
87
86
  # :startdoc:
88
87
 
89
88
  # :call-seq:
90
- # Container.create(filename, mimetype = "application/epub+zip") -> document
91
- # Container.create(filename, mimetype = "application/epub+zip") {|document| ...}
89
+ # File.create(filename, mimetype) -> document
90
+ # File.create(filename, mimetype) {|document| ...}
92
91
  #
93
92
  # Create a new ZipContainer file on disk with the specified mimetype.
94
- def Container.create(filename, mimetype, &block)
93
+ def self.create(filename, mimetype, &block)
95
94
  ::Zip::OutputStream.open(filename) do |stream|
96
95
  stream.put_next_entry(MIMETYPE_FILE, nil, nil, ::Zip::Entry::STORED)
97
96
  stream.write mimetype
@@ -112,13 +111,13 @@ module ZipContainer
112
111
  end
113
112
 
114
113
  # :call-seq:
115
- # Container.each_entry -> Enumerator
116
- # Container.each_entry {|entry| ...}
114
+ # File.each_entry -> Enumerator
115
+ # File.each_entry {|entry| ...}
117
116
  #
118
117
  # Iterate over the entries in the ZipContainer file. The entry objects
119
118
  # returned by this method are Zip::Entry objects. Please see the
120
119
  # rubyzip documentation for details.
121
- def Container.each_entry(filename, &block)
120
+ def self.each_entry(filename, &block)
122
121
  c = new(filename)
123
122
 
124
123
  if block_given?
@@ -133,12 +132,12 @@ module ZipContainer
133
132
  end
134
133
 
135
134
  # :call-seq:
136
- # Container.open(filename) -> document
137
- # Container.open(filename) {|document| ...}
135
+ # File.open(filename) -> document
136
+ # File.open(filename) {|document| ...}
138
137
  #
139
138
  # Open an existing ZipContainer file from disk. It will be checked for
140
139
  # conformance upon first access.
141
- def Container.open(filename, &block)
140
+ def self.open(filename, &block)
142
141
  c = new(filename)
143
142
 
144
143
  if block_given?
@@ -153,12 +152,12 @@ module ZipContainer
153
152
  end
154
153
 
155
154
  # :call-seq:
156
- # Container.verify(filename) -> boolean
155
+ # File.verify(filename) -> boolean
157
156
  #
158
157
  # Verify that the specified ZipContainer file conforms to the
159
158
  # specification. This method returns +false+ if there are any problems at
160
159
  # all with the file (including if it cannot be found).
161
- def Container.verify(filename)
160
+ def self.verify(filename)
162
161
  begin
163
162
  new(filename).verify!
164
163
  rescue
@@ -169,13 +168,13 @@ module ZipContainer
169
168
  end
170
169
 
171
170
  # :call-seq:
172
- # Container.verify!(filename)
171
+ # File.verify!(filename)
173
172
  #
174
173
  # Verify that the specified ZipContainer file conforms to the
175
174
  # specification. This method raises exceptions when errors are found or if
176
175
  # there is something fundamental wrong with the file itself (e.g. it
177
176
  # cannot be found).
178
- def Container.verify!(filename)
177
+ def self.verify!(filename)
179
178
  new(filename).verify!
180
179
  end
181
180
 
@@ -238,6 +237,40 @@ module ZipContainer
238
237
  @fs_file
239
238
  end
240
239
 
240
+ # :call-seq:
241
+ # find_entry(entry_name, options = {}) -> Zip::Entry or nil
242
+ #
243
+ # Searches for the entry with the specified name. Returns +nil+ if no
244
+ # entry is found or if the specified entry is hidden for normal use. You
245
+ # can specify <tt>:include_hidden => true</tt> to include hidden entries
246
+ # in the search.
247
+ def find_entry(entry_name, options = {})
248
+ options = {:include_hidden => false}.merge(options)
249
+
250
+ unless options[:include_hidden]
251
+ return if hidden_entry?(entry_name)
252
+ end
253
+
254
+ @zipfile.find_entry(entry_name)
255
+ end
256
+
257
+ # :call-seq:
258
+ # get_entry(entry, options = {}) -> Zip::Entry or nil
259
+ #
260
+ # Searches for an entry like find_entry, but throws Errno::ENOENT if no
261
+ # entry is found or if the specified entry is hidden for normal use. You
262
+ # can specify <tt>:include_hidden => true</tt> to include hidden entries
263
+ # in the search.
264
+ def get_entry(entry, options = {})
265
+ options = {:include_hidden => false}.merge(options)
266
+
267
+ unless options[:include_hidden]
268
+ raise Errno::ENOENT, entry if hidden_entry?(entry)
269
+ end
270
+
271
+ @zipfile.get_entry(entry)
272
+ end
273
+
241
274
  # :call-seq:
242
275
  # get_output_stream(entry, permission = nil) -> stream
243
276
  # get_output_stream(entry, permission = nil) {|stream| ...}
@@ -256,6 +289,41 @@ module ZipContainer
256
289
  @zipfile.get_output_stream(entry, permission, &block)
257
290
  end
258
291
 
292
+ # :call-seq:
293
+ # glob(pattern) -> Array
294
+ # glob(pattern) { |entry| ... }
295
+ # glob(pattern, *parameters) -> Array
296
+ # glob(pattern, *parameters) { |entry| ... }
297
+ #
298
+ # Searches for entries given a glob. Hidden files are ignored by default.
299
+ #
300
+ # The parameters that can be supplied are:
301
+ # * +flags+ - A bitwise OR of the <tt>FNM_xxx</tt> parameters defined in
302
+ # File::Constants. The default value is
303
+ # <tt>::File::FNM_PATHNAME | ::File::FNM_DOTMATCH</tt>
304
+ # * +options+ - <tt>:include_hidden => true</tt> will include hidden
305
+ # entries in the search.
306
+ def glob(pattern, *params, &block)
307
+ flags = ::File::FNM_PATHNAME | ::File::FNM_DOTMATCH
308
+ options = { :include_hidden => false }
309
+
310
+ params.each do |param|
311
+ case param
312
+ when Hash
313
+ options = options.merge(param)
314
+ else
315
+ flags = param
316
+ end
317
+ end
318
+
319
+ entries.map do |entry|
320
+ next if !options[:include_hidden] && hidden_entry?(entry)
321
+ next unless ::File.fnmatch(pattern, entry.name.chomp('/'), flags)
322
+ yield(entry) if block_given?
323
+ entry
324
+ end.compact
325
+ end
326
+
259
327
  # :call-seq:
260
328
  # in_memory? -> boolean
261
329
  #
@@ -0,0 +1,59 @@
1
+ # Copyright (c) 2014 The University of Manchester, UK.
2
+ #
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # * Redistributions of source code must retain the above copyright notice,
9
+ # this list of conditions and the following disclaimer.
10
+ #
11
+ # * Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # * Neither the names of The University of Manchester nor the names of its
16
+ # contributors may be used to endorse or promote products derived from this
17
+ # software without specific prior written permission.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
+ # POSSIBILITY OF SUCH DAMAGE.
30
+ #
31
+ # Author: Robert Haines
32
+
33
+ #
34
+ module ZipContainer
35
+
36
+ # Utility methods useful throughout the rest of the ZipContainer library.
37
+ module Util
38
+
39
+ # :call-seq:
40
+ # entry_name(entry) -> String
41
+ #
42
+ # A lot of methods can take either a String or a Zip::Entry object to
43
+ # represent an item in a Zip file so this method normalizes these
44
+ # parameters.
45
+ #
46
+ # In common with rubyzip this method also removes a trailing slash (/)
47
+ # from a name if it can.
48
+ def entry_name(entry)
49
+ name = entry.kind_of?(::Zip::Entry) ? entry.name : entry
50
+
51
+ if name.respond_to?(:end_with?) && name.respond_to?(:chop!)
52
+ name.chop! if name.end_with?("/")
53
+ end
54
+
55
+ name
56
+ end
57
+
58
+ end
59
+ end
Binary file
@@ -0,0 +1,35 @@
1
+ # Copyright (c) 2014 The University of Manchester, UK.
2
+ #
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # * Redistributions of source code must retain the above copyright notice,
9
+ # this list of conditions and the following disclaimer.
10
+ #
11
+ # * Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # * Neither the names of The University of Manchester nor the names of its
16
+ # contributors may be used to endorse or promote products derived from this
17
+ # software without specific prior written permission.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
+ # POSSIBILITY OF SUCH DAMAGE.
30
+ #
31
+ # Author: Robert Haines
32
+
33
+ def entry_list_names(entries)
34
+ entries.map { |entry| entry.name }
35
+ end
data/test/tc_create.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2013 The University of Manchester, UK.
1
+ # Copyright (c) 2013, 2014 The University of Manchester, UK.
2
2
  #
3
3
  # All rights reserved.
4
4
  #
@@ -42,7 +42,7 @@ class TestCreation < Test::Unit::TestCase
42
42
  filename = File.join(dir, "test.container")
43
43
 
44
44
  assert_nothing_raised do
45
- ZipContainer::Container.create(filename, $mimetype) do |c|
45
+ ZipContainer::File.create(filename, $mimetype) do |c|
46
46
  assert(c.on_disk?)
47
47
  refute(c.in_memory?)
48
48
 
@@ -50,8 +50,8 @@ class TestCreation < Test::Unit::TestCase
50
50
  end
51
51
  end
52
52
 
53
- assert_nothing_raised(ZipContainer::MalformedContainerError, Zip::ZipError) do
54
- ZipContainer::Container.verify!(filename)
53
+ assert_nothing_raised(ZipContainer::MalformedContainerError, ZipContainer::ZipError) do
54
+ ZipContainer::File.verify!(filename)
55
55
  end
56
56
  end
57
57
  end
@@ -64,7 +64,7 @@ class TestCreation < Test::Unit::TestCase
64
64
  filename = File.join(dir, "test.container")
65
65
 
66
66
  assert_nothing_raised do
67
- ZipContainer::Container.create(filename, mimetype) do |c|
67
+ ZipContainer::File.create(filename, mimetype) do |c|
68
68
  assert(c.on_disk?)
69
69
  refute(c.in_memory?)
70
70
 
@@ -72,8 +72,8 @@ class TestCreation < Test::Unit::TestCase
72
72
  end
73
73
  end
74
74
 
75
- assert_nothing_raised(ZipContainer::MalformedContainerError, Zip::ZipError) do
76
- ZipContainer::Container.verify!(filename)
75
+ assert_nothing_raised(ZipContainer::MalformedContainerError, ZipContainer::ZipError) do
76
+ ZipContainer::File.verify!(filename)
77
77
  end
78
78
  end
79
79
  end
@@ -85,7 +85,7 @@ class TestCreation < Test::Unit::TestCase
85
85
  filename = File.join(dir, "test.container")
86
86
 
87
87
  assert_nothing_raised do
88
- ZipContainer::Container.create(filename, $mimetype) do |c|
88
+ ZipContainer::File.create(filename, $mimetype) do |c|
89
89
  assert(c.on_disk?)
90
90
  refute(c.in_memory?)
91
91
 
@@ -115,8 +115,8 @@ class TestCreation < Test::Unit::TestCase
115
115
  end
116
116
  end
117
117
 
118
- assert_nothing_raised(ZipContainer::MalformedContainerError, Zip::ZipError) do
119
- ZipContainer::Container.open(filename) do |c|
118
+ assert_nothing_raised(ZipContainer::MalformedContainerError, ZipContainer::ZipError) do
119
+ ZipContainer::File.open(filename) do |c|
120
120
  assert(c.on_disk?)
121
121
  refute(c.in_memory?)
122
122
 
@@ -0,0 +1,56 @@
1
+ # Copyright (c) 2014 The University of Manchester, UK.
2
+ #
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # * Redistributions of source code must retain the above copyright notice,
9
+ # this list of conditions and the following disclaimer.
10
+ #
11
+ # * Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # * Neither the names of The University of Manchester nor the names of its
16
+ # contributors may be used to endorse or promote products derived from this
17
+ # software without specific prior written permission.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
+ # POSSIBILITY OF SUCH DAMAGE.
30
+ #
31
+ # Author: Robert Haines
32
+
33
+ require 'test/unit'
34
+ require 'zip-container'
35
+
36
+ class TestExceptions < Test::Unit::TestCase
37
+
38
+ def test_rescue_container_errors
39
+ assert_raise(ZipContainer::ContainerError) do
40
+ raise ZipContainer::ZipError.new
41
+ end
42
+
43
+ assert_raise(ZipContainer::ContainerError) do
44
+ raise ZipContainer::MalformedContainerError.new
45
+ end
46
+
47
+ assert_raise(ZipContainer::ContainerError) do
48
+ raise ZipContainer::ReservedNameClashError.new("test")
49
+ end
50
+
51
+ assert_raise(ZipContainer::ContainerError) do
52
+ raise Zip::ZipError.new
53
+ end
54
+ end
55
+
56
+ end
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2013 The University of Manchester, UK.
1
+ # Copyright (c) 2013, 2014 The University of Manchester, UK.
2
2
  #
3
3
  # All rights reserved.
4
4
  #
@@ -33,35 +33,41 @@
33
33
  require 'test/unit'
34
34
  require 'tmpdir'
35
35
  require 'zip-container'
36
+ require 'helpers/entry_lists'
36
37
 
37
38
  # Classes to test managed entries.
38
- class ManagedZipContainer < ZipContainer::Container
39
+ class ManagedZipContainer < ZipContainer::File
39
40
 
40
41
  private_class_method :new
41
42
 
42
43
  def initialize(filename)
43
44
  super(filename)
44
- register_managed_entry(ZipContainer::ManagedDirectory.new("src", true))
45
- register_managed_entry(ZipContainer::ManagedDirectory.new("test"))
45
+ test_file = ZipContainer::ManagedFile.new("test.txt")
46
+ deep_file = ZipContainer::ManagedFile.new("deep.txt")
47
+ deep_dir = ZipContainer::ManagedDirectory.new("deep",
48
+ :entries => [deep_file])
49
+ register_managed_entry(ZipContainer::ManagedDirectory.new("src", :required => true))
50
+ register_managed_entry(ZipContainer::ManagedDirectory.new("test",
51
+ :hidden => true, :entries => [deep_dir, test_file]))
46
52
  register_managed_entry(ZipContainer::ManagedDirectory.new("lib"))
47
- register_managed_entry(ZipContainer::ManagedFile.new("index.html", true))
53
+ register_managed_entry(ZipContainer::ManagedFile.new("index.html", :required => true))
48
54
  end
49
55
 
50
56
  end
51
57
 
52
- class ExampleZipContainer < ZipContainer::Container
58
+ class ExampleZipContainer < ZipContainer::File
53
59
 
54
60
  private_class_method :new
55
61
 
56
62
  def initialize(filename)
57
63
  super(filename)
58
- register_managed_entry(ZipContainer::ManagedDirectory.new("dir", true))
59
- register_managed_entry(ZipContainer::ManagedFile.new("greeting.txt", true))
64
+ register_managed_entry(ZipContainer::ManagedDirectory.new("dir", :required => true))
65
+ register_managed_entry(ZipContainer::ManagedFile.new("greeting.txt", :required => true))
60
66
  end
61
67
 
62
68
  end
63
69
 
64
- class ExampleZipContainer2 < ZipContainer::Container
70
+ class ExampleZipContainer2 < ZipContainer::File
65
71
 
66
72
  private_class_method :new
67
73
 
@@ -70,7 +76,7 @@ class ExampleZipContainer2 < ZipContainer::Container
70
76
 
71
77
  valid = Proc.new { |contents| contents.match(/[Hh]ello/) }
72
78
  register_managed_entry(ZipContainer::ManagedFile.new("greeting.txt",
73
- true, valid))
79
+ :required => true, :validation_proc => valid))
74
80
  end
75
81
 
76
82
  def ExampleZipContainer2.create(filename, &block)
@@ -117,7 +123,7 @@ class TestManagedEntries < Test::Unit::TestCase
117
123
  filename = File.join(dir, "test.container")
118
124
 
119
125
  assert_nothing_raised do
120
- ZipContainer::Container.create(filename, $mimetype) do |c|
126
+ ZipContainer::File.create(filename, $mimetype) do |c|
121
127
  c.mkdir("META-INF")
122
128
  assert(c.file.exists?("META-INF"))
123
129
 
@@ -129,7 +135,7 @@ class TestManagedEntries < Test::Unit::TestCase
129
135
  end
130
136
 
131
137
  assert_nothing_raised(ZipContainer::MalformedContainerError) do
132
- ZipContainer::Container.verify!(filename)
138
+ ZipContainer::File.verify!(filename)
133
139
  end
134
140
  end
135
141
  end
@@ -167,6 +173,26 @@ class TestManagedEntries < Test::Unit::TestCase
167
173
  c.file.open("index.html", "w") do |f|
168
174
  f.puts "<html />"
169
175
  end
176
+
177
+ # Test hidden entries before and after creation.
178
+ assert_nil(c.find_entry("test", :include_hidden => true))
179
+ assert_nil(c.find_entry("test/test.txt", :include_hidden => true))
180
+ c.dir.mkdir("test")
181
+ c.file.open("test/test.txt", "w") do |f|
182
+ f.puts "A test!"
183
+ end
184
+ assert_not_nil(c.find_entry("test", :include_hidden => true))
185
+ assert_not_nil(c.find_entry("test/test.txt", :include_hidden => true))
186
+
187
+ # Test deep hidden entries before and after creation.
188
+ assert_nil(c.find_entry("test/deep", :include_hidden => true))
189
+ assert_nil(c.find_entry("test/deep/deep.txt", :include_hidden => true))
190
+ c.dir.mkdir("test/deep")
191
+ c.file.open("test/deep/deep.txt", "w") do |f|
192
+ f.puts "A deep test!"
193
+ end
194
+ assert_not_nil(c.find_entry("test/deep", :include_hidden => true))
195
+ assert_not_nil(c.find_entry("test/deep/deep.txt", :include_hidden => true))
170
196
  end
171
197
  end
172
198
 
@@ -177,6 +203,95 @@ class TestManagedEntries < Test::Unit::TestCase
177
203
  end
178
204
  end
179
205
 
206
+ def test_hidden_entries
207
+ assert_nothing_raised do
208
+ ManagedZipContainer.open($subclass) do |c|
209
+ refute(c.hidden_entry?("src"))
210
+ refute(c.hidden_file?("src"))
211
+ refute(c.hidden_directory?("src"))
212
+
213
+ assert(c.hidden_entry?("test"))
214
+ assert(c.hidden_directory?("test"))
215
+ assert(c.hidden_entry?("test/"))
216
+ assert(c.hidden_directory?("test/"))
217
+ refute(c.hidden_file?("test"))
218
+
219
+ assert(c.hidden_entry?("test/deep"))
220
+ assert(c.hidden_directory?("test/deep"))
221
+ assert(c.hidden_entry?("test/deep/deep.txt"))
222
+ assert(c.hidden_file?("test/deep/deep.txt"))
223
+ end
224
+ end
225
+ end
226
+
227
+ def test_find_entry
228
+ assert_nothing_raised do
229
+ ManagedZipContainer.open($subclass) do |c|
230
+ assert_not_nil(c.find_entry("src"))
231
+ assert_not_nil(c.find_entry("src", :include_hidden => true))
232
+
233
+ assert_nil(c.find_entry("test"))
234
+ assert_nil(c.find_entry("test/test.txt"))
235
+ assert_not_nil(c.find_entry("test", :include_hidden => true))
236
+ assert_not_nil(c.find_entry("test/test.txt", :include_hidden => true))
237
+
238
+ assert_nil(c.find_entry("test/deep"))
239
+ assert_nil(c.find_entry("test/deep/deep.txt"))
240
+ assert_not_nil(c.find_entry("test/deep", :include_hidden => true))
241
+ assert_not_nil(c.find_entry("test/deep/deep.txt", :include_hidden => true))
242
+ end
243
+ end
244
+ end
245
+
246
+ def test_get_entry
247
+ ManagedZipContainer.open($subclass) do |c|
248
+ assert_nothing_raised(Errno::ENOENT) do
249
+ c.get_entry("src")
250
+ end
251
+ assert_nothing_raised(Errno::ENOENT) do
252
+ c.get_entry("src", :include_hidden => true)
253
+ end
254
+
255
+ assert_raise(Errno::ENOENT) do
256
+ c.get_entry("test")
257
+ end
258
+ assert_raise(Errno::ENOENT) do
259
+ c.get_entry("test/test.txt")
260
+ end
261
+ assert_nothing_raised(Errno::ENOENT) do
262
+ c.get_entry("test", :include_hidden => true)
263
+ end
264
+ assert_nothing_raised(Errno::ENOENT) do
265
+ c.get_entry("test/test.txt", :include_hidden => true)
266
+ end
267
+
268
+ assert_raise(Errno::ENOENT) do
269
+ c.get_entry("test/deep")
270
+ end
271
+ assert_raise(Errno::ENOENT) do
272
+ c.get_entry("test/deep/deep.txt")
273
+ end
274
+ assert_nothing_raised(Errno::ENOENT) do
275
+ c.get_entry("test/deep", :include_hidden => true)
276
+ end
277
+ assert_nothing_raised(Errno::ENOENT) do
278
+ c.get_entry("test/deep/deep.txt", :include_hidden => true)
279
+ end
280
+ end
281
+ end
282
+
283
+ def test_glob
284
+ ManagedZipContainer.open($subclass) do |c|
285
+ assert_equal(["index.html"], entry_list_names(c.glob("in*")))
286
+ assert_equal([], c.glob("test/**/*"))
287
+ assert_equal(["test/test.txt", "test/deep", "test/deep/deep.txt"],
288
+ entry_list_names(c.glob("test/**/*", :include_hidden => true)))
289
+ assert_equal(["test/test.txt", "test/deep/deep.txt"],
290
+ entry_list_names(c.glob("**/*.TXT", ::File::FNM_CASEFOLD,
291
+ :include_hidden => true)))
292
+ end
293
+ end
294
+
180
295
  def test_create_subclassed_mimetype
181
296
  Dir.mktmpdir do |dir|
182
297
  filename = File.join(dir, "test.container")