minitar 0.12.1 → 1.0.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 +4 -4
- data/Code-of-Conduct.md +105 -51
- data/History.md +62 -51
- data/Licence.md +2 -2
- data/Manifest.txt +7 -8
- data/README.rdoc +1 -1
- data/Rakefile +3 -33
- data/lib/{archive/tar/minitar → minitar}/input.rb +24 -28
- data/lib/{archive/tar/minitar → minitar}/output.rb +10 -12
- data/lib/minitar/posix_header.rb +267 -0
- data/lib/{archive/tar/minitar → minitar}/reader.rb +18 -23
- data/lib/{archive/tar/minitar → minitar}/writer.rb +43 -49
- data/lib/minitar.rb +297 -9
- data/test/minitest_helper.rb +0 -2
- data/test/support/tar_test_helpers.rb +7 -8
- data/test/test_issue_46.rb +49 -0
- data/test/test_minitar.rb +60 -0
- data/test/test_tar_header.rb +34 -36
- data/test/test_tar_input.rb +55 -55
- data/test/test_tar_output.rb +3 -3
- data/test/test_tar_reader.rb +54 -56
- data/test/test_tar_writer.rb +37 -41
- metadata +40 -15
- data/lib/archive/tar/minitar/posix_header.rb +0 -278
- data/lib/archive/tar/minitar.rb +0 -311
- data/lib/archive-tar-minitar.rb +0 -3
- data/support/hoe/deprecated_gem.rb +0 -64
data/test/test_tar_input.rb
CHANGED
@@ -6,28 +6,28 @@ require "base64"
|
|
6
6
|
require "zlib"
|
7
7
|
|
8
8
|
class TestTarInput < Minitest::Test
|
9
|
-
TEST_TGZ = Base64.decode64(
|
10
|
-
H4sIAKJpllQAA0tJLEnUK0ks0kuvYqAVMDAwMDMxUQDR5mbmYNrACMIHA2MjIwUDc3NzEzMz
|
11
|
-
QxMDAwUDQ2NTczMGBQOauQgJlBYDfQ90SiKQkZmHWx1QWVoaHnMgXlGA00MEyHdzMMzOnBbC
|
12
|
-
wPz28n2uJgOR44Xrq7tsHc/utNe/9FdihkmH3pZ7+zOTRFREzkzYJ99iHHDn4n0/Wb3E8Ceq
|
13
|
-
S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BaNgFIwCUgAAGnyo6wAoAAA=
|
18
18
|
EOS
|
19
19
|
FILETIMES = Time.utc(2004).to_i
|
20
20
|
|
21
21
|
TEST_CONTENTS = {
|
22
|
-
"data.tar.gz" => {:
|
23
|
-
"file3" => {:
|
22
|
+
"data.tar.gz" => {size: 210, mode: 0o644},
|
23
|
+
"file3" => {size: 18, mode: 0o755}
|
24
24
|
}.freeze
|
25
25
|
|
26
26
|
TEST_DATA_CONTENTS = {
|
27
|
-
"data/" => {:
|
28
|
-
"data/__dir__/" => {:
|
29
|
-
"data/file1" => {:
|
30
|
-
"data/file2" => {:
|
27
|
+
"data/" => {size: 0, mode: 0o755},
|
28
|
+
"data/__dir__/" => {size: 0, mode: 0o755},
|
29
|
+
"data/file1" => {size: 16, mode: 0o644},
|
30
|
+
"data/file2" => {size: 16, mode: 0o644}
|
31
31
|
}.freeze
|
32
32
|
|
33
33
|
def setup
|
@@ -52,36 +52,36 @@ UTAKRsEoGAWjYBSMglEwCkbBKBgFo2AUjIJRMApGwSgYBaNgFIwCUgAAGnyo6wAoAAA=
|
|
52
52
|
Minitar::Input.open(reader) do |stream|
|
53
53
|
outer = 0
|
54
54
|
stream.each.with_index do |entry, i|
|
55
|
-
assert_kind_of
|
55
|
+
assert_kind_of Minitar::Reader::EntryStream, entry
|
56
56
|
assert TEST_CONTENTS.key?(entry.name)
|
57
57
|
|
58
|
-
assert_equal
|
58
|
+
assert_equal TEST_CONTENTS[entry.name][:size], entry.size, entry.name
|
59
59
|
assert_modes_equal(TEST_CONTENTS[entry.name][:mode],
|
60
60
|
entry.mode, entry.name)
|
61
|
-
assert_equal
|
61
|
+
assert_equal FILETIMES, entry.mtime, "entry.mtime"
|
62
62
|
|
63
63
|
if i.zero?
|
64
64
|
data_reader = Zlib::GzipReader.new(StringIO.new(entry.read))
|
65
65
|
Minitar::Input.open(data_reader) do |is2|
|
66
66
|
inner = 0
|
67
67
|
is2.each_with_index do |entry2, _j|
|
68
|
-
assert_kind_of
|
68
|
+
assert_kind_of Minitar::Reader::EntryStream, entry2
|
69
69
|
assert TEST_DATA_CONTENTS.key?(entry2.name)
|
70
70
|
assert_equal(TEST_DATA_CONTENTS[entry2.name][:size], entry2.size,
|
71
71
|
entry2.name)
|
72
72
|
assert_modes_equal(TEST_DATA_CONTENTS[entry2.name][:mode],
|
73
73
|
entry2.mode, entry2.name)
|
74
|
-
assert_equal
|
74
|
+
assert_equal FILETIMES, entry2.mtime, entry2.name
|
75
75
|
inner += 1
|
76
76
|
end
|
77
|
-
assert_equal
|
77
|
+
assert_equal 4, inner
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
81
|
outer += 1
|
82
82
|
end
|
83
83
|
|
84
|
-
assert_equal
|
84
|
+
assert_equal 2, outer
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
@@ -100,7 +100,7 @@ UTAKRsEoGAWjYBSMglEwCkbBKBgFo2AUjIJRMApGwSgYBaNgFIwCUgAAGnyo6wAoAAA=
|
|
100
100
|
else
|
101
101
|
assert(File.file?(name))
|
102
102
|
|
103
|
-
assert_equal
|
103
|
+
assert_equal TEST_CONTENTS[entry.name][:size], File.stat(name).size
|
104
104
|
end
|
105
105
|
|
106
106
|
assert_modes_equal(TEST_CONTENTS[entry.name][:mode],
|
@@ -136,7 +136,7 @@ UTAKRsEoGAWjYBSMglEwCkbBKBgFo2AUjIJRMApGwSgYBaNgFIwCUgAAGnyo6wAoAAA=
|
|
136
136
|
outer_count += 1
|
137
137
|
end
|
138
138
|
|
139
|
-
assert_equal
|
139
|
+
assert_equal 2, outer_count
|
140
140
|
end
|
141
141
|
end
|
142
142
|
|
@@ -145,7 +145,7 @@ UTAKRsEoGAWjYBSMglEwCkbBKBgFo2AUjIJRMApGwSgYBaNgFIwCUgAAGnyo6wAoAAA=
|
|
145
145
|
|
146
146
|
IO.respond_to?(:write) &&
|
147
147
|
IO.write("data__/file4", "") ||
|
148
|
-
File.
|
148
|
+
File.write("data__/file4", "")
|
149
149
|
|
150
150
|
File.symlink("data__/file4", "data__/file3")
|
151
151
|
File.symlink("data__/file4", "data__/data")
|
@@ -158,33 +158,33 @@ UTAKRsEoGAWjYBSMglEwCkbBKBgFo2AUjIJRMApGwSgYBaNgFIwCUgAAGnyo6wAoAAA=
|
|
158
158
|
refute File.symlink?("data__/data")
|
159
159
|
end
|
160
160
|
|
161
|
-
RELATIVE_DIRECTORY_TGZ = Base64.decode64
|
162
|
-
H4sICIIoKVgCA2JhZC1kaXIudGFyANPT0y8sTy0qqWSgHTAwMDAzMVEA0eZmpmDawAjChwEFQ2MDQyMg
|
163
|
-
MDUzVDAwNDY0N2VQMGCgAygtLkksAjolEcjIzMOtDqgsLQ2/J0H+gNOjYBSMglEwyAEA2LchrwAGAAA=
|
161
|
+
RELATIVE_DIRECTORY_TGZ = Base64.decode64 <<~EOS
|
162
|
+
H4sICIIoKVgCA2JhZC1kaXIudGFyANPT0y8sTy0qqWSgHTAwMDAzMVEA0eZmpmDawAjChwEFQ2MDQyMg
|
163
|
+
MDUzVDAwNDY0N2VQMGCgAygtLkksAjolEcjIzMOtDqgsLQ2/J0H+gNOjYBSMglEwyAEA2LchrwAGAAA=
|
164
164
|
EOS
|
165
165
|
|
166
166
|
def test_extract_entry_fails_with_relative_directory
|
167
167
|
reader = Zlib::GzipReader.new(StringIO.new(RELATIVE_DIRECTORY_TGZ))
|
168
168
|
Minitar::Input.open(reader) do |stream|
|
169
169
|
stream.each do |entry|
|
170
|
-
assert_raises
|
170
|
+
assert_raises Minitar::SecureRelativePathError do
|
171
171
|
stream.extract_entry("data__", entry)
|
172
172
|
end
|
173
173
|
end
|
174
174
|
end
|
175
175
|
end
|
176
176
|
|
177
|
-
NON_STRICT_OCTAL_TGZ = Base64.decode64(
|
178
|
-
H4sIAEk55FsAA0tJLEnUK0ks0kuvYqAVMDAwMDMxUQDR5mbmYNrACMjX0zMH
|
179
|
-
AzMDUwUDIG1iZmZoYmCgYGBobGpuxqBgQDMXIYHSYqDvgU5KBDIy83CrAypL
|
180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SMnNSjWlsByjfm5pi5n8DGDAyQsv/RiZmxqP5nx4gJCOzWAGIQOlA
|
186
|
+
wVhPgZdroF00CkbBKBgFo2AUjIJRMApGwSgYBaNgFIyCUTAKRsEoGAWjYBSM
|
187
|
+
glEwCkbBKBgFo2AUjIJRMApIAQD0DyzXACgAAA==
|
188
188
|
EOS
|
189
189
|
|
190
190
|
def test_extract_with_non_strict_octal
|
@@ -195,23 +195,23 @@ glEwCkbBKBgFo2AUjIJRMApIAQD0DyzXACgAAA==
|
|
195
195
|
end
|
196
196
|
end
|
197
197
|
|
198
|
-
OCTAL_WRAPPED_BY_SPACE_TGZ = Base64.decode64(
|
199
|
-
H4sIAOQg5FsAA0tJLEnUK0ks0kuvYqAVMDAwMDMxUQDR5mbmYNrACMhXgAJj
|
200
|
-
IyMFA3NzcxMzM0MTAwMFA0NjU3MzBgUDmrkICZQWA30PdFIikJGZh1sdUFla
|
201
|
-
Gh5zDMBAAU4PESDfzcEwO3NaCAPz28v3uZoMRI4Xrq/usnU8u9Ne/9JfiRkm
|
202
|
-
HXpb7u3PTBJRETkzYZ98i3HAnYv3/WT1EsOfqC4tOdaxMMo8ZOWXvX0tJecy
|
203
|
-
s73vrvde2qvVcvLO9Qe3Yp1mR3FmCp5/P9+73/Tsmepj72e88rpS++/e9Y1f
|
204
|
-
7a5b/rCpn/tu8n+htj+zK6ym/Pzm8f9wlu3k/VVn969ao9ly5vqlw/Of77c/
|
205
|
-
5rdktT3Tojt5dXf5p5me3X9q+/Hwz/kz/6vanN2f9I8R7o2EtXlrf/bUMGgM
|
206
|
-
YFAOSZCWmZNqTGM7QPne1BQz/xvAAEb+NzIxMx7N//QAIRmZxQpABEoHCsZ6
|
207
|
-
CrxcA+2iUTAKRsEoGAWjYBSMglEwCkbBKBgFo2AUjIJRMApGwSgYBaNgFIyC
|
208
|
-
UTAKRsEoGAWjYBSMglFACgAAuUHUvwAoAAA=
|
198
|
+
OCTAL_WRAPPED_BY_SPACE_TGZ = Base64.decode64(<<~EOS).freeze
|
199
|
+
H4sIAOQg5FsAA0tJLEnUK0ks0kuvYqAVMDAwMDMxUQDR5mbmYNrACMhXgAJj
|
200
|
+
IyMFA3NzcxMzM0MTAwMFA0NjU3MzBgUDmrkICZQWA30PdFIikJGZh1sdUFla
|
201
|
+
Gh5zDMBAAU4PESDfzcEwO3NaCAPz28v3uZoMRI4Xrq/usnU8u9Ne/9JfiRkm
|
202
|
+
HXpb7u3PTBJRETkzYZ98i3HAnYv3/WT1EsOfqC4tOdaxMMo8ZOWXvX0tJecy
|
203
|
+
s73vrvde2qvVcvLO9Qe3Yp1mR3FmCp5/P9+73/Tsmepj72e88rpS++/e9Y1f
|
204
|
+
7a5b/rCpn/tu8n+htj+zK6ym/Pzm8f9wlu3k/VVn969ao9ly5vqlw/Of77c/
|
205
|
+
5rdktT3Tojt5dXf5p5me3X9q+/Hwz/kz/6vanN2f9I8R7o2EtXlrf/bUMGgM
|
206
|
+
YFAOSZCWmZNqTGM7QPne1BQz/xvAAEb+NzIxMx7N//QAIRmZxQpABEoHCsZ6
|
207
|
+
CrxcA+2iUTAKRsEoGAWjYBSMglEwCkbBKBgFo2AUjIJRMApGwSgYBaNgFIyC
|
208
|
+
UTAKRsEoGAWjYBSMglFACgAAuUHUvwAoAAA=
|
209
209
|
EOS
|
210
210
|
|
211
211
|
def test_extract_octal_wrapped_by_space
|
212
212
|
reader = Zlib::GzipReader.new(StringIO.new(OCTAL_WRAPPED_BY_SPACE_TGZ))
|
213
|
-
header =
|
214
|
-
assert_equal
|
213
|
+
header = Minitar::PosixHeader.from_stream(reader)
|
214
|
+
assert_equal 210, header.size
|
215
215
|
|
216
216
|
reader = Zlib::GzipReader.new(StringIO.new(OCTAL_WRAPPED_BY_SPACE_TGZ))
|
217
217
|
Minitar.unpack(reader, "data__", [])
|
@@ -219,9 +219,9 @@ UTAKRsEoGAWjYBSMglFACgAAuUHUvwAoAAA=
|
|
219
219
|
|
220
220
|
def test_fsync_false
|
221
221
|
outer = 0
|
222
|
-
Minitar.unpack(Zlib::GzipReader.new(StringIO.new(TEST_TGZ)), "data__", [], :
|
222
|
+
Minitar.unpack(Zlib::GzipReader.new(StringIO.new(TEST_TGZ)), "data__", [], fsync: false) do |_label, _path, _stats|
|
223
223
|
outer += 1
|
224
224
|
end
|
225
|
-
assert_equal
|
225
|
+
assert_equal 6, outer
|
226
226
|
end
|
227
227
|
end
|
data/test/test_tar_output.rb
CHANGED
@@ -34,7 +34,7 @@ class TestTarOutput < Minitest::Test
|
|
34
34
|
Dir.chdir("data__") do
|
35
35
|
NAMES.each do |name|
|
36
36
|
stat = File.stat(name)
|
37
|
-
opts = {:
|
37
|
+
opts = {size: stat.size, mode: 0o644}
|
38
38
|
os.tar.add_file_simple(name, opts) do |ss|
|
39
39
|
File.open(name, "rb") { |ff| ss.write(ff.read(4096)) until ff.eof? }
|
40
40
|
end
|
@@ -46,9 +46,9 @@ class TestTarOutput < Minitest::Test
|
|
46
46
|
names_from_tar = is.map do |entry|
|
47
47
|
entry.name
|
48
48
|
end
|
49
|
-
assert_equal
|
49
|
+
assert_equal NAMES, names_from_tar
|
50
50
|
end
|
51
51
|
ensure
|
52
|
-
ff
|
52
|
+
ff&.close
|
53
53
|
end
|
54
54
|
end
|
data/test/test_tar_reader.rb
CHANGED
@@ -4,8 +4,6 @@ require "minitar"
|
|
4
4
|
require "minitest_helper"
|
5
5
|
|
6
6
|
class TestTarReader < Minitest::Test
|
7
|
-
include Archive::Tar::Minitar::ByteSize
|
8
|
-
|
9
7
|
def test_open_no_block
|
10
8
|
str = tar_file_header("lib/foo", "", 0o10644, 10) + "\0" * 512
|
11
9
|
str += tar_file_header("bar", "baz", 0o644, 0)
|
@@ -34,35 +32,35 @@ class TestTarReader < Minitest::Test
|
|
34
32
|
Minitar::Reader.new(StringIO.new(str)) do |is|
|
35
33
|
i = 0
|
36
34
|
is.each_entry do |entry|
|
37
|
-
assert_kind_of
|
38
|
-
assert_equal
|
39
|
-
assert_equal
|
40
|
-
assert_equal
|
41
|
-
assert_equal
|
42
|
-
assert_equal
|
43
|
-
assert_equal
|
35
|
+
assert_kind_of Minitar::Reader::EntryStream, entry
|
36
|
+
assert_equal names[i], entry.name
|
37
|
+
assert_equal prefixes[i], entry.prefix
|
38
|
+
assert_equal sizes[i], entry.size
|
39
|
+
assert_equal modes[i], entry.mode
|
40
|
+
assert_equal isdir[i], entry.directory?
|
41
|
+
assert_equal isfile[i], entry.file?
|
44
42
|
if prefixes[i] != ""
|
45
|
-
assert_equal
|
43
|
+
assert_equal File.join(prefixes[i], names[i]), entry.full_name
|
46
44
|
else
|
47
|
-
assert_equal
|
45
|
+
assert_equal names[i], entry.name
|
48
46
|
end
|
49
47
|
i += 1
|
50
48
|
end
|
51
|
-
assert_equal
|
49
|
+
assert_equal names.size, i
|
52
50
|
end
|
53
51
|
end
|
54
52
|
|
55
53
|
def test_rewind_entry_works
|
56
54
|
content = ("a".."z").to_a.join(" ")
|
57
|
-
str = tar_file_header("lib/foo", "", 0o10644, bytesize
|
58
|
-
content + "\0" * (512 - bytesize
|
55
|
+
str = tar_file_header("lib/foo", "", 0o10644, content.bytesize) +
|
56
|
+
content + "\0" * (512 - content.bytesize)
|
59
57
|
str << "\0" * 1024
|
60
58
|
Minitar::Reader.new(StringIO.new(str)) do |is|
|
61
59
|
is.each_entry do |entry|
|
62
60
|
3.times do
|
63
61
|
entry.rewind
|
64
|
-
assert_equal
|
65
|
-
assert_equal
|
62
|
+
assert_equal content, entry.read
|
63
|
+
assert_equal content.bytesize, entry.pos
|
66
64
|
end
|
67
65
|
end
|
68
66
|
end
|
@@ -70,53 +68,53 @@ class TestTarReader < Minitest::Test
|
|
70
68
|
|
71
69
|
def test_rewind_works
|
72
70
|
content = ("a".."z").to_a.join(" ")
|
73
|
-
str = tar_file_header("lib/foo", "", 0o10644, bytesize
|
74
|
-
content + "\0" * (512 - bytesize
|
71
|
+
str = tar_file_header("lib/foo", "", 0o10644, content.bytesize) +
|
72
|
+
content + "\0" * (512 - content.bytesize)
|
75
73
|
str << "\0" * 1024
|
76
74
|
Minitar::Reader.new(StringIO.new(str)) do |is|
|
77
75
|
3.times do
|
78
76
|
is.rewind
|
79
77
|
i = 0
|
80
78
|
is.each_entry do |entry|
|
81
|
-
assert_equal
|
79
|
+
assert_equal content, entry.read
|
82
80
|
i += 1
|
83
81
|
end
|
84
|
-
assert_equal
|
82
|
+
assert_equal 1, i
|
85
83
|
end
|
86
84
|
end
|
87
85
|
end
|
88
86
|
|
89
87
|
def test_read_works
|
90
88
|
contents = ("a".."z").inject("") { |a, e| a << e * 100 }
|
91
|
-
str = tar_file_header("lib/foo", "", 0o10644, bytesize
|
92
|
-
str += "\0" * (512 - (bytesize
|
89
|
+
str = tar_file_header("lib/foo", "", 0o10644, contents.bytesize) + contents
|
90
|
+
str += "\0" * (512 - (str.bytesize % 512))
|
93
91
|
Minitar::Reader.new(StringIO.new(str)) do |is|
|
94
92
|
is.each_entry do |entry|
|
95
|
-
assert_kind_of
|
96
|
-
data = entry.read(3000) # bigger than bytesize
|
97
|
-
assert_equal
|
98
|
-
|
93
|
+
assert_kind_of Minitar::Reader::EntryStream, entry
|
94
|
+
data = entry.read(3000) # bigger than contents.bytesize
|
95
|
+
assert_equal contents, data
|
96
|
+
assert entry.eof?
|
99
97
|
end
|
100
98
|
end
|
101
99
|
Minitar::Reader.new(StringIO.new(str)) do |is|
|
102
100
|
is.each_entry do |entry|
|
103
|
-
assert_kind_of
|
101
|
+
assert_kind_of Minitar::Reader::EntryStream, entry
|
104
102
|
data = entry.read(100)
|
105
|
-
(entry.size - bytesize
|
106
|
-
assert_equal
|
107
|
-
|
108
|
-
|
103
|
+
(entry.size - data.bytesize).times { data << entry.getc.chr }
|
104
|
+
assert_equal contents, data
|
105
|
+
assert_nil entry.read(10)
|
106
|
+
assert entry.eof?
|
109
107
|
end
|
110
108
|
end
|
111
109
|
Minitar::Reader.new(StringIO.new(str)) do |is|
|
112
110
|
is.each_entry do |entry|
|
113
|
-
assert_kind_of
|
111
|
+
assert_kind_of Minitar::Reader::EntryStream, entry
|
114
112
|
data = entry.read
|
115
|
-
assert_equal
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
113
|
+
assert_equal contents, data
|
114
|
+
assert_nil entry.read(10)
|
115
|
+
assert_nil entry.read
|
116
|
+
assert_nil entry.getc
|
117
|
+
assert entry.eof?
|
120
118
|
end
|
121
119
|
end
|
122
120
|
end
|
@@ -125,25 +123,25 @@ class TestTarReader < Minitest::Test
|
|
125
123
|
str = tar_file_header("bar", "baz", 0o644, 0)
|
126
124
|
Minitar::Reader.new(StringIO.new(str)) do |is|
|
127
125
|
is.each_entry do |entry|
|
128
|
-
assert_kind_of
|
126
|
+
assert_kind_of Minitar::Reader::EntryStream, entry
|
129
127
|
data = entry.read
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
128
|
+
assert_nil data
|
129
|
+
assert_nil entry.read(10)
|
130
|
+
assert_nil entry.read
|
131
|
+
assert_nil entry.getc
|
132
|
+
assert entry.eof?
|
135
133
|
end
|
136
134
|
end
|
137
135
|
str = tar_dir_header("foo", "bar", 0o12345)
|
138
136
|
Minitar::Reader.new(StringIO.new(str)) do |is|
|
139
137
|
is.each_entry do |entry|
|
140
|
-
assert_kind_of
|
138
|
+
assert_kind_of Minitar::Reader::EntryStream, entry
|
141
139
|
data = entry.read
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
140
|
+
assert_nil data
|
141
|
+
assert_nil entry.read(10)
|
142
|
+
assert_nil entry.read
|
143
|
+
assert_nil entry.getc
|
144
|
+
assert entry.eof?
|
147
145
|
end
|
148
146
|
end
|
149
147
|
str = tar_dir_header("foo", "bar", 0o12345)
|
@@ -151,19 +149,19 @@ class TestTarReader < Minitest::Test
|
|
151
149
|
str += tar_file_header("bar", "baz", 0o644, 0)
|
152
150
|
Minitar::Reader.new(StringIO.new(str)) do |is|
|
153
151
|
is.each_entry do |entry|
|
154
|
-
assert_kind_of
|
152
|
+
assert_kind_of Minitar::Reader::EntryStream, entry
|
155
153
|
data = entry.read
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
154
|
+
assert_nil data
|
155
|
+
assert_nil entry.read(10)
|
156
|
+
assert_nil entry.read
|
157
|
+
assert_nil entry.getc
|
158
|
+
assert entry.eof?
|
161
159
|
end
|
162
160
|
end
|
163
161
|
end
|
164
162
|
|
165
163
|
def test_read_invalid_tar_file
|
166
|
-
assert_raises
|
164
|
+
assert_raises Minitar::InvalidTarStream do
|
167
165
|
Minitar::Reader.open(StringIO.new("testing")) do |r|
|
168
166
|
r.each_entry do |entry|
|
169
167
|
fail "invalid tar file should not read files"
|
data/test/test_tar_writer.rb
CHANGED
@@ -4,11 +4,7 @@ require "minitar"
|
|
4
4
|
require "minitest_helper"
|
5
5
|
|
6
6
|
class TestTarWriter < Minitest::Test
|
7
|
-
include Archive::Tar::Minitar::ByteSize
|
8
|
-
|
9
7
|
class DummyIO
|
10
|
-
include Archive::Tar::Minitar::ByteSize
|
11
|
-
|
12
8
|
attr_reader :data
|
13
9
|
|
14
10
|
def initialize
|
@@ -50,32 +46,32 @@ class TestTarWriter < Minitest::Test
|
|
50
46
|
@dummyos.reset
|
51
47
|
|
52
48
|
Minitar::Writer.open(@dummyos) do |os|
|
53
|
-
os.add_file_simple("lib/foo/bar", :
|
49
|
+
os.add_file_simple("lib/foo/bar", mode: 0o644, size: 10) do |f|
|
54
50
|
f.write "a" * 10
|
55
51
|
end
|
56
|
-
os.add_file_simple("lib/bar/baz", :
|
52
|
+
os.add_file_simple("lib/bar/baz", mode: 0o644, size: 100) do |f|
|
57
53
|
f.write "fillme"
|
58
54
|
end
|
59
55
|
end
|
60
56
|
|
61
57
|
assert_headers_equal(tar_file_header("lib/foo/bar", "", 0o644, 10),
|
62
58
|
@dummyos.data[0, 512])
|
63
|
-
assert_equal
|
59
|
+
assert_equal "a" * 10 + "\0" * 502, @dummyos.data[512, 512]
|
64
60
|
assert_headers_equal(tar_file_header("lib/bar/baz", "", 0o644, 100),
|
65
61
|
@dummyos.data[512 * 2, 512])
|
66
|
-
assert_equal
|
67
|
-
assert_equal
|
68
|
-
assert_equal
|
62
|
+
assert_equal "fillme" + "\0" * 506, @dummyos.data[512 * 3, 512]
|
63
|
+
assert_equal "\0" * 512, @dummyos.data[512 * 4, 512]
|
64
|
+
assert_equal "\0" * 512, @dummyos.data[512 * 5, 512]
|
69
65
|
end
|
70
66
|
|
71
67
|
def test_write_operations_fail_after_closed
|
72
68
|
@dummyos.reset
|
73
|
-
@os.add_file_simple("sadd", :
|
69
|
+
@os.add_file_simple("sadd", mode: 0o644, size: 20) { |f| }
|
74
70
|
@os.close
|
75
71
|
assert_raises(Minitar::ClosedStream) { @os.flush }
|
76
|
-
assert_raises(Minitar::ClosedStream) { @os.add_file("dfdsf", :
|
77
|
-
assert_raises(Minitar::ClosedStream) { @os.mkdir "sdfdsf", :
|
78
|
-
assert_raises(Minitar::ClosedStream) { @os.symlink "a", "b", :
|
72
|
+
assert_raises(Minitar::ClosedStream) { @os.add_file("dfdsf", mode: 0o644) {} }
|
73
|
+
assert_raises(Minitar::ClosedStream) { @os.mkdir "sdfdsf", mode: 0o644 }
|
74
|
+
assert_raises(Minitar::ClosedStream) { @os.symlink "a", "b", mode: 0o644 }
|
79
75
|
end
|
80
76
|
|
81
77
|
def test_file_name_is_split_correctly
|
@@ -103,7 +99,7 @@ class TestTarWriter < Minitest::Test
|
|
103
99
|
"#{"a" * 49}x"
|
104
100
|
]
|
105
101
|
names.each do |name|
|
106
|
-
@os.add_file_simple(name, :
|
102
|
+
@os.add_file_simple(name, mode: 0o644, size: 10) {}
|
107
103
|
end
|
108
104
|
names.each_index do |i|
|
109
105
|
assert_headers_equal(
|
@@ -117,13 +113,13 @@ class TestTarWriter < Minitest::Test
|
|
117
113
|
@dummyos.reset
|
118
114
|
|
119
115
|
@os.add_file_simple(File.join("a" * 152, "b" * 10, "c" * 92),
|
120
|
-
:
|
116
|
+
mode: 0o644, size: 10) {}
|
121
117
|
@os.add_file_simple(File.join("d" * 162, "e" * 10),
|
122
|
-
:
|
118
|
+
mode: 0o644, size: 10) {}
|
123
119
|
@os.add_file_simple(File.join("f" * 10, "g" * 110),
|
124
|
-
:
|
120
|
+
mode: 0o644, size: 10) {}
|
125
121
|
# Issue #6.
|
126
|
-
@os.add_file_simple("a" * 114, :
|
122
|
+
@os.add_file_simple("a" * 114, mode: 0o644, size: 10) {}
|
127
123
|
|
128
124
|
# "././@LongLink", a file name, its actual header, its data, ...
|
129
125
|
4.times do |i|
|
@@ -137,7 +133,7 @@ class TestTarWriter < Minitest::Test
|
|
137
133
|
|
138
134
|
long_name_file_content = "where_is_all_the_content_gone"
|
139
135
|
|
140
|
-
@os.add_file_simple("a" * 114, :
|
136
|
+
@os.add_file_simple("a" * 114, mode: 0o0644, data: long_name_file_content)
|
141
137
|
|
142
138
|
assert_equal(long_name_file_content,
|
143
139
|
@dummyos.data[3 * 512, long_name_file_content.bytesize])
|
@@ -156,7 +152,7 @@ class TestTarWriter < Minitest::Test
|
|
156
152
|
long_name_file_content = "where_is_all_the_content_gone"
|
157
153
|
|
158
154
|
Minitar::Writer.open(dummyos) do |os|
|
159
|
-
os.add_file("a" * 114, :
|
155
|
+
os.add_file("a" * 114, mode: 0o0644) do |f|
|
160
156
|
f.write(long_name_file_content)
|
161
157
|
end
|
162
158
|
end
|
@@ -177,58 +173,58 @@ class TestTarWriter < Minitest::Test
|
|
177
173
|
content1 = ("a".."z").to_a.join("") # 26
|
178
174
|
content2 = ("aa".."zz").to_a.join("") # 1352
|
179
175
|
Minitar::Writer.open(dummyos) do |os|
|
180
|
-
os.add_file("lib/foo/bar", :
|
181
|
-
os.add_file("lib/bar/baz", :
|
182
|
-
os.add_file("lib/bar/baz", :
|
183
|
-
os.add_file("lib/bar/baz", :
|
176
|
+
os.add_file("lib/foo/bar", mode: 0o644) { |f, _opts| f.write "a" * 10 }
|
177
|
+
os.add_file("lib/bar/baz", mode: 0o644) { |f, _opts| f.write content1 }
|
178
|
+
os.add_file("lib/bar/baz", mode: 0o644) { |f, _opts| f.write content2 }
|
179
|
+
os.add_file("lib/bar/baz", mode: 0o644) { |_f, _opts| }
|
184
180
|
end
|
185
181
|
assert_headers_equal(tar_file_header("lib/foo/bar", "", 0o644, 10),
|
186
182
|
dummyos[0, 512])
|
187
|
-
assert_equal
|
183
|
+
assert_equal %(#{"a" * 10}#{"\0" * 502}), dummyos[512, 512]
|
188
184
|
offset = 512 * 2
|
189
185
|
[content1, content2, ""].each do |data|
|
190
186
|
assert_headers_equal(tar_file_header("lib/bar/baz", "", 0o644,
|
191
|
-
bytesize
|
187
|
+
data.bytesize), dummyos[offset, 512])
|
192
188
|
offset += 512
|
193
189
|
until !data || data == ""
|
194
190
|
chunk = data[0, 512]
|
195
191
|
data[0, 512] = ""
|
196
|
-
assert_equal(chunk + "\0" * (512 - bytesize
|
192
|
+
assert_equal(chunk + "\0" * (512 - chunk.bytesize),
|
197
193
|
dummyos[offset, 512])
|
198
194
|
offset += 512
|
199
195
|
end
|
200
196
|
end
|
201
|
-
assert_equal
|
197
|
+
assert_equal "\0" * 1024, dummyos[offset, 1024]
|
202
198
|
end
|
203
199
|
|
204
200
|
def test_add_file_tests_seekability
|
205
|
-
assert_raises(
|
206
|
-
@os.add_file("libdfdsfd", :
|
201
|
+
assert_raises(Minitar::NonSeekableStream) do
|
202
|
+
@os.add_file("libdfdsfd", mode: 0o644) { |f| }
|
207
203
|
end
|
208
204
|
end
|
209
205
|
|
210
206
|
def test_write_header
|
211
207
|
@dummyos.reset
|
212
|
-
@os.add_file_simple("lib/foo/bar", :
|
208
|
+
@os.add_file_simple("lib/foo/bar", mode: 0o644, size: 0) {}
|
213
209
|
@os.flush
|
214
210
|
assert_headers_equal(tar_file_header("lib/foo/bar", "", 0o644, 0),
|
215
211
|
@dummyos.data[0, 512])
|
216
212
|
@dummyos.reset
|
217
|
-
@os.mkdir("lib/foo", :
|
213
|
+
@os.mkdir("lib/foo", mode: 0o644)
|
218
214
|
assert_headers_equal(tar_dir_header("lib/foo", "", 0o644),
|
219
215
|
@dummyos.data[0, 512])
|
220
|
-
@os.mkdir("lib/bar", :
|
216
|
+
@os.mkdir("lib/bar", mode: 0o644)
|
221
217
|
assert_headers_equal(tar_dir_header("lib/bar", "", 0o644),
|
222
218
|
@dummyos.data[512 * 1, 512])
|
223
219
|
end
|
224
220
|
|
225
221
|
def test_write_data
|
226
222
|
@dummyos.reset
|
227
|
-
@os.add_file_simple("lib/foo/bar", :
|
223
|
+
@os.add_file_simple("lib/foo/bar", mode: 0o644, size: 10) do |f|
|
228
224
|
f.write @data
|
229
225
|
end
|
230
226
|
@os.flush
|
231
|
-
assert_equal(@data + ("\0" * (512 -
|
227
|
+
assert_equal(@data + ("\0" * (512 - @data.bytesize)),
|
232
228
|
@dummyos.data[512, 512])
|
233
229
|
end
|
234
230
|
|
@@ -243,27 +239,27 @@ class TestTarWriter < Minitest::Test
|
|
243
239
|
|
244
240
|
file = ["lib/foo/b", 0xc3.chr, 0xa5.chr, "r"].join
|
245
241
|
|
246
|
-
@os.add_file_simple(file, :
|
242
|
+
@os.add_file_simple(file, mode: 0o644, size: 20) do |f|
|
247
243
|
f.write @unicode
|
248
244
|
end
|
249
245
|
@os.flush
|
250
|
-
assert_equal(@unicode + ("\0" * (512 -
|
246
|
+
assert_equal(@unicode + ("\0" * (512 - @unicode.bytesize)),
|
251
247
|
@dummyos.data[512, 512])
|
252
248
|
end
|
253
249
|
|
254
250
|
def test_file_size_is_checked
|
255
251
|
@dummyos.reset
|
256
252
|
assert_raises(Minitar::Writer::WriteBoundaryOverflow) do
|
257
|
-
@os.add_file_simple("lib/foo/bar", :
|
253
|
+
@os.add_file_simple("lib/foo/bar", mode: 0o644, size: 10) do |f|
|
258
254
|
f.write "1" * 100
|
259
255
|
end
|
260
256
|
end
|
261
|
-
@os.add_file_simple("lib/foo/bar", :
|
257
|
+
@os.add_file_simple("lib/foo/bar", mode: 0o644, size: 10) { |f| }
|
262
258
|
end
|
263
259
|
|
264
260
|
def test_symlink
|
265
261
|
@dummyos.reset
|
266
|
-
@os.symlink("lib/foo/bar", "lib/foo/baz", :
|
262
|
+
@os.symlink("lib/foo/bar", "lib/foo/baz", mode: 0o644)
|
267
263
|
@os.flush
|
268
264
|
assert_headers_equal(tar_symlink_header("lib/foo/bar", "", 0o644, "lib/foo/baz"),
|
269
265
|
@dummyos.data[0, 512])
|