rubyzip 1.3.0 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -8
- data/Rakefile +3 -0
- data/lib/zip.rb +4 -3
- data/lib/zip/central_directory.rb +9 -5
- data/lib/zip/constants.rb +52 -0
- data/lib/zip/crypto/decrypted_io.rb +40 -0
- data/lib/zip/crypto/traditional_encryption.rb +9 -9
- data/lib/zip/decompressor.rb +19 -1
- data/lib/zip/dos_time.rb +12 -7
- data/lib/zip/entry.rb +57 -38
- data/lib/zip/entry_set.rb +2 -0
- data/lib/zip/errors.rb +1 -0
- data/lib/zip/extra_field.rb +11 -9
- data/lib/zip/extra_field/generic.rb +10 -9
- data/lib/zip/extra_field/ntfs.rb +4 -0
- data/lib/zip/extra_field/old_unix.rb +3 -1
- data/lib/zip/extra_field/universal_time.rb +42 -12
- data/lib/zip/extra_field/unix.rb +3 -1
- data/lib/zip/extra_field/zip64.rb +4 -2
- data/lib/zip/file.rb +79 -54
- data/lib/zip/filesystem.rb +193 -177
- data/lib/zip/inflater.rb +24 -36
- data/lib/zip/input_stream.rb +33 -26
- data/lib/zip/ioextras.rb +1 -1
- data/lib/zip/ioextras/abstract_input_stream.rb +19 -8
- data/lib/zip/ioextras/abstract_output_stream.rb +1 -1
- data/lib/zip/null_decompressor.rb +1 -9
- data/lib/zip/output_stream.rb +14 -5
- data/lib/zip/pass_thru_compressor.rb +2 -2
- data/lib/zip/pass_thru_decompressor.rb +13 -22
- data/lib/zip/streamable_directory.rb +3 -3
- data/lib/zip/streamable_stream.rb +6 -10
- data/lib/zip/version.rb +1 -1
- data/samples/example.rb +2 -2
- data/samples/example_filesystem.rb +1 -1
- data/samples/gtk_ruby_zip.rb +19 -19
- data/samples/qtzip.rb +6 -6
- data/samples/write_simple.rb +2 -4
- data/samples/zipfind.rb +23 -22
- metadata +28 -169
- data/test/basic_zip_file_test.rb +0 -60
- data/test/case_sensitivity_test.rb +0 -69
- data/test/central_directory_entry_test.rb +0 -69
- data/test/central_directory_test.rb +0 -100
- data/test/crypto/null_encryption_test.rb +0 -57
- data/test/crypto/traditional_encryption_test.rb +0 -80
- data/test/data/WarnInvalidDate.zip +0 -0
- data/test/data/file1.txt +0 -46
- data/test/data/file1.txt.deflatedData +0 -0
- data/test/data/file2.txt +0 -1504
- data/test/data/globTest.zip +0 -0
- data/test/data/globTest/foo.txt +0 -0
- data/test/data/globTest/foo/bar/baz/foo.txt +0 -0
- data/test/data/globTest/food.txt +0 -0
- data/test/data/gpbit3stored.zip +0 -0
- data/test/data/mimetype +0 -1
- data/test/data/notzippedruby.rb +0 -7
- data/test/data/ntfs.zip +0 -0
- data/test/data/oddExtraField.zip +0 -0
- data/test/data/path_traversal/Makefile +0 -10
- data/test/data/path_traversal/jwilk/README.md +0 -5
- 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 +0 -3
- 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/data/rubycode2.zip +0 -0
- data/test/data/test.xls +0 -0
- data/test/data/testDirectory.bin +0 -0
- data/test/data/zip64-sample.zip +0 -0
- data/test/data/zipWithDirs.zip +0 -0
- data/test/data/zipWithEncryption.zip +0 -0
- data/test/deflater_test.rb +0 -65
- data/test/encryption_test.rb +0 -42
- data/test/entry_set_test.rb +0 -163
- data/test/entry_test.rb +0 -154
- data/test/errors_test.rb +0 -35
- data/test/extra_field_test.rb +0 -76
- data/test/file_extract_directory_test.rb +0 -54
- data/test/file_extract_test.rb +0 -145
- data/test/file_permissions_test.rb +0 -65
- data/test/file_split_test.rb +0 -57
- data/test/file_test.rb +0 -666
- data/test/filesystem/dir_iterator_test.rb +0 -58
- data/test/filesystem/directory_test.rb +0 -139
- data/test/filesystem/file_mutating_test.rb +0 -87
- data/test/filesystem/file_nonmutating_test.rb +0 -508
- data/test/filesystem/file_stat_test.rb +0 -64
- data/test/gentestfiles.rb +0 -126
- data/test/inflater_test.rb +0 -14
- data/test/input_stream_test.rb +0 -182
- data/test/ioextras/abstract_input_stream_test.rb +0 -102
- data/test/ioextras/abstract_output_stream_test.rb +0 -106
- data/test/ioextras/fake_io_test.rb +0 -18
- data/test/local_entry_test.rb +0 -154
- data/test/output_stream_test.rb +0 -128
- data/test/pass_thru_compressor_test.rb +0 -30
- data/test/pass_thru_decompressor_test.rb +0 -14
- data/test/path_traversal_test.rb +0 -141
- data/test/samples/example_recursive_test.rb +0 -37
- data/test/settings_test.rb +0 -95
- data/test/test_helper.rb +0 -234
- data/test/unicode_file_names_and_comments_test.rb +0 -62
- data/test/zip64_full_test.rb +0 -51
- data/test/zip64_support_test.rb +0 -14
@@ -1,58 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'zip/filesystem'
|
3
|
-
|
4
|
-
class ZipFsDirIteratorTest < MiniTest::Test
|
5
|
-
FILENAME_ARRAY = %w[f1 f2 f3 f4 f5 f6]
|
6
|
-
|
7
|
-
def setup
|
8
|
-
@dirIt = ::Zip::FileSystem::ZipFsDirIterator.new(FILENAME_ARRAY)
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_close
|
12
|
-
@dirIt.close
|
13
|
-
assert_raises(IOError, 'closed directory') do
|
14
|
-
@dirIt.each { |e| p e }
|
15
|
-
end
|
16
|
-
assert_raises(IOError, 'closed directory') do
|
17
|
-
@dirIt.read
|
18
|
-
end
|
19
|
-
assert_raises(IOError, 'closed directory') do
|
20
|
-
@dirIt.rewind
|
21
|
-
end
|
22
|
-
assert_raises(IOError, 'closed directory') do
|
23
|
-
@dirIt.seek(0)
|
24
|
-
end
|
25
|
-
assert_raises(IOError, 'closed directory') do
|
26
|
-
@dirIt.tell
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_each
|
31
|
-
# Tested through Enumerable.entries
|
32
|
-
assert_equal(FILENAME_ARRAY, @dirIt.entries)
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_read
|
36
|
-
FILENAME_ARRAY.size.times do |i|
|
37
|
-
assert_equal(FILENAME_ARRAY[i], @dirIt.read)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_rewind
|
42
|
-
@dirIt.read
|
43
|
-
@dirIt.read
|
44
|
-
assert_equal(FILENAME_ARRAY[2], @dirIt.read)
|
45
|
-
@dirIt.rewind
|
46
|
-
assert_equal(FILENAME_ARRAY[0], @dirIt.read)
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_tell_seek
|
50
|
-
@dirIt.read
|
51
|
-
@dirIt.read
|
52
|
-
pos = @dirIt.tell
|
53
|
-
valAtPos = @dirIt.read
|
54
|
-
@dirIt.read
|
55
|
-
@dirIt.seek(pos)
|
56
|
-
assert_equal(valAtPos, @dirIt.read)
|
57
|
-
end
|
58
|
-
end
|
@@ -1,139 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'zip/filesystem'
|
3
|
-
|
4
|
-
class ZipFsDirectoryTest < MiniTest::Test
|
5
|
-
TEST_ZIP = 'test/data/generated/zipWithDirs_copy.zip'
|
6
|
-
GLOB_TEST_ZIP = 'test/data/globTest.zip'
|
7
|
-
|
8
|
-
def setup
|
9
|
-
FileUtils.cp('test/data/zipWithDirs.zip', TEST_ZIP)
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_delete
|
13
|
-
::Zip::File.open(TEST_ZIP) do |zf|
|
14
|
-
assert_raises(Errno::ENOENT, 'No such file or directory - NoSuchFile.txt') do
|
15
|
-
zf.dir.delete('NoSuchFile.txt')
|
16
|
-
end
|
17
|
-
assert_raises(Errno::EINVAL, 'Invalid argument - file1') do
|
18
|
-
zf.dir.delete('file1')
|
19
|
-
end
|
20
|
-
assert(zf.file.exists?('dir1'))
|
21
|
-
zf.dir.delete('dir1')
|
22
|
-
assert(!zf.file.exists?('dir1'))
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_mkdir
|
27
|
-
::Zip::File.open(TEST_ZIP) do |zf|
|
28
|
-
assert_raises(Errno::EEXIST, 'File exists - dir1') do
|
29
|
-
zf.dir.mkdir('file1')
|
30
|
-
end
|
31
|
-
assert_raises(Errno::EEXIST, 'File exists - dir1') do
|
32
|
-
zf.dir.mkdir('dir1')
|
33
|
-
end
|
34
|
-
assert(!zf.file.exists?('newDir'))
|
35
|
-
zf.dir.mkdir('newDir')
|
36
|
-
assert(zf.file.directory?('newDir'))
|
37
|
-
assert(!zf.file.exists?('newDir2'))
|
38
|
-
zf.dir.mkdir('newDir2', 3485)
|
39
|
-
assert(zf.file.directory?('newDir2'))
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_pwd_chdir_entries
|
44
|
-
::Zip::File.open(TEST_ZIP) do |zf|
|
45
|
-
assert_equal('/', zf.dir.pwd)
|
46
|
-
|
47
|
-
assert_raises(Errno::ENOENT, 'No such file or directory - no such dir') do
|
48
|
-
zf.dir.chdir 'no such dir'
|
49
|
-
end
|
50
|
-
|
51
|
-
assert_raises(Errno::EINVAL, 'Invalid argument - file1') do
|
52
|
-
zf.dir.chdir 'file1'
|
53
|
-
end
|
54
|
-
|
55
|
-
assert_equal(%w[dir1 dir2 file1].sort, zf.dir.entries('.').sort)
|
56
|
-
zf.dir.chdir 'dir1'
|
57
|
-
assert_equal('/dir1', zf.dir.pwd)
|
58
|
-
assert_equal(%w[dir11 file11 file12], zf.dir.entries('.').sort)
|
59
|
-
|
60
|
-
zf.dir.chdir '../dir2/dir21'
|
61
|
-
assert_equal('/dir2/dir21', zf.dir.pwd)
|
62
|
-
assert_equal(['dir221'].sort, zf.dir.entries('.').sort)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_foreach
|
67
|
-
::Zip::File.open(TEST_ZIP) do |zf|
|
68
|
-
blockCalled = false
|
69
|
-
assert_raises(Errno::ENOENT, 'No such file or directory - noSuchDir') do
|
70
|
-
zf.dir.foreach('noSuchDir') { |_e| blockCalled = true }
|
71
|
-
end
|
72
|
-
assert(!blockCalled)
|
73
|
-
|
74
|
-
assert_raises(Errno::ENOTDIR, 'Not a directory - file1') do
|
75
|
-
zf.dir.foreach('file1') { |_e| blockCalled = true }
|
76
|
-
end
|
77
|
-
assert(!blockCalled)
|
78
|
-
|
79
|
-
entries = []
|
80
|
-
zf.dir.foreach('.') { |e| entries << e }
|
81
|
-
assert_equal(%w[dir1 dir2 file1].sort, entries.sort)
|
82
|
-
|
83
|
-
entries = []
|
84
|
-
zf.dir.foreach('dir1') { |e| entries << e }
|
85
|
-
assert_equal(%w[dir11 file11 file12], entries.sort)
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
def test_chroot
|
90
|
-
::Zip::File.open(TEST_ZIP) do |zf|
|
91
|
-
assert_raises(NotImplementedError) do
|
92
|
-
zf.dir.chroot
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
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
|
119
|
-
|
120
|
-
def test_open_new
|
121
|
-
::Zip::File.open(TEST_ZIP) do |zf|
|
122
|
-
assert_raises(Errno::ENOTDIR, 'Not a directory - file1') do
|
123
|
-
zf.dir.new('file1')
|
124
|
-
end
|
125
|
-
|
126
|
-
assert_raises(Errno::ENOENT, 'No such file or directory - noSuchFile') do
|
127
|
-
zf.dir.new('noSuchFile')
|
128
|
-
end
|
129
|
-
|
130
|
-
d = zf.dir.new('.')
|
131
|
-
assert_equal(%w[file1 dir1 dir2].sort, d.entries.sort)
|
132
|
-
d.close
|
133
|
-
|
134
|
-
zf.dir.open('dir1') do |dir|
|
135
|
-
assert_equal(%w[dir11 file11 file12].sort, dir.entries.sort)
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
@@ -1,87 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'zip/filesystem'
|
3
|
-
|
4
|
-
class ZipFsFileMutatingTest < MiniTest::Test
|
5
|
-
TEST_ZIP = 'test/data/generated/zipWithDirs_copy.zip'
|
6
|
-
def setup
|
7
|
-
FileUtils.cp('test/data/zipWithDirs.zip', TEST_ZIP)
|
8
|
-
end
|
9
|
-
|
10
|
-
def teardown; end
|
11
|
-
|
12
|
-
def test_delete
|
13
|
-
do_test_delete_or_unlink(:delete)
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_unlink
|
17
|
-
do_test_delete_or_unlink(:unlink)
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_open_write
|
21
|
-
::Zip::File.open(TEST_ZIP) do |zf|
|
22
|
-
zf.file.open('test_open_write_entry', 'w') do |f|
|
23
|
-
f.write "This is what I'm writing"
|
24
|
-
end
|
25
|
-
assert_equal("This is what I'm writing",
|
26
|
-
zf.file.read('test_open_write_entry'))
|
27
|
-
|
28
|
-
# Test with existing entry
|
29
|
-
zf.file.open('file1', 'wb') do |f| # also check that 'b' option is ignored
|
30
|
-
f.write "This is what I'm writing too"
|
31
|
-
end
|
32
|
-
assert_equal("This is what I'm writing too",
|
33
|
-
zf.file.read('file1'))
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_rename
|
38
|
-
::Zip::File.open(TEST_ZIP) do |zf|
|
39
|
-
assert_raises(Errno::ENOENT, '') do
|
40
|
-
zf.file.rename('NoSuchFile', 'bimse')
|
41
|
-
end
|
42
|
-
zf.file.rename('file1', 'newNameForFile1')
|
43
|
-
end
|
44
|
-
|
45
|
-
::Zip::File.open(TEST_ZIP) do |zf|
|
46
|
-
assert(!zf.file.exists?('file1'))
|
47
|
-
assert(zf.file.exists?('newNameForFile1'))
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_chmod
|
52
|
-
::Zip::File.open(TEST_ZIP) do |zf|
|
53
|
-
zf.file.chmod(0o765, 'file1')
|
54
|
-
end
|
55
|
-
|
56
|
-
::Zip::File.open(TEST_ZIP) do |zf|
|
57
|
-
assert_equal(0o100765, zf.file.stat('file1').mode)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def do_test_delete_or_unlink(symbol)
|
62
|
-
::Zip::File.open(TEST_ZIP) do |zf|
|
63
|
-
assert(zf.file.exists?('dir2/dir21/dir221/file2221'))
|
64
|
-
zf.file.send(symbol, 'dir2/dir21/dir221/file2221')
|
65
|
-
assert(!zf.file.exists?('dir2/dir21/dir221/file2221'))
|
66
|
-
|
67
|
-
assert(zf.file.exists?('dir1/file11'))
|
68
|
-
assert(zf.file.exists?('dir1/file12'))
|
69
|
-
zf.file.send(symbol, 'dir1/file11', 'dir1/file12')
|
70
|
-
assert(!zf.file.exists?('dir1/file11'))
|
71
|
-
assert(!zf.file.exists?('dir1/file12'))
|
72
|
-
|
73
|
-
assert_raises(Errno::ENOENT) { zf.file.send(symbol, 'noSuchFile') }
|
74
|
-
assert_raises(Errno::EISDIR) { zf.file.send(symbol, 'dir1/dir11') }
|
75
|
-
assert_raises(Errno::EISDIR) { zf.file.send(symbol, 'dir1/dir11/') }
|
76
|
-
end
|
77
|
-
|
78
|
-
::Zip::File.open(TEST_ZIP) do |zf|
|
79
|
-
assert(!zf.file.exists?('dir2/dir21/dir221/file2221'))
|
80
|
-
assert(!zf.file.exists?('dir1/file11'))
|
81
|
-
assert(!zf.file.exists?('dir1/file12'))
|
82
|
-
|
83
|
-
assert(zf.file.exists?('dir1/dir11'))
|
84
|
-
assert(zf.file.exists?('dir1/dir11/'))
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
@@ -1,508 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'zip/filesystem'
|
3
|
-
|
4
|
-
class ZipFsFileNonmutatingTest < MiniTest::Test
|
5
|
-
def setup
|
6
|
-
@zipsha = Digest::SHA1.file('test/data/zipWithDirs.zip')
|
7
|
-
@zip_file = ::Zip::File.new('test/data/zipWithDirs.zip')
|
8
|
-
end
|
9
|
-
|
10
|
-
def teardown
|
11
|
-
@zip_file.close if @zip_file
|
12
|
-
assert_equal(@zipsha, Digest::SHA1.file('test/data/zipWithDirs.zip'))
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_umask
|
16
|
-
assert_equal(::File.umask, @zip_file.file.umask)
|
17
|
-
@zip_file.file.umask(0o006)
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_exists?
|
21
|
-
assert(!@zip_file.file.exists?('notAFile'))
|
22
|
-
assert(@zip_file.file.exists?('file1'))
|
23
|
-
assert(@zip_file.file.exists?('dir1'))
|
24
|
-
assert(@zip_file.file.exists?('dir1/'))
|
25
|
-
assert(@zip_file.file.exists?('dir1/file12'))
|
26
|
-
assert(@zip_file.file.exist?('dir1/file12')) # notice, tests exist? alias of exists? !
|
27
|
-
|
28
|
-
@zip_file.dir.chdir 'dir1/'
|
29
|
-
assert(!@zip_file.file.exists?('file1'))
|
30
|
-
assert(@zip_file.file.exists?('file12'))
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_open_read
|
34
|
-
blockCalled = false
|
35
|
-
@zip_file.file.open('file1', 'r') do |f|
|
36
|
-
blockCalled = true
|
37
|
-
assert_equal("this is the entry 'file1' in my test archive!",
|
38
|
-
f.readline.chomp)
|
39
|
-
end
|
40
|
-
assert(blockCalled)
|
41
|
-
|
42
|
-
blockCalled = false
|
43
|
-
@zip_file.file.open('file1', 'rb') do |f| # test binary flag is ignored
|
44
|
-
blockCalled = true
|
45
|
-
assert_equal("this is the entry 'file1' in my test archive!",
|
46
|
-
f.readline.chomp)
|
47
|
-
end
|
48
|
-
assert(blockCalled)
|
49
|
-
|
50
|
-
blockCalled = false
|
51
|
-
@zip_file.dir.chdir 'dir2'
|
52
|
-
@zip_file.file.open('file21', 'r') do |f|
|
53
|
-
blockCalled = true
|
54
|
-
assert_equal("this is the entry 'dir2/file21' in my test archive!",
|
55
|
-
f.readline.chomp)
|
56
|
-
end
|
57
|
-
assert(blockCalled)
|
58
|
-
@zip_file.dir.chdir '/'
|
59
|
-
|
60
|
-
assert_raises(Errno::ENOENT) do
|
61
|
-
@zip_file.file.open('noSuchEntry')
|
62
|
-
end
|
63
|
-
|
64
|
-
begin
|
65
|
-
is = @zip_file.file.open('file1')
|
66
|
-
assert_equal("this is the entry 'file1' in my test archive!",
|
67
|
-
is.readline.chomp)
|
68
|
-
ensure
|
69
|
-
is.close if is
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def test_new
|
74
|
-
begin
|
75
|
-
is = @zip_file.file.new('file1')
|
76
|
-
assert_equal("this is the entry 'file1' in my test archive!",
|
77
|
-
is.readline.chomp)
|
78
|
-
ensure
|
79
|
-
is.close if is
|
80
|
-
end
|
81
|
-
begin
|
82
|
-
is = @zip_file.file.new('file1') do
|
83
|
-
fail 'should not call block'
|
84
|
-
end
|
85
|
-
ensure
|
86
|
-
is.close if is
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
def test_symlink
|
91
|
-
assert_raises(NotImplementedError) do
|
92
|
-
@zip_file.file.symlink('file1', 'aSymlink')
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
def test_size
|
97
|
-
assert_raises(Errno::ENOENT) { @zip_file.file.size('notAFile') }
|
98
|
-
assert_equal(72, @zip_file.file.size('file1'))
|
99
|
-
assert_equal(0, @zip_file.file.size('dir2/dir21'))
|
100
|
-
|
101
|
-
assert_equal(72, @zip_file.file.stat('file1').size)
|
102
|
-
assert_equal(0, @zip_file.file.stat('dir2/dir21').size)
|
103
|
-
end
|
104
|
-
|
105
|
-
def test_size?
|
106
|
-
assert_nil(@zip_file.file.size?('notAFile'))
|
107
|
-
assert_equal(72, @zip_file.file.size?('file1'))
|
108
|
-
assert_nil(@zip_file.file.size?('dir2/dir21'))
|
109
|
-
|
110
|
-
assert_equal(72, @zip_file.file.stat('file1').size?)
|
111
|
-
assert_nil(@zip_file.file.stat('dir2/dir21').size?)
|
112
|
-
end
|
113
|
-
|
114
|
-
def test_file?
|
115
|
-
assert(@zip_file.file.file?('file1'))
|
116
|
-
assert(@zip_file.file.file?('dir2/file21'))
|
117
|
-
assert(!@zip_file.file.file?('dir1'))
|
118
|
-
assert(!@zip_file.file.file?('dir1/dir11'))
|
119
|
-
|
120
|
-
assert(@zip_file.file.stat('file1').file?)
|
121
|
-
assert(@zip_file.file.stat('dir2/file21').file?)
|
122
|
-
assert(!@zip_file.file.stat('dir1').file?)
|
123
|
-
assert(!@zip_file.file.stat('dir1/dir11').file?)
|
124
|
-
end
|
125
|
-
|
126
|
-
include ExtraAssertions
|
127
|
-
|
128
|
-
def test_dirname
|
129
|
-
assert_forwarded(File, :dirname, 'retVal', 'a/b/c/d') do
|
130
|
-
@zip_file.file.dirname('a/b/c/d')
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
def test_basename
|
135
|
-
assert_forwarded(File, :basename, 'retVal', 'a/b/c/d') do
|
136
|
-
@zip_file.file.basename('a/b/c/d')
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
def test_split
|
141
|
-
assert_forwarded(File, :split, 'retVal', 'a/b/c/d') do
|
142
|
-
@zip_file.file.split('a/b/c/d')
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
def test_join
|
147
|
-
assert_equal('a/b/c', @zip_file.file.join('a/b', 'c'))
|
148
|
-
assert_equal('a/b/c/d', @zip_file.file.join('a/b', 'c/d'))
|
149
|
-
assert_equal('/c/d', @zip_file.file.join('', 'c/d'))
|
150
|
-
assert_equal('a/b/c/d', @zip_file.file.join('a', 'b', 'c', 'd'))
|
151
|
-
end
|
152
|
-
|
153
|
-
def test_utime
|
154
|
-
t_now = ::Zip::DOSTime.now
|
155
|
-
t_bak = @zip_file.file.mtime('file1')
|
156
|
-
@zip_file.file.utime(t_now, 'file1')
|
157
|
-
assert_equal(t_now, @zip_file.file.mtime('file1'))
|
158
|
-
@zip_file.file.utime(t_bak, 'file1')
|
159
|
-
assert_equal(t_bak, @zip_file.file.mtime('file1'))
|
160
|
-
end
|
161
|
-
|
162
|
-
def assert_always_false(operation)
|
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
|
-
end
|
169
|
-
|
170
|
-
def assert_true_if_entry_exists(operation)
|
171
|
-
assert(!@zip_file.file.send(operation, 'noSuchFile'))
|
172
|
-
assert(@zip_file.file.send(operation, 'file1'))
|
173
|
-
assert(@zip_file.file.send(operation, 'dir1'))
|
174
|
-
assert(@zip_file.file.stat('file1').send(operation))
|
175
|
-
assert(@zip_file.file.stat('dir1').send(operation))
|
176
|
-
end
|
177
|
-
|
178
|
-
def test_pipe?
|
179
|
-
assert_always_false(:pipe?)
|
180
|
-
end
|
181
|
-
|
182
|
-
def test_blockdev?
|
183
|
-
assert_always_false(:blockdev?)
|
184
|
-
end
|
185
|
-
|
186
|
-
def test_symlink?
|
187
|
-
assert_always_false(:symlink?)
|
188
|
-
end
|
189
|
-
|
190
|
-
def test_socket?
|
191
|
-
assert_always_false(:socket?)
|
192
|
-
end
|
193
|
-
|
194
|
-
def test_chardev?
|
195
|
-
assert_always_false(:chardev?)
|
196
|
-
end
|
197
|
-
|
198
|
-
def test_truncate
|
199
|
-
assert_raises(StandardError, 'truncate not supported') do
|
200
|
-
@zip_file.file.truncate('file1', 100)
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
def assert_e_n_o_e_n_t(operation, args = ['NoSuchFile'])
|
205
|
-
assert_raises(Errno::ENOENT) do
|
206
|
-
@zip_file.file.send(operation, *args)
|
207
|
-
end
|
208
|
-
end
|
209
|
-
|
210
|
-
def test_ftype
|
211
|
-
assert_e_n_o_e_n_t(:ftype)
|
212
|
-
assert_equal('file', @zip_file.file.ftype('file1'))
|
213
|
-
assert_equal('directory', @zip_file.file.ftype('dir1/dir11'))
|
214
|
-
assert_equal('directory', @zip_file.file.ftype('dir1/dir11/'))
|
215
|
-
end
|
216
|
-
|
217
|
-
def test_link
|
218
|
-
assert_raises(NotImplementedError) do
|
219
|
-
@zip_file.file.link('file1', 'someOtherString')
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
def test_directory?
|
224
|
-
assert(!@zip_file.file.directory?('notAFile'))
|
225
|
-
assert(!@zip_file.file.directory?('file1'))
|
226
|
-
assert(!@zip_file.file.directory?('dir1/file11'))
|
227
|
-
assert(@zip_file.file.directory?('dir1'))
|
228
|
-
assert(@zip_file.file.directory?('dir1/'))
|
229
|
-
assert(@zip_file.file.directory?('dir2/dir21'))
|
230
|
-
|
231
|
-
assert(!@zip_file.file.stat('file1').directory?)
|
232
|
-
assert(!@zip_file.file.stat('dir1/file11').directory?)
|
233
|
-
assert(@zip_file.file.stat('dir1').directory?)
|
234
|
-
assert(@zip_file.file.stat('dir1/').directory?)
|
235
|
-
assert(@zip_file.file.stat('dir2/dir21').directory?)
|
236
|
-
end
|
237
|
-
|
238
|
-
def test_chown
|
239
|
-
assert_equal(2, @zip_file.file.chown(1, 2, 'dir1', 'file1'))
|
240
|
-
assert_equal(1, @zip_file.file.stat('dir1').uid)
|
241
|
-
assert_equal(2, @zip_file.file.stat('dir1').gid)
|
242
|
-
assert_equal(2, @zip_file.file.chown(nil, nil, 'dir1', 'file1'))
|
243
|
-
end
|
244
|
-
|
245
|
-
def test_zero?
|
246
|
-
assert(!@zip_file.file.zero?('notAFile'))
|
247
|
-
assert(!@zip_file.file.zero?('file1'))
|
248
|
-
assert(@zip_file.file.zero?('dir1'))
|
249
|
-
blockCalled = false
|
250
|
-
::Zip::File.open('test/data/generated/5entry.zip') do |zf|
|
251
|
-
blockCalled = true
|
252
|
-
assert(zf.file.zero?('test/data/generated/empty.txt'))
|
253
|
-
end
|
254
|
-
assert(blockCalled)
|
255
|
-
|
256
|
-
assert(!@zip_file.file.stat('file1').zero?)
|
257
|
-
assert(@zip_file.file.stat('dir1').zero?)
|
258
|
-
blockCalled = false
|
259
|
-
::Zip::File.open('test/data/generated/5entry.zip') do |zf|
|
260
|
-
blockCalled = true
|
261
|
-
assert(zf.file.stat('test/data/generated/empty.txt').zero?)
|
262
|
-
end
|
263
|
-
assert(blockCalled)
|
264
|
-
end
|
265
|
-
|
266
|
-
def test_expand_path
|
267
|
-
::Zip::File.open('test/data/zipWithDirs.zip') do |zf|
|
268
|
-
assert_equal('/', zf.file.expand_path('.'))
|
269
|
-
zf.dir.chdir 'dir1'
|
270
|
-
assert_equal('/dir1', zf.file.expand_path('.'))
|
271
|
-
assert_equal('/dir1/file12', zf.file.expand_path('file12'))
|
272
|
-
assert_equal('/', zf.file.expand_path('..'))
|
273
|
-
assert_equal('/dir2/dir21', zf.file.expand_path('../dir2/dir21'))
|
274
|
-
end
|
275
|
-
end
|
276
|
-
|
277
|
-
def test_mtime
|
278
|
-
assert_equal(::Zip::DOSTime.at(1_027_694_306),
|
279
|
-
@zip_file.file.mtime('dir2/file21'))
|
280
|
-
assert_equal(::Zip::DOSTime.at(1_027_690_863),
|
281
|
-
@zip_file.file.mtime('dir2/dir21'))
|
282
|
-
assert_raises(Errno::ENOENT) do
|
283
|
-
@zip_file.file.mtime('noSuchEntry')
|
284
|
-
end
|
285
|
-
|
286
|
-
assert_equal(::Zip::DOSTime.at(1_027_694_306),
|
287
|
-
@zip_file.file.stat('dir2/file21').mtime)
|
288
|
-
assert_equal(::Zip::DOSTime.at(1_027_690_863),
|
289
|
-
@zip_file.file.stat('dir2/dir21').mtime)
|
290
|
-
end
|
291
|
-
|
292
|
-
def test_ctime
|
293
|
-
assert_nil(@zip_file.file.ctime('file1'))
|
294
|
-
assert_nil(@zip_file.file.stat('file1').ctime)
|
295
|
-
end
|
296
|
-
|
297
|
-
def test_atime
|
298
|
-
assert_nil(@zip_file.file.atime('file1'))
|
299
|
-
assert_nil(@zip_file.file.stat('file1').atime)
|
300
|
-
end
|
301
|
-
|
302
|
-
def test_ntfs_time
|
303
|
-
::Zip::File.open('test/data/ntfs.zip') do |zf|
|
304
|
-
t = ::Zip::DOSTime.at(1_410_496_497.405178)
|
305
|
-
assert_equal(zf.file.mtime('data.txt'), t)
|
306
|
-
assert_equal(zf.file.atime('data.txt'), t)
|
307
|
-
assert_equal(zf.file.ctime('data.txt'), t)
|
308
|
-
end
|
309
|
-
end
|
310
|
-
|
311
|
-
def test_readable?
|
312
|
-
assert(!@zip_file.file.readable?('noSuchFile'))
|
313
|
-
assert(@zip_file.file.readable?('file1'))
|
314
|
-
assert(@zip_file.file.readable?('dir1'))
|
315
|
-
assert(@zip_file.file.stat('file1').readable?)
|
316
|
-
assert(@zip_file.file.stat('dir1').readable?)
|
317
|
-
end
|
318
|
-
|
319
|
-
def test_readable_real?
|
320
|
-
assert(!@zip_file.file.readable_real?('noSuchFile'))
|
321
|
-
assert(@zip_file.file.readable_real?('file1'))
|
322
|
-
assert(@zip_file.file.readable_real?('dir1'))
|
323
|
-
assert(@zip_file.file.stat('file1').readable_real?)
|
324
|
-
assert(@zip_file.file.stat('dir1').readable_real?)
|
325
|
-
end
|
326
|
-
|
327
|
-
def test_writable?
|
328
|
-
assert(!@zip_file.file.writable?('noSuchFile'))
|
329
|
-
assert(@zip_file.file.writable?('file1'))
|
330
|
-
assert(@zip_file.file.writable?('dir1'))
|
331
|
-
assert(@zip_file.file.stat('file1').writable?)
|
332
|
-
assert(@zip_file.file.stat('dir1').writable?)
|
333
|
-
end
|
334
|
-
|
335
|
-
def test_writable_real?
|
336
|
-
assert(!@zip_file.file.writable_real?('noSuchFile'))
|
337
|
-
assert(@zip_file.file.writable_real?('file1'))
|
338
|
-
assert(@zip_file.file.writable_real?('dir1'))
|
339
|
-
assert(@zip_file.file.stat('file1').writable_real?)
|
340
|
-
assert(@zip_file.file.stat('dir1').writable_real?)
|
341
|
-
end
|
342
|
-
|
343
|
-
def test_executable?
|
344
|
-
assert(!@zip_file.file.executable?('noSuchFile'))
|
345
|
-
assert(!@zip_file.file.executable?('file1'))
|
346
|
-
assert(@zip_file.file.executable?('dir1'))
|
347
|
-
assert(!@zip_file.file.stat('file1').executable?)
|
348
|
-
assert(@zip_file.file.stat('dir1').executable?)
|
349
|
-
end
|
350
|
-
|
351
|
-
def test_executable_real?
|
352
|
-
assert(!@zip_file.file.executable_real?('noSuchFile'))
|
353
|
-
assert(!@zip_file.file.executable_real?('file1'))
|
354
|
-
assert(@zip_file.file.executable_real?('dir1'))
|
355
|
-
assert(!@zip_file.file.stat('file1').executable_real?)
|
356
|
-
assert(@zip_file.file.stat('dir1').executable_real?)
|
357
|
-
end
|
358
|
-
|
359
|
-
def test_owned?
|
360
|
-
assert_true_if_entry_exists(:owned?)
|
361
|
-
end
|
362
|
-
|
363
|
-
def test_grpowned?
|
364
|
-
assert_true_if_entry_exists(:grpowned?)
|
365
|
-
end
|
366
|
-
|
367
|
-
def test_setgid?
|
368
|
-
assert_always_false(:setgid?)
|
369
|
-
end
|
370
|
-
|
371
|
-
def test_setuid?
|
372
|
-
assert_always_false(:setgid?)
|
373
|
-
end
|
374
|
-
|
375
|
-
def test_sticky?
|
376
|
-
assert_always_false(:sticky?)
|
377
|
-
end
|
378
|
-
|
379
|
-
def test_readlink
|
380
|
-
assert_raises(NotImplementedError) do
|
381
|
-
@zip_file.file.readlink('someString')
|
382
|
-
end
|
383
|
-
end
|
384
|
-
|
385
|
-
def test_stat
|
386
|
-
s = @zip_file.file.stat('file1')
|
387
|
-
assert(s.kind_of?(File::Stat)) # It pretends
|
388
|
-
assert_raises(Errno::ENOENT, 'No such file or directory - noSuchFile') do
|
389
|
-
@zip_file.file.stat('noSuchFile')
|
390
|
-
end
|
391
|
-
end
|
392
|
-
|
393
|
-
def test_lstat
|
394
|
-
assert(@zip_file.file.lstat('file1').file?)
|
395
|
-
end
|
396
|
-
|
397
|
-
def test_pipe
|
398
|
-
assert_raises(NotImplementedError) do
|
399
|
-
@zip_file.file.pipe
|
400
|
-
end
|
401
|
-
end
|
402
|
-
|
403
|
-
def test_foreach
|
404
|
-
::Zip::File.open('test/data/generated/zipWithDir.zip') do |zf|
|
405
|
-
ref = []
|
406
|
-
File.foreach('test/data/file1.txt') { |e| ref << e }
|
407
|
-
index = 0
|
408
|
-
|
409
|
-
zf.file.foreach('test/data/file1.txt') do |l|
|
410
|
-
# Ruby replaces \n with \r\n automatically on windows
|
411
|
-
newline = Zip::RUNNING_ON_WINDOWS ? l.gsub(/\r\n/, "\n") : l
|
412
|
-
assert_equal(ref[index], newline)
|
413
|
-
index = index.next
|
414
|
-
end
|
415
|
-
assert_equal(ref.size, index)
|
416
|
-
end
|
417
|
-
|
418
|
-
::Zip::File.open('test/data/generated/zipWithDir.zip') do |zf|
|
419
|
-
ref = []
|
420
|
-
File.foreach('test/data/file1.txt', ' ') { |e| ref << e }
|
421
|
-
index = 0
|
422
|
-
|
423
|
-
zf.file.foreach('test/data/file1.txt', ' ') do |l|
|
424
|
-
# Ruby replaces \n with \r\n automatically on windows
|
425
|
-
newline = Zip::RUNNING_ON_WINDOWS ? l.gsub(/\r\n/, "\n") : l
|
426
|
-
assert_equal(ref[index], newline)
|
427
|
-
index = index.next
|
428
|
-
end
|
429
|
-
assert_equal(ref.size, index)
|
430
|
-
end
|
431
|
-
end
|
432
|
-
|
433
|
-
def test_glob
|
434
|
-
::Zip::File.open('test/data/globTest.zip') do |zf|
|
435
|
-
{
|
436
|
-
'globTest/foo.txt' => ['globTest/foo.txt'],
|
437
|
-
'*/foo.txt' => ['globTest/foo.txt'],
|
438
|
-
'**/foo.txt' => ['globTest/foo.txt', 'globTest/foo/bar/baz/foo.txt'],
|
439
|
-
'*/foo/**/*.txt' => ['globTest/foo/bar/baz/foo.txt']
|
440
|
-
}.each do |spec, expected_results|
|
441
|
-
results = zf.glob(spec)
|
442
|
-
assert results.all? { |entry| entry.is_a? ::Zip::Entry }
|
443
|
-
|
444
|
-
result_strings = results.map(&:to_s)
|
445
|
-
missing_matches = expected_results - result_strings
|
446
|
-
extra_matches = result_strings - expected_results
|
447
|
-
|
448
|
-
assert extra_matches.empty?, "spec #{spec.inspect} has extra results #{extra_matches.inspect}"
|
449
|
-
assert missing_matches.empty?, "spec #{spec.inspect} missing results #{missing_matches.inspect}"
|
450
|
-
end
|
451
|
-
end
|
452
|
-
|
453
|
-
::Zip::File.open('test/data/globTest.zip') do |zf|
|
454
|
-
results = []
|
455
|
-
zf.glob('**/foo.txt') do |match|
|
456
|
-
results << "<#{match.class.name}: #{match}>"
|
457
|
-
end
|
458
|
-
assert(!results.empty?, 'block not run, or run out of context')
|
459
|
-
assert_equal 2, results.size
|
460
|
-
assert_operator results, :include?, '<Zip::Entry: globTest/foo.txt>'
|
461
|
-
assert_operator results, :include?, '<Zip::Entry: globTest/foo/bar/baz/foo.txt>'
|
462
|
-
end
|
463
|
-
end
|
464
|
-
|
465
|
-
def test_popen
|
466
|
-
if Zip::RUNNING_ON_WINDOWS
|
467
|
-
# This is pretty much projectile vomit but it allows the test to be
|
468
|
-
# run on windows also
|
469
|
-
system_dir = ::File.popen('dir') { |f| f.read }.gsub(/Dir\(s\).*$/, '')
|
470
|
-
zipfile_dir = @zip_file.file.popen('dir') { |f| f.read }.gsub(/Dir\(s\).*$/, '')
|
471
|
-
assert_equal(system_dir, zipfile_dir)
|
472
|
-
else
|
473
|
-
assert_equal(::File.popen('ls') { |f| f.read },
|
474
|
-
@zip_file.file.popen('ls') { |f| f.read })
|
475
|
-
end
|
476
|
-
end
|
477
|
-
|
478
|
-
# Can be added later
|
479
|
-
# def test_select
|
480
|
-
# fail "implement test"
|
481
|
-
# end
|
482
|
-
|
483
|
-
def test_readlines
|
484
|
-
::Zip::File.open('test/data/generated/zipWithDir.zip') do |zf|
|
485
|
-
orig_file = ::File.readlines('test/data/file1.txt')
|
486
|
-
zip_file = zf.file.readlines('test/data/file1.txt')
|
487
|
-
|
488
|
-
# Ruby replaces \n with \r\n automatically on windows
|
489
|
-
zip_file.each { |l| l.gsub!(/\r\n/, "\n") } if Zip::RUNNING_ON_WINDOWS
|
490
|
-
|
491
|
-
assert_equal(orig_file, zip_file)
|
492
|
-
end
|
493
|
-
end
|
494
|
-
|
495
|
-
def test_read
|
496
|
-
::Zip::File.open('test/data/generated/zipWithDir.zip') do |zf|
|
497
|
-
orig_file = ::File.read('test/data/file1.txt')
|
498
|
-
|
499
|
-
# Ruby replaces \n with \r\n automatically on windows
|
500
|
-
zip_file = if Zip::RUNNING_ON_WINDOWS
|
501
|
-
zf.file.read('test/data/file1.txt').gsub(/\r\n/, "\n")
|
502
|
-
else
|
503
|
-
zf.file.read('test/data/file1.txt')
|
504
|
-
end
|
505
|
-
assert_equal(orig_file, zip_file)
|
506
|
-
end
|
507
|
-
end
|
508
|
-
end
|