rubyzip 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/README.md +95 -43
- data/lib/zip.rb +11 -1
- data/lib/zip/central_directory.rb +3 -3
- data/lib/zip/compressor.rb +1 -2
- data/lib/zip/constants.rb +3 -3
- data/lib/zip/crypto/null_encryption.rb +2 -4
- data/lib/zip/decompressor.rb +1 -1
- data/lib/zip/dos_time.rb +1 -1
- data/lib/zip/entry.rb +70 -54
- data/lib/zip/entry_set.rb +4 -4
- data/lib/zip/errors.rb +1 -0
- data/lib/zip/extra_field.rb +2 -2
- data/lib/zip/extra_field/generic.rb +1 -1
- data/lib/zip/extra_field/zip64_placeholder.rb +1 -2
- data/lib/zip/file.rb +62 -51
- data/lib/zip/filesystem.rb +17 -13
- data/lib/zip/inflater.rb +2 -2
- data/lib/zip/input_stream.rb +10 -7
- data/lib/zip/ioextras/abstract_input_stream.rb +1 -1
- data/lib/zip/ioextras/abstract_output_stream.rb +3 -3
- data/lib/zip/output_stream.rb +5 -5
- data/lib/zip/pass_thru_decompressor.rb +1 -1
- data/lib/zip/streamable_stream.rb +1 -1
- data/lib/zip/version.rb +1 -1
- data/samples/example_recursive.rb +15 -18
- data/samples/gtk_ruby_zip.rb +1 -1
- data/samples/qtzip.rb +1 -1
- data/samples/zipfind.rb +2 -2
- data/test/central_directory_entry_test.rb +2 -2
- data/test/crypto/null_encryption_test.rb +6 -2
- data/test/data/gpbit3stored.zip +0 -0
- data/test/data/path_traversal/Makefile +10 -0
- data/test/data/path_traversal/jwilk/README.md +5 -0
- data/test/data/path_traversal/jwilk/absolute1.zip +0 -0
- data/test/data/path_traversal/jwilk/absolute2.zip +0 -0
- data/test/data/path_traversal/jwilk/dirsymlink.zip +0 -0
- data/test/data/path_traversal/jwilk/dirsymlink2a.zip +0 -0
- data/test/data/path_traversal/jwilk/dirsymlink2b.zip +0 -0
- data/test/data/path_traversal/jwilk/relative0.zip +0 -0
- data/test/data/path_traversal/jwilk/relative2.zip +0 -0
- data/test/data/path_traversal/jwilk/symlink.zip +0 -0
- data/test/data/path_traversal/relative1.zip +0 -0
- data/test/data/path_traversal/tilde.zip +0 -0
- data/test/data/path_traversal/tuzovakaoff/README.md +3 -0
- data/test/data/path_traversal/tuzovakaoff/absolutepath.zip +0 -0
- data/test/data/path_traversal/tuzovakaoff/symlink.zip +0 -0
- data/test/data/rubycode.zip +0 -0
- data/test/entry_set_test.rb +13 -2
- data/test/entry_test.rb +3 -12
- data/test/errors_test.rb +1 -0
- data/test/file_extract_test.rb +62 -0
- data/test/file_permissions_test.rb +39 -43
- data/test/file_test.rb +115 -12
- data/test/filesystem/dir_iterator_test.rb +1 -1
- data/test/filesystem/directory_test.rb +29 -11
- data/test/filesystem/file_mutating_test.rb +3 -4
- data/test/filesystem/file_nonmutating_test.rb +34 -34
- data/test/filesystem/file_stat_test.rb +5 -5
- data/test/gentestfiles.rb +17 -13
- data/test/input_stream_test.rb +10 -10
- data/test/ioextras/abstract_input_stream_test.rb +1 -1
- data/test/ioextras/abstract_output_stream_test.rb +2 -2
- data/test/ioextras/fake_io_test.rb +1 -1
- data/test/local_entry_test.rb +1 -1
- data/test/path_traversal_test.rb +141 -0
- data/test/test_helper.rb +16 -3
- data/test/unicode_file_names_and_comments_test.rb +12 -0
- data/test/zip64_full_test.rb +2 -2
- metadata +103 -51
data/test/file_test.rb
CHANGED
@@ -2,6 +2,7 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class ZipFileTest < MiniTest::Test
|
4
4
|
include CommonZipFileFixture
|
5
|
+
include ZipEntryData
|
5
6
|
|
6
7
|
OK_DELETE_FILE = 'test/data/generated/okToDelete.txt'
|
7
8
|
OK_DELETE_MOVED_FILE = 'test/data/generated/okToDeleteMoved.txt'
|
@@ -40,6 +41,26 @@ class ZipFileTest < MiniTest::Test
|
|
40
41
|
assert_equal(2, zfRead.entries.length)
|
41
42
|
end
|
42
43
|
|
44
|
+
def test_create_from_scratch_with_old_create_parameter
|
45
|
+
comment = 'a short comment'
|
46
|
+
|
47
|
+
zf = ::Zip::File.new(EMPTY_FILENAME, 1)
|
48
|
+
zf.get_output_stream('myFile') { |os| os.write 'myFile contains just this' }
|
49
|
+
zf.mkdir('dir1')
|
50
|
+
zf.comment = comment
|
51
|
+
zf.close
|
52
|
+
|
53
|
+
zfRead = ::Zip::File.new(EMPTY_FILENAME)
|
54
|
+
assert_equal(comment, zfRead.comment)
|
55
|
+
assert_equal(2, zfRead.entries.length)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_get_input_stream_stored_with_gpflag_bit3
|
59
|
+
::Zip::File.open('test/data/gpbit3stored.zip') do |zf|
|
60
|
+
assert_equal("foo\n", zf.read("foo.txt"))
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
43
64
|
def test_get_output_stream
|
44
65
|
entryCount = nil
|
45
66
|
::Zip::File.open(TEST_ZIP.zip_name) do |zf|
|
@@ -56,7 +77,7 @@ class ZipFileTest < MiniTest::Test
|
|
56
77
|
assert_equal(entryCount + 1, zf.size)
|
57
78
|
assert_equal('Putting stuff in data/generated/empty.txt', zf.read('test/data/generated/empty.txt'))
|
58
79
|
|
59
|
-
custom_entry_args = [
|
80
|
+
custom_entry_args = [TEST_COMMENT, TEST_EXTRA, TEST_COMPRESSED_SIZE, TEST_CRC, ::Zip::Entry::STORED, TEST_SIZE, TEST_TIME]
|
60
81
|
zf.get_output_stream('entry_with_custom_args.txt', nil, *custom_entry_args) do |os|
|
61
82
|
os.write 'Some data'
|
62
83
|
end
|
@@ -82,6 +103,13 @@ class ZipFileTest < MiniTest::Test
|
|
82
103
|
end
|
83
104
|
end
|
84
105
|
|
106
|
+
def test_open_buffer_with_string
|
107
|
+
string = File.read('test/data/rubycode.zip')
|
108
|
+
::Zip::File.open_buffer string do |zf|
|
109
|
+
assert zf.entries.map { |e| e.name }.include?('zippedruby1.rb')
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
85
113
|
def test_open_buffer_with_stringio
|
86
114
|
string_io = StringIO.new File.read('test/data/rubycode.zip')
|
87
115
|
::Zip::File.open_buffer string_io do |zf|
|
@@ -89,6 +117,63 @@ class ZipFileTest < MiniTest::Test
|
|
89
117
|
end
|
90
118
|
end
|
91
119
|
|
120
|
+
def test_close_buffer_with_stringio
|
121
|
+
string_io = StringIO.new File.read('test/data/rubycode.zip')
|
122
|
+
zf = ::Zip::File.open_buffer string_io
|
123
|
+
assert_nil zf.close
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_open_buffer_no_op_does_not_change_file
|
127
|
+
Dir.mktmpdir do |tmp|
|
128
|
+
test_zip = File.join(tmp, 'test.zip')
|
129
|
+
FileUtils.cp 'test/data/rubycode.zip', test_zip
|
130
|
+
|
131
|
+
# Note: this may change the file if it is opened with r+b instead of rb.
|
132
|
+
# The 'extra fields' in this particular zip file get reordered.
|
133
|
+
File.open(test_zip, 'rb') do |file|
|
134
|
+
Zip::File.open_buffer(file) do |zf|
|
135
|
+
nil # do nothing
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
assert_equal \
|
140
|
+
File.binread('test/data/rubycode.zip'),
|
141
|
+
File.binread(test_zip)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_open_buffer_close_does_not_change_file
|
146
|
+
Dir.mktmpdir do |tmp|
|
147
|
+
test_zip = File.join(tmp, 'test.zip')
|
148
|
+
FileUtils.cp 'test/data/rubycode.zip', test_zip
|
149
|
+
|
150
|
+
File.open(test_zip, 'rb') do |file|
|
151
|
+
zf = Zip::File.open_buffer(file)
|
152
|
+
refute zf.commit_required?
|
153
|
+
assert_nil zf.close
|
154
|
+
end
|
155
|
+
|
156
|
+
assert_equal \
|
157
|
+
File.binread('test/data/rubycode.zip'),
|
158
|
+
File.binread(test_zip)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
def test_open_buffer_with_io_and_block
|
163
|
+
File.open('test/data/rubycode.zip') do |io|
|
164
|
+
io.set_encoding(Encoding::BINARY) # not strictly required but can be set
|
165
|
+
Zip::File.open_buffer(io) do |zip_io|
|
166
|
+
# left empty on purpose
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
def test_open_buffer_without_block
|
172
|
+
string_io = StringIO.new File.read('test/data/rubycode.zip')
|
173
|
+
zf = ::Zip::File.open_buffer string_io
|
174
|
+
assert zf.entries.map { |e| e.name }.include?('zippedruby1.rb')
|
175
|
+
end
|
176
|
+
|
92
177
|
def test_cleans_up_tempfiles_after_close
|
93
178
|
zf = ::Zip::File.new(EMPTY_FILENAME, ::Zip::File::CREATE)
|
94
179
|
zf.get_output_stream('myFile') do |os|
|
@@ -119,17 +204,37 @@ class ZipFileTest < MiniTest::Test
|
|
119
204
|
zfRead.get_input_stream(entryName) { |zis| zis.read })
|
120
205
|
end
|
121
206
|
|
207
|
+
def test_add_stored
|
208
|
+
srcFile = 'test/data/file2.txt'
|
209
|
+
entryName = 'newEntryName.rb'
|
210
|
+
assert(::File.exist?(srcFile))
|
211
|
+
zf = ::Zip::File.new(EMPTY_FILENAME, ::Zip::File::CREATE)
|
212
|
+
zf.add_stored(entryName, srcFile)
|
213
|
+
zf.close
|
214
|
+
|
215
|
+
zfRead = ::Zip::File.new(EMPTY_FILENAME)
|
216
|
+
entry = zfRead.entries.first
|
217
|
+
assert_equal('', zfRead.comment)
|
218
|
+
assert_equal(1, zfRead.entries.length)
|
219
|
+
assert_equal(entryName, entry.name)
|
220
|
+
assert_equal(File.size(srcFile), entry.size)
|
221
|
+
assert_equal(entry.size, entry.compressed_size)
|
222
|
+
assert_equal(::Zip::Entry::STORED, entry.compression_method)
|
223
|
+
AssertEntry.assert_contents(srcFile,
|
224
|
+
zfRead.get_input_stream(entryName) { |zis| zis.read })
|
225
|
+
end
|
226
|
+
|
122
227
|
def test_recover_permissions_after_add_files_to_archive
|
123
228
|
srcZip = TEST_ZIP.zip_name
|
124
|
-
::File.chmod(
|
229
|
+
::File.chmod(0o664, srcZip)
|
125
230
|
srcFile = 'test/data/file2.txt'
|
126
231
|
entryName = 'newEntryName.rb'
|
127
|
-
assert_equal(::File.stat(srcZip).mode,
|
232
|
+
assert_equal(::File.stat(srcZip).mode, 0o100664)
|
128
233
|
assert(::File.exist?(srcZip))
|
129
234
|
zf = ::Zip::File.new(srcZip, ::Zip::File::CREATE)
|
130
235
|
zf.add(entryName, srcFile)
|
131
236
|
zf.close
|
132
|
-
assert_equal(::File.stat(srcZip).mode,
|
237
|
+
assert_equal(::File.stat(srcZip).mode, 0o100664)
|
133
238
|
end
|
134
239
|
|
135
240
|
def test_add_existing_entry_name
|
@@ -213,7 +318,7 @@ class ZipFileTest < MiniTest::Test
|
|
213
318
|
zf.mkdir('test')
|
214
319
|
arr << 'test/'
|
215
320
|
arr_renamed << 'Ztest/'
|
216
|
-
%w
|
321
|
+
%w[a b c d].each do |f|
|
217
322
|
zf.get_output_stream("test/#{f}") { |file| file.puts 'aaaa' }
|
218
323
|
arr << "test/#{f}"
|
219
324
|
arr_renamed << "Ztest/#{f}"
|
@@ -308,7 +413,7 @@ class ZipFileTest < MiniTest::Test
|
|
308
413
|
|
309
414
|
def test_replace_non_entry
|
310
415
|
entryToReplace = 'nonExistingEntryname'
|
311
|
-
::Zip::File.open(TEST_ZIP.zip_name) do
|
416
|
+
::Zip::File.open(TEST_ZIP.zip_name) do |zf|
|
312
417
|
assert_raises(Errno::ENOENT) { zf.replace(entryToReplace, 'test/data/file2.txt') }
|
313
418
|
end
|
314
419
|
end
|
@@ -326,7 +431,7 @@ class ZipFileTest < MiniTest::Test
|
|
326
431
|
zfRead.close
|
327
432
|
|
328
433
|
zf.close
|
329
|
-
res = system("unzip -
|
434
|
+
res = system("unzip -tqq #{TEST_ZIP.zip_name}")
|
330
435
|
assert_equal(res, true)
|
331
436
|
end
|
332
437
|
|
@@ -342,7 +447,7 @@ class ZipFileTest < MiniTest::Test
|
|
342
447
|
zf2 = ::Zip::File.open(filename)
|
343
448
|
assert(zf2.entries.detect { |e| e.name == 'test1.txt' } != nil)
|
344
449
|
assert(zf2.entries.detect { |e| e.name == 'test2.txt' } != nil)
|
345
|
-
res = system("unzip -
|
450
|
+
res = system("unzip -tqq #{filename}")
|
346
451
|
assert_equal(res, true)
|
347
452
|
end
|
348
453
|
|
@@ -413,7 +518,6 @@ class ZipFileTest < MiniTest::Test
|
|
413
518
|
filename_to_remove = originalEntries.map(&:to_s).find { |name| name.match('longBinary') }
|
414
519
|
zf.remove(filename_to_remove)
|
415
520
|
assert_not_contains(zf, filename_to_remove)
|
416
|
-
|
417
521
|
ensure
|
418
522
|
zf.close
|
419
523
|
end
|
@@ -528,9 +632,8 @@ class ZipFileTest < MiniTest::Test
|
|
528
632
|
end
|
529
633
|
|
530
634
|
def test_empty_zip
|
531
|
-
puts `touch empty.zip`
|
532
635
|
assert_raises(::Zip::Error) do
|
533
|
-
::Zip::File.open(
|
636
|
+
::Zip::File.open(TestFiles::NULL_FILE)
|
534
637
|
end
|
535
638
|
end
|
536
639
|
|
@@ -538,7 +641,7 @@ class ZipFileTest < MiniTest::Test
|
|
538
641
|
entry_count = 0
|
539
642
|
File.open 'test/data/oddExtraField.zip', 'rb' do |zip_io|
|
540
643
|
Zip::File.open_buffer zip_io.read do |zip|
|
541
|
-
zip.each do |
|
644
|
+
zip.each do |_zip_entry|
|
542
645
|
entry_count += 1
|
543
646
|
end
|
544
647
|
end
|
@@ -3,6 +3,7 @@ require 'zip/filesystem'
|
|
3
3
|
|
4
4
|
class ZipFsDirectoryTest < MiniTest::Test
|
5
5
|
TEST_ZIP = 'test/data/generated/zipWithDirs_copy.zip'
|
6
|
+
GLOB_TEST_ZIP = 'test/data/globTest.zip'
|
6
7
|
|
7
8
|
def setup
|
8
9
|
FileUtils.cp('test/data/zipWithDirs.zip', TEST_ZIP)
|
@@ -51,10 +52,10 @@ class ZipFsDirectoryTest < MiniTest::Test
|
|
51
52
|
zf.dir.chdir 'file1'
|
52
53
|
end
|
53
54
|
|
54
|
-
assert_equal(%w
|
55
|
+
assert_equal(%w[dir1 dir2 file1].sort, zf.dir.entries('.').sort)
|
55
56
|
zf.dir.chdir 'dir1'
|
56
57
|
assert_equal('/dir1', zf.dir.pwd)
|
57
|
-
assert_equal(%w
|
58
|
+
assert_equal(%w[dir11 file11 file12], zf.dir.entries('.').sort)
|
58
59
|
|
59
60
|
zf.dir.chdir '../dir2/dir21'
|
60
61
|
assert_equal('/dir2/dir21', zf.dir.pwd)
|
@@ -77,11 +78,11 @@ class ZipFsDirectoryTest < MiniTest::Test
|
|
77
78
|
|
78
79
|
entries = []
|
79
80
|
zf.dir.foreach('.') { |e| entries << e }
|
80
|
-
assert_equal(%w
|
81
|
+
assert_equal(%w[dir1 dir2 file1].sort, entries.sort)
|
81
82
|
|
82
83
|
entries = []
|
83
84
|
zf.dir.foreach('dir1') { |e| entries << e }
|
84
|
-
assert_equal(%w
|
85
|
+
assert_equal(%w[dir11 file11 file12], entries.sort)
|
85
86
|
end
|
86
87
|
end
|
87
88
|
|
@@ -93,11 +94,28 @@ class ZipFsDirectoryTest < MiniTest::Test
|
|
93
94
|
end
|
94
95
|
end
|
95
96
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
97
|
+
def test_glob
|
98
|
+
globbed_files = [
|
99
|
+
'globTest/foo/bar/baz/foo.txt',
|
100
|
+
'globTest/foo.txt',
|
101
|
+
'globTest/food.txt'
|
102
|
+
]
|
103
|
+
|
104
|
+
::Zip::File.open(GLOB_TEST_ZIP) do |zf|
|
105
|
+
zf.dir.glob('**/*.txt') do |f|
|
106
|
+
assert globbed_files.include?(f.name)
|
107
|
+
end
|
108
|
+
|
109
|
+
zf.dir.glob('globTest/foo/**/*.txt') do |f|
|
110
|
+
assert_equal globbed_files[0], f.name
|
111
|
+
end
|
112
|
+
|
113
|
+
zf.dir.chdir('globTest/foo')
|
114
|
+
zf.dir.glob('**/*.txt') do |f|
|
115
|
+
assert_equal globbed_files[0], f.name
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
101
119
|
|
102
120
|
def test_open_new
|
103
121
|
::Zip::File.open(TEST_ZIP) do |zf|
|
@@ -110,11 +128,11 @@ class ZipFsDirectoryTest < MiniTest::Test
|
|
110
128
|
end
|
111
129
|
|
112
130
|
d = zf.dir.new('.')
|
113
|
-
assert_equal(%w
|
131
|
+
assert_equal(%w[file1 dir1 dir2].sort, d.entries.sort)
|
114
132
|
d.close
|
115
133
|
|
116
134
|
zf.dir.open('dir1') do |dir|
|
117
|
-
assert_equal(%w
|
135
|
+
assert_equal(%w[dir11 file11 file12].sort, dir.entries.sort)
|
118
136
|
end
|
119
137
|
end
|
120
138
|
end
|
@@ -7,8 +7,7 @@ class ZipFsFileMutatingTest < MiniTest::Test
|
|
7
7
|
FileUtils.cp('test/data/zipWithDirs.zip', TEST_ZIP)
|
8
8
|
end
|
9
9
|
|
10
|
-
def teardown
|
11
|
-
end
|
10
|
+
def teardown; end
|
12
11
|
|
13
12
|
def test_delete
|
14
13
|
do_test_delete_or_unlink(:delete)
|
@@ -51,11 +50,11 @@ class ZipFsFileMutatingTest < MiniTest::Test
|
|
51
50
|
|
52
51
|
def test_chmod
|
53
52
|
::Zip::File.open(TEST_ZIP) do |zf|
|
54
|
-
zf.file.chmod(
|
53
|
+
zf.file.chmod(0o765, 'file1')
|
55
54
|
end
|
56
55
|
|
57
56
|
::Zip::File.open(TEST_ZIP) do |zf|
|
58
|
-
assert_equal(
|
57
|
+
assert_equal(0o100765, zf.file.stat('file1').mode)
|
59
58
|
end
|
60
59
|
end
|
61
60
|
|
@@ -14,11 +14,11 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
|
|
14
14
|
|
15
15
|
def test_umask
|
16
16
|
assert_equal(::File.umask, @zip_file.file.umask)
|
17
|
-
@zip_file.file.umask(
|
17
|
+
@zip_file.file.umask(0o006)
|
18
18
|
end
|
19
19
|
|
20
20
|
def test_exists?
|
21
|
-
assert(
|
21
|
+
assert(!@zip_file.file.exists?('notAFile'))
|
22
22
|
assert(@zip_file.file.exists?('file1'))
|
23
23
|
assert(@zip_file.file.exists?('dir1'))
|
24
24
|
assert(@zip_file.file.exists?('dir1/'))
|
@@ -103,24 +103,24 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
|
|
103
103
|
end
|
104
104
|
|
105
105
|
def test_size?
|
106
|
-
|
106
|
+
assert_nil(@zip_file.file.size?('notAFile'))
|
107
107
|
assert_equal(72, @zip_file.file.size?('file1'))
|
108
|
-
|
108
|
+
assert_nil(@zip_file.file.size?('dir2/dir21'))
|
109
109
|
|
110
110
|
assert_equal(72, @zip_file.file.stat('file1').size?)
|
111
|
-
|
111
|
+
assert_nil(@zip_file.file.stat('dir2/dir21').size?)
|
112
112
|
end
|
113
113
|
|
114
114
|
def test_file?
|
115
115
|
assert(@zip_file.file.file?('file1'))
|
116
116
|
assert(@zip_file.file.file?('dir2/file21'))
|
117
|
-
assert(
|
118
|
-
assert(
|
117
|
+
assert(!@zip_file.file.file?('dir1'))
|
118
|
+
assert(!@zip_file.file.file?('dir1/dir11'))
|
119
119
|
|
120
120
|
assert(@zip_file.file.stat('file1').file?)
|
121
121
|
assert(@zip_file.file.stat('dir2/file21').file?)
|
122
|
-
assert(
|
123
|
-
assert(
|
122
|
+
assert(!@zip_file.file.stat('dir1').file?)
|
123
|
+
assert(!@zip_file.file.stat('dir1/dir11').file?)
|
124
124
|
end
|
125
125
|
|
126
126
|
include ExtraAssertions
|
@@ -160,15 +160,15 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
|
|
160
160
|
end
|
161
161
|
|
162
162
|
def assert_always_false(operation)
|
163
|
-
assert(
|
164
|
-
assert(
|
165
|
-
assert(
|
166
|
-
assert(
|
167
|
-
assert(
|
163
|
+
assert(!@zip_file.file.send(operation, 'noSuchFile'))
|
164
|
+
assert(!@zip_file.file.send(operation, 'file1'))
|
165
|
+
assert(!@zip_file.file.send(operation, 'dir1'))
|
166
|
+
assert(!@zip_file.file.stat('file1').send(operation))
|
167
|
+
assert(!@zip_file.file.stat('dir1').send(operation))
|
168
168
|
end
|
169
169
|
|
170
170
|
def assert_true_if_entry_exists(operation)
|
171
|
-
assert(
|
171
|
+
assert(!@zip_file.file.send(operation, 'noSuchFile'))
|
172
172
|
assert(@zip_file.file.send(operation, 'file1'))
|
173
173
|
assert(@zip_file.file.send(operation, 'dir1'))
|
174
174
|
assert(@zip_file.file.stat('file1').send(operation))
|
@@ -221,15 +221,15 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
|
|
221
221
|
end
|
222
222
|
|
223
223
|
def test_directory?
|
224
|
-
assert(
|
225
|
-
assert(
|
226
|
-
assert(
|
224
|
+
assert(!@zip_file.file.directory?('notAFile'))
|
225
|
+
assert(!@zip_file.file.directory?('file1'))
|
226
|
+
assert(!@zip_file.file.directory?('dir1/file11'))
|
227
227
|
assert(@zip_file.file.directory?('dir1'))
|
228
228
|
assert(@zip_file.file.directory?('dir1/'))
|
229
229
|
assert(@zip_file.file.directory?('dir2/dir21'))
|
230
230
|
|
231
|
-
assert(
|
232
|
-
assert(
|
231
|
+
assert(!@zip_file.file.stat('file1').directory?)
|
232
|
+
assert(!@zip_file.file.stat('dir1/file11').directory?)
|
233
233
|
assert(@zip_file.file.stat('dir1').directory?)
|
234
234
|
assert(@zip_file.file.stat('dir1/').directory?)
|
235
235
|
assert(@zip_file.file.stat('dir2/dir21').directory?)
|
@@ -243,8 +243,8 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
|
|
243
243
|
end
|
244
244
|
|
245
245
|
def test_zero?
|
246
|
-
assert(
|
247
|
-
assert(
|
246
|
+
assert(!@zip_file.file.zero?('notAFile'))
|
247
|
+
assert(!@zip_file.file.zero?('file1'))
|
248
248
|
assert(@zip_file.file.zero?('dir1'))
|
249
249
|
blockCalled = false
|
250
250
|
::Zip::File.open('test/data/generated/5entry.zip') do |zf|
|
@@ -253,7 +253,7 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
|
|
253
253
|
end
|
254
254
|
assert(blockCalled)
|
255
255
|
|
256
|
-
assert(
|
256
|
+
assert(!@zip_file.file.stat('file1').zero?)
|
257
257
|
assert(@zip_file.file.stat('dir1').zero?)
|
258
258
|
blockCalled = false
|
259
259
|
::Zip::File.open('test/data/generated/5entry.zip') do |zf|
|
@@ -309,7 +309,7 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
|
|
309
309
|
end
|
310
310
|
|
311
311
|
def test_readable?
|
312
|
-
assert(
|
312
|
+
assert(!@zip_file.file.readable?('noSuchFile'))
|
313
313
|
assert(@zip_file.file.readable?('file1'))
|
314
314
|
assert(@zip_file.file.readable?('dir1'))
|
315
315
|
assert(@zip_file.file.stat('file1').readable?)
|
@@ -317,7 +317,7 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
|
|
317
317
|
end
|
318
318
|
|
319
319
|
def test_readable_real?
|
320
|
-
assert(
|
320
|
+
assert(!@zip_file.file.readable_real?('noSuchFile'))
|
321
321
|
assert(@zip_file.file.readable_real?('file1'))
|
322
322
|
assert(@zip_file.file.readable_real?('dir1'))
|
323
323
|
assert(@zip_file.file.stat('file1').readable_real?)
|
@@ -325,7 +325,7 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
|
|
325
325
|
end
|
326
326
|
|
327
327
|
def test_writable?
|
328
|
-
assert(
|
328
|
+
assert(!@zip_file.file.writable?('noSuchFile'))
|
329
329
|
assert(@zip_file.file.writable?('file1'))
|
330
330
|
assert(@zip_file.file.writable?('dir1'))
|
331
331
|
assert(@zip_file.file.stat('file1').writable?)
|
@@ -333,7 +333,7 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
|
|
333
333
|
end
|
334
334
|
|
335
335
|
def test_writable_real?
|
336
|
-
assert(
|
336
|
+
assert(!@zip_file.file.writable_real?('noSuchFile'))
|
337
337
|
assert(@zip_file.file.writable_real?('file1'))
|
338
338
|
assert(@zip_file.file.writable_real?('dir1'))
|
339
339
|
assert(@zip_file.file.stat('file1').writable_real?)
|
@@ -341,18 +341,18 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
|
|
341
341
|
end
|
342
342
|
|
343
343
|
def test_executable?
|
344
|
-
assert(
|
345
|
-
assert(
|
344
|
+
assert(!@zip_file.file.executable?('noSuchFile'))
|
345
|
+
assert(!@zip_file.file.executable?('file1'))
|
346
346
|
assert(@zip_file.file.executable?('dir1'))
|
347
|
-
assert(
|
347
|
+
assert(!@zip_file.file.stat('file1').executable?)
|
348
348
|
assert(@zip_file.file.stat('dir1').executable?)
|
349
349
|
end
|
350
350
|
|
351
351
|
def test_executable_real?
|
352
|
-
assert(
|
353
|
-
assert(
|
352
|
+
assert(!@zip_file.file.executable_real?('noSuchFile'))
|
353
|
+
assert(!@zip_file.file.executable_real?('file1'))
|
354
354
|
assert(@zip_file.file.executable_real?('dir1'))
|
355
|
-
assert(
|
355
|
+
assert(!@zip_file.file.stat('file1').executable_real?)
|
356
356
|
assert(@zip_file.file.stat('dir1').executable_real?)
|
357
357
|
end
|
358
358
|
|
@@ -455,7 +455,7 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
|
|
455
455
|
zf.glob('**/foo.txt') do |match|
|
456
456
|
results << "<#{match.class.name}: #{match}>"
|
457
457
|
end
|
458
|
-
assert(
|
458
|
+
assert(!results.empty?, 'block not run, or run out of context')
|
459
459
|
assert_equal 2, results.size
|
460
460
|
assert_operator results, :include?, '<Zip::Entry: globTest/foo.txt>'
|
461
461
|
assert_operator results, :include?, '<Zip::Entry: globTest/foo/bar/baz/foo.txt>'
|