minitar 0.9 → 0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Contributing.md +48 -47
- data/History.md +158 -127
- data/Manifest.txt +1 -0
- data/README.rdoc +1 -6
- data/Rakefile +53 -33
- data/lib/archive/tar/minitar/input.rb +18 -18
- data/lib/archive/tar/minitar/output.rb +6 -6
- data/lib/archive/tar/minitar/posix_header.rb +36 -34
- data/lib/archive/tar/minitar/reader.rb +47 -33
- data/lib/archive/tar/minitar/writer.rb +64 -35
- data/lib/archive/tar/minitar.rb +45 -44
- data/lib/archive-tar-minitar.rb +1 -1
- data/lib/minitar.rb +1 -1
- data/support/hoe/deprecated_gem.rb +64 -0
- data/test/minitest_helper.rb +7 -6
- data/test/support/tar_test_helpers.rb +45 -41
- data/test/test_tar_header.rb +30 -31
- data/test/test_tar_input.rb +31 -31
- data/test/test_tar_output.rb +12 -12
- data/test/test_tar_reader.rb +23 -23
- data/test/test_tar_writer.rb +119 -69
- metadata +70 -31
data/test/test_tar_input.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
3
|
+
require "minitar"
|
4
|
+
require "minitest_helper"
|
5
|
+
require "base64"
|
6
|
+
require "zlib"
|
7
7
|
|
8
8
|
class TestTarInput < Minitest::Test
|
9
9
|
TEST_TGZ = Base64.decode64(<<-EOS).freeze
|
@@ -19,23 +19,23 @@ UTAKRsEoGAWjYBSMglEwCkbBKBgFo2AUjIJRMApGwSgYBaNgFIwCUgAAGnyo6wAoAAA=
|
|
19
19
|
FILETIMES = Time.utc(2004).to_i
|
20
20
|
|
21
21
|
TEST_CONTENTS = {
|
22
|
-
|
23
|
-
|
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
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
34
|
-
FileUtils.mkdir_p(
|
34
|
+
FileUtils.mkdir_p("data__")
|
35
35
|
end
|
36
36
|
|
37
37
|
def teardown
|
38
|
-
FileUtils.rm_rf(
|
38
|
+
FileUtils.rm_rf("data__")
|
39
39
|
end
|
40
40
|
|
41
41
|
def test_open_no_block
|
@@ -58,7 +58,7 @@ UTAKRsEoGAWjYBSMglEwCkbBKBgFo2AUjIJRMApGwSgYBaNgFIwCUgAAGnyo6wAoAAA=
|
|
58
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(FILETIMES, entry.mtime,
|
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))
|
@@ -90,8 +90,8 @@ UTAKRsEoGAWjYBSMglEwCkbBKBgFo2AUjIJRMApGwSgYBaNgFIwCUgAAGnyo6wAoAAA=
|
|
90
90
|
Minitar::Input.open(reader) do |stream|
|
91
91
|
outer_count = 0
|
92
92
|
stream.each_with_index do |entry, i|
|
93
|
-
stream.extract_entry(
|
94
|
-
name = File.join(
|
93
|
+
stream.extract_entry("data__", entry)
|
94
|
+
name = File.join("data__", entry.name)
|
95
95
|
|
96
96
|
assert TEST_CONTENTS.key?(entry.name)
|
97
97
|
|
@@ -108,12 +108,12 @@ UTAKRsEoGAWjYBSMglEwCkbBKBgFo2AUjIJRMApGwSgYBaNgFIwCUgAAGnyo6wAoAAA=
|
|
108
108
|
|
109
109
|
if i.zero?
|
110
110
|
begin
|
111
|
-
ff = File.open(name,
|
111
|
+
ff = File.open(name, "rb")
|
112
112
|
data_reader = Zlib::GzipReader.new(ff)
|
113
113
|
Minitar::Input.open(data_reader) do |is2|
|
114
114
|
is2.each_with_index do |entry2, _j|
|
115
|
-
is2.extract_entry(
|
116
|
-
name2 = File.join(
|
115
|
+
is2.extract_entry("data__", entry2)
|
116
|
+
name2 = File.join("data__", entry2.name)
|
117
117
|
|
118
118
|
assert TEST_DATA_CONTENTS.key?(entry2.name)
|
119
119
|
|
@@ -144,18 +144,18 @@ UTAKRsEoGAWjYBSMglEwCkbBKBgFo2AUjIJRMApGwSgYBaNgFIwCUgAAGnyo6wAoAAA=
|
|
144
144
|
return if Minitar.windows?
|
145
145
|
|
146
146
|
IO.respond_to?(:write) &&
|
147
|
-
IO.write(
|
148
|
-
File.open(
|
147
|
+
IO.write("data__/file4", "") ||
|
148
|
+
File.open("data__/file4", "w") { |f| f.write "" }
|
149
149
|
|
150
|
-
File.symlink(
|
151
|
-
File.symlink(
|
150
|
+
File.symlink("data__/file4", "data__/file3")
|
151
|
+
File.symlink("data__/file4", "data__/data")
|
152
152
|
|
153
|
-
Minitar.unpack(Zlib::GzipReader.new(StringIO.new(TEST_TGZ)),
|
154
|
-
Minitar.unpack(Zlib::GzipReader.new(File.open(
|
155
|
-
|
153
|
+
Minitar.unpack(Zlib::GzipReader.new(StringIO.new(TEST_TGZ)), "data__")
|
154
|
+
Minitar.unpack(Zlib::GzipReader.new(File.open("data__/data.tar.gz", "rb")),
|
155
|
+
"data__")
|
156
156
|
|
157
|
-
refute File.symlink?(
|
158
|
-
refute File.symlink?(
|
157
|
+
refute File.symlink?("data__/file3")
|
158
|
+
refute File.symlink?("data__/data")
|
159
159
|
end
|
160
160
|
|
161
161
|
RELATIVE_DIRECTORY_TGZ = Base64.decode64 <<-EOS
|
@@ -168,7 +168,7 @@ MDUzVDAwNDY0N2VQMGCgAygtLkksAjolEcjIzMOtDqgsLQ2/J0H+gNOjYBSMglEwyAEA2LchrwAGAAA=
|
|
168
168
|
Minitar::Input.open(reader) do |stream|
|
169
169
|
stream.each do |entry|
|
170
170
|
assert_raises Archive::Tar::Minitar::SecureRelativePathError do
|
171
|
-
stream.extract_entry(
|
171
|
+
stream.extract_entry("data__", entry)
|
172
172
|
end
|
173
173
|
end
|
174
174
|
end
|
@@ -191,7 +191,7 @@ glEwCkbBKBgFo2AUjIJRMApIAQD0DyzXACgAAA==
|
|
191
191
|
reader = Zlib::GzipReader.new(StringIO.new(NON_STRICT_OCTAL_TGZ))
|
192
192
|
|
193
193
|
assert_raises(ArgumentError) do
|
194
|
-
Minitar.unpack(reader,
|
194
|
+
Minitar.unpack(reader, "data__")
|
195
195
|
end
|
196
196
|
end
|
197
197
|
|
@@ -214,12 +214,12 @@ UTAKRsEoGAWjYBSMglFACgAAuUHUvwAoAAA=
|
|
214
214
|
assert_equal(210, header.size)
|
215
215
|
|
216
216
|
reader = Zlib::GzipReader.new(StringIO.new(OCTAL_WRAPPED_BY_SPACE_TGZ))
|
217
|
-
Minitar.unpack(reader,
|
217
|
+
Minitar.unpack(reader, "data__", [])
|
218
218
|
end
|
219
219
|
|
220
220
|
def test_fsync_false
|
221
221
|
outer = 0
|
222
|
-
Minitar.unpack(Zlib::GzipReader.new(StringIO.new(TEST_TGZ)),
|
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
225
|
assert_equal(6, outer)
|
data/test/test_tar_output.rb
CHANGED
@@ -1,24 +1,24 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "minitar"
|
4
|
+
require "minitest_helper"
|
5
5
|
|
6
6
|
class TestTarOutput < Minitest::Test
|
7
|
-
NAMES = [
|
7
|
+
NAMES = ["a", "b", "c", "d" * 200]
|
8
8
|
|
9
9
|
def setup
|
10
|
-
FileUtils.mkdir_p(
|
10
|
+
FileUtils.mkdir_p("data__")
|
11
11
|
NAMES.each do |filename|
|
12
|
-
name = File.join(
|
13
|
-
File.open(name,
|
12
|
+
name = File.join("data__", filename)
|
13
|
+
File.open(name, "wb") { |f|
|
14
14
|
f.puts "#{name}: 123456789012345678901234567890"
|
15
15
|
}
|
16
16
|
end
|
17
|
-
@tarfile =
|
17
|
+
@tarfile = "data__/bla2.tar"
|
18
18
|
end
|
19
19
|
|
20
20
|
def teardown
|
21
|
-
FileUtils.rm_rf(
|
21
|
+
FileUtils.rm_rf("data__")
|
22
22
|
end
|
23
23
|
|
24
24
|
def test_open_no_block
|
@@ -31,17 +31,17 @@ class TestTarOutput < Minitest::Test
|
|
31
31
|
|
32
32
|
def test_file_looks_good
|
33
33
|
Minitar::Output.open(@tarfile) do |os|
|
34
|
-
Dir.chdir(
|
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
|
-
File.open(name,
|
39
|
+
File.open(name, "rb") { |ff| ss.write(ff.read(4096)) until ff.eof? }
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
44
|
-
ff = File.open(@tarfile,
|
44
|
+
ff = File.open(@tarfile, "rb")
|
45
45
|
Minitar::Reader.open(ff) do |is|
|
46
46
|
names_from_tar = is.map do |entry|
|
47
47
|
entry.name
|
data/test/test_tar_reader.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "minitar"
|
4
|
+
require "minitest_helper"
|
5
5
|
|
6
6
|
class TestTarReader < Minitest::Test
|
7
7
|
include Archive::Tar::Minitar::ByteSize
|
8
8
|
|
9
9
|
def test_open_no_block
|
10
|
-
str = tar_file_header(
|
11
|
-
str += tar_file_header(
|
12
|
-
str += tar_dir_header(
|
10
|
+
str = tar_file_header("lib/foo", "", 0o10644, 10) + "\0" * 512
|
11
|
+
str += tar_file_header("bar", "baz", 0o644, 0)
|
12
|
+
str += tar_dir_header("foo", "bar", 0o12345)
|
13
13
|
str += "\0" * 1024
|
14
14
|
|
15
15
|
reader = Minitar::Reader.open(StringIO.new(str))
|
@@ -20,13 +20,13 @@ class TestTarReader < Minitest::Test
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def test_multiple_entries
|
23
|
-
str = tar_file_header(
|
24
|
-
str += tar_file_header(
|
25
|
-
str += tar_dir_header(
|
26
|
-
str += tar_file_header(
|
23
|
+
str = tar_file_header("lib/foo", "", 0o10644, 10) + "\0" * 512
|
24
|
+
str += tar_file_header("bar", "baz", 0o644, 0)
|
25
|
+
str += tar_dir_header("foo", "bar", 0o12345)
|
26
|
+
str += tar_file_header("src/", "", 0o755, 0) # "file" with a trailing slash
|
27
27
|
str += "\0" * 1024
|
28
|
-
names = %w
|
29
|
-
prefixes = [
|
28
|
+
names = %w[lib/foo bar foo src/]
|
29
|
+
prefixes = ["", "baz", "bar", ""]
|
30
30
|
modes = [0o10644, 0o644, 0o12345, 0o755]
|
31
31
|
sizes = [10, 0, 0, 0]
|
32
32
|
isdir = [false, false, true, true]
|
@@ -41,7 +41,7 @@ class TestTarReader < Minitest::Test
|
|
41
41
|
assert_equal(modes[i], entry.mode)
|
42
42
|
assert_equal(isdir[i], entry.directory?)
|
43
43
|
assert_equal(isfile[i], entry.file?)
|
44
|
-
if prefixes[i] !=
|
44
|
+
if prefixes[i] != ""
|
45
45
|
assert_equal(File.join(prefixes[i], names[i]), entry.full_name)
|
46
46
|
else
|
47
47
|
assert_equal(names[i], entry.name)
|
@@ -53,8 +53,8 @@ class TestTarReader < Minitest::Test
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def test_rewind_entry_works
|
56
|
-
content = (
|
57
|
-
str = tar_file_header(
|
56
|
+
content = ("a".."z").to_a.join(" ")
|
57
|
+
str = tar_file_header("lib/foo", "", 0o10644, bytesize(content)) +
|
58
58
|
content + "\0" * (512 - bytesize(content))
|
59
59
|
str << "\0" * 1024
|
60
60
|
Minitar::Reader.new(StringIO.new(str)) do |is|
|
@@ -69,8 +69,8 @@ class TestTarReader < Minitest::Test
|
|
69
69
|
end
|
70
70
|
|
71
71
|
def test_rewind_works
|
72
|
-
content = (
|
73
|
-
str = tar_file_header(
|
72
|
+
content = ("a".."z").to_a.join(" ")
|
73
|
+
str = tar_file_header("lib/foo", "", 0o10644, bytesize(content)) +
|
74
74
|
content + "\0" * (512 - bytesize(content))
|
75
75
|
str << "\0" * 1024
|
76
76
|
Minitar::Reader.new(StringIO.new(str)) do |is|
|
@@ -87,8 +87,8 @@ class TestTarReader < Minitest::Test
|
|
87
87
|
end
|
88
88
|
|
89
89
|
def test_read_works
|
90
|
-
contents = (
|
91
|
-
str = tar_file_header(
|
90
|
+
contents = ("a".."z").inject("") { |a, e| a << e * 100 }
|
91
|
+
str = tar_file_header("lib/foo", "", 0o10644, bytesize(contents)) + contents
|
92
92
|
str += "\0" * (512 - (bytesize(str) % 512))
|
93
93
|
Minitar::Reader.new(StringIO.new(str)) do |is|
|
94
94
|
is.each_entry do |entry|
|
@@ -122,7 +122,7 @@ class TestTarReader < Minitest::Test
|
|
122
122
|
end
|
123
123
|
|
124
124
|
def test_eof_works
|
125
|
-
str = tar_file_header(
|
125
|
+
str = tar_file_header("bar", "baz", 0o644, 0)
|
126
126
|
Minitar::Reader.new(StringIO.new(str)) do |is|
|
127
127
|
is.each_entry do |entry|
|
128
128
|
assert_kind_of(Minitar::Reader::EntryStream, entry)
|
@@ -134,7 +134,7 @@ class TestTarReader < Minitest::Test
|
|
134
134
|
assert_equal(true, entry.eof?)
|
135
135
|
end
|
136
136
|
end
|
137
|
-
str = tar_dir_header(
|
137
|
+
str = tar_dir_header("foo", "bar", 0o12345)
|
138
138
|
Minitar::Reader.new(StringIO.new(str)) do |is|
|
139
139
|
is.each_entry do |entry|
|
140
140
|
assert_kind_of(Minitar::Reader::EntryStream, entry)
|
@@ -146,9 +146,9 @@ class TestTarReader < Minitest::Test
|
|
146
146
|
assert_equal(true, entry.eof?)
|
147
147
|
end
|
148
148
|
end
|
149
|
-
str = tar_dir_header(
|
150
|
-
str += tar_file_header(
|
151
|
-
str += tar_file_header(
|
149
|
+
str = tar_dir_header("foo", "bar", 0o12345)
|
150
|
+
str += tar_file_header("bar", "baz", 0o644, 0)
|
151
|
+
str += tar_file_header("bar", "baz", 0o644, 0)
|
152
152
|
Minitar::Reader.new(StringIO.new(str)) do |is|
|
153
153
|
is.each_entry do |entry|
|
154
154
|
assert_kind_of(Minitar::Reader::EntryStream, entry)
|
data/test/test_tar_writer.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "minitar"
|
4
|
+
require "minitest_helper"
|
5
5
|
|
6
6
|
class TestTarWriter < Minitest::Test
|
7
7
|
include Archive::Tar::Minitar::ByteSize
|
@@ -21,15 +21,15 @@ class TestTarWriter < Minitest::Test
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def reset
|
24
|
-
@data =
|
25
|
-
@data.force_encoding(
|
24
|
+
@data = ""
|
25
|
+
@data.force_encoding("ascii-8bit") if @data.respond_to?(:force_encoding)
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
29
|
def setup
|
30
|
-
@data =
|
30
|
+
@data = "a" * 10
|
31
31
|
@unicode = [0xc3.chr, 0xa5.chr].join * 10
|
32
|
-
@unicode.force_encoding(
|
32
|
+
@unicode.force_encoding("utf-8") if @unicode.respond_to?(:force_encoding)
|
33
33
|
@dummyos = DummyIO.new
|
34
34
|
@os = Minitar::Writer.new(@dummyos)
|
35
35
|
end
|
@@ -46,63 +46,61 @@ class TestTarWriter < Minitest::Test
|
|
46
46
|
assert writer.closed?
|
47
47
|
end
|
48
48
|
|
49
|
-
|
50
49
|
def test_add_file_simple
|
51
50
|
@dummyos.reset
|
52
51
|
|
53
52
|
Minitar::Writer.open(@dummyos) do |os|
|
54
|
-
os.add_file_simple(
|
55
|
-
f.write
|
53
|
+
os.add_file_simple("lib/foo/bar", :mode => 0o644, :size => 10) do |f|
|
54
|
+
f.write "a" * 10
|
56
55
|
end
|
57
|
-
os.add_file_simple(
|
58
|
-
f.write
|
56
|
+
os.add_file_simple("lib/bar/baz", :mode => 0o644, :size => 100) do |f|
|
57
|
+
f.write "fillme"
|
59
58
|
end
|
60
59
|
end
|
61
60
|
|
62
|
-
assert_headers_equal(tar_file_header(
|
61
|
+
assert_headers_equal(tar_file_header("lib/foo/bar", "", 0o644, 10),
|
63
62
|
@dummyos.data[0, 512])
|
64
|
-
assert_equal(
|
65
|
-
assert_headers_equal(tar_file_header(
|
63
|
+
assert_equal("a" * 10 + "\0" * 502, @dummyos.data[512, 512])
|
64
|
+
assert_headers_equal(tar_file_header("lib/bar/baz", "", 0o644, 100),
|
66
65
|
@dummyos.data[512 * 2, 512])
|
67
|
-
assert_equal(
|
66
|
+
assert_equal("fillme" + "\0" * 506, @dummyos.data[512 * 3, 512])
|
68
67
|
assert_equal("\0" * 512, @dummyos.data[512 * 4, 512])
|
69
68
|
assert_equal("\0" * 512, @dummyos.data[512 * 5, 512])
|
70
69
|
end
|
71
70
|
|
72
71
|
def test_write_operations_fail_after_closed
|
73
72
|
@dummyos.reset
|
74
|
-
@os.add_file_simple(
|
73
|
+
@os.add_file_simple("sadd", :mode => 0o644, :size => 20) { |f| }
|
75
74
|
@os.close
|
76
75
|
assert_raises(Minitar::ClosedStream) { @os.flush }
|
77
|
-
assert_raises(Minitar::ClosedStream) {
|
78
|
-
|
79
|
-
}
|
80
|
-
assert_raises(Minitar::ClosedStream) { @os.mkdir 'sdfdsf', :mode => 0o644 }
|
76
|
+
assert_raises(Minitar::ClosedStream) { @os.add_file("dfdsf", :mode => 0o644) {} }
|
77
|
+
assert_raises(Minitar::ClosedStream) { @os.mkdir "sdfdsf", :mode => 0o644 }
|
78
|
+
assert_raises(Minitar::ClosedStream) { @os.symlink "a", "b", :mode => 0o644 }
|
81
79
|
end
|
82
80
|
|
83
81
|
def test_file_name_is_split_correctly
|
84
82
|
# test insane file lengths, and: a{100}/b{155}, etc
|
85
83
|
@dummyos.reset
|
86
84
|
names = [
|
87
|
-
"#{
|
88
|
-
"#{
|
89
|
-
"/#{
|
90
|
-
"#{
|
91
|
-
"#{
|
85
|
+
"#{"a" * 155}/#{"b" * 100}",
|
86
|
+
"#{"a" * 151}/#{"qwer/" * 19}bla",
|
87
|
+
"/#{"a" * 49}/#{"b" * 50}",
|
88
|
+
"#{"a" * 49}/#{"b" * 50}x",
|
89
|
+
"#{"a" * 49}x/#{"b" * 50}"
|
92
90
|
]
|
93
91
|
o_names = [
|
94
|
-
|
95
|
-
"#{
|
96
|
-
|
97
|
-
"#{
|
98
|
-
|
92
|
+
"b" * 100,
|
93
|
+
"#{"qwer/" * 19}bla",
|
94
|
+
"b" * 50,
|
95
|
+
"#{"b" * 50}x",
|
96
|
+
"b" * 50
|
99
97
|
]
|
100
98
|
o_prefixes = [
|
101
|
-
|
102
|
-
|
103
|
-
"/#{
|
104
|
-
|
105
|
-
"#{
|
99
|
+
"a" * 155,
|
100
|
+
"a" * 151,
|
101
|
+
"/#{"a" * 49}",
|
102
|
+
"a" * 49,
|
103
|
+
"#{"a" * 49}x"
|
106
104
|
]
|
107
105
|
names.each do |name|
|
108
106
|
@os.add_file_simple(name, :mode => 0o644, :size => 10) {}
|
@@ -118,46 +116,83 @@ class TestTarWriter < Minitest::Test
|
|
118
116
|
def test_file_name_is_long
|
119
117
|
@dummyos.reset
|
120
118
|
|
121
|
-
@os.add_file_simple(File.join(
|
122
|
-
|
123
|
-
@os.add_file_simple(File.join(
|
124
|
-
|
125
|
-
@os.add_file_simple(File.join(
|
126
|
-
|
119
|
+
@os.add_file_simple(File.join("a" * 152, "b" * 10, "c" * 92),
|
120
|
+
:mode => 0o644, :size => 10) {}
|
121
|
+
@os.add_file_simple(File.join("d" * 162, "e" * 10),
|
122
|
+
:mode => 0o644, :size => 10) {}
|
123
|
+
@os.add_file_simple(File.join("f" * 10, "g" * 110),
|
124
|
+
:mode => 0o644, :size => 10) {}
|
127
125
|
# Issue #6.
|
128
|
-
@os.add_file_simple(
|
126
|
+
@os.add_file_simple("a" * 114, :mode => 0o644, :size => 10) {}
|
129
127
|
|
130
128
|
# "././@LongLink", a file name, its actual header, its data, ...
|
131
129
|
4.times do |i|
|
132
130
|
assert_equal(Minitar::PosixHeader::GNU_EXT_LONG_LINK,
|
133
|
-
|
131
|
+
@dummyos.data[4 * i * 512, 32].rstrip)
|
134
132
|
end
|
135
133
|
end
|
136
134
|
|
135
|
+
def test_add_file_simple_content_with_long_name
|
136
|
+
@dummyos.reset
|
137
|
+
|
138
|
+
long_name_file_content = "where_is_all_the_content_gone"
|
139
|
+
|
140
|
+
@os.add_file_simple("a" * 114, :mode => 0o0644, :data => long_name_file_content)
|
141
|
+
|
142
|
+
assert_equal(long_name_file_content,
|
143
|
+
@dummyos.data[3 * 512, long_name_file_content.bytesize])
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_add_file_content_with_long_name
|
147
|
+
dummyos = StringIO.new
|
148
|
+
def dummyos.method_missing(meth, *a)
|
149
|
+
string.send(meth, *a)
|
150
|
+
end
|
151
|
+
|
152
|
+
def dummyos.respond_to_missing?(meth, all)
|
153
|
+
string.respond_to?(meth, all)
|
154
|
+
end
|
155
|
+
|
156
|
+
long_name_file_content = "where_is_all_the_content_gone"
|
157
|
+
|
158
|
+
Minitar::Writer.open(dummyos) do |os|
|
159
|
+
os.add_file("a" * 114, :mode => 0o0644) do |f|
|
160
|
+
f.write(long_name_file_content)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
assert_equal(long_name_file_content,
|
165
|
+
dummyos[3 * 512, long_name_file_content.bytesize])
|
166
|
+
end
|
167
|
+
|
137
168
|
def test_add_file
|
138
169
|
dummyos = StringIO.new
|
139
|
-
def dummyos.method_missing(meth, *a)
|
170
|
+
def dummyos.method_missing(meth, *a)
|
140
171
|
string.send(meth, *a)
|
141
172
|
end
|
142
|
-
|
143
|
-
|
173
|
+
|
174
|
+
def dummyos.respond_to_missing?(meth, all)
|
175
|
+
string.respond_to?(meth, all)
|
176
|
+
end
|
177
|
+
content1 = ("a".."z").to_a.join("") # 26
|
178
|
+
content2 = ("aa".."zz").to_a.join("") # 1352
|
144
179
|
Minitar::Writer.open(dummyos) do |os|
|
145
|
-
os.add_file(
|
146
|
-
os.add_file(
|
147
|
-
os.add_file(
|
148
|
-
os.add_file(
|
180
|
+
os.add_file("lib/foo/bar", :mode => 0o644) { |f, _opts| f.write "a" * 10 }
|
181
|
+
os.add_file("lib/bar/baz", :mode => 0o644) { |f, _opts| f.write content1 }
|
182
|
+
os.add_file("lib/bar/baz", :mode => 0o644) { |f, _opts| f.write content2 }
|
183
|
+
os.add_file("lib/bar/baz", :mode => 0o644) { |_f, _opts| }
|
149
184
|
end
|
150
|
-
assert_headers_equal(tar_file_header(
|
185
|
+
assert_headers_equal(tar_file_header("lib/foo/bar", "", 0o644, 10),
|
151
186
|
dummyos[0, 512])
|
152
|
-
assert_equal(%
|
187
|
+
assert_equal(%(#{"a" * 10}#{"\0" * 502}), dummyos[512, 512])
|
153
188
|
offset = 512 * 2
|
154
|
-
[content1, content2,
|
155
|
-
assert_headers_equal(tar_file_header(
|
189
|
+
[content1, content2, ""].each do |data|
|
190
|
+
assert_headers_equal(tar_file_header("lib/bar/baz", "", 0o644,
|
156
191
|
bytesize(data)), dummyos[offset, 512])
|
157
192
|
offset += 512
|
158
|
-
until !data || data ==
|
193
|
+
until !data || data == ""
|
159
194
|
chunk = data[0, 512]
|
160
|
-
data[0, 512] =
|
195
|
+
data[0, 512] = ""
|
161
196
|
assert_equal(chunk + "\0" * (512 - bytesize(chunk)),
|
162
197
|
dummyos[offset, 512])
|
163
198
|
offset += 512
|
@@ -168,28 +203,28 @@ class TestTarWriter < Minitest::Test
|
|
168
203
|
|
169
204
|
def test_add_file_tests_seekability
|
170
205
|
assert_raises(Archive::Tar::Minitar::NonSeekableStream) do
|
171
|
-
@os.add_file(
|
206
|
+
@os.add_file("libdfdsfd", :mode => 0o644) { |f| }
|
172
207
|
end
|
173
208
|
end
|
174
209
|
|
175
210
|
def test_write_header
|
176
211
|
@dummyos.reset
|
177
|
-
@os.add_file_simple(
|
212
|
+
@os.add_file_simple("lib/foo/bar", :mode => 0o644, :size => 0) {}
|
178
213
|
@os.flush
|
179
|
-
assert_headers_equal(tar_file_header(
|
214
|
+
assert_headers_equal(tar_file_header("lib/foo/bar", "", 0o644, 0),
|
180
215
|
@dummyos.data[0, 512])
|
181
216
|
@dummyos.reset
|
182
|
-
@os.mkdir(
|
183
|
-
assert_headers_equal(tar_dir_header(
|
217
|
+
@os.mkdir("lib/foo", :mode => 0o644)
|
218
|
+
assert_headers_equal(tar_dir_header("lib/foo", "", 0o644),
|
184
219
|
@dummyos.data[0, 512])
|
185
|
-
@os.mkdir(
|
186
|
-
assert_headers_equal(tar_dir_header(
|
220
|
+
@os.mkdir("lib/bar", :mode => 0o644)
|
221
|
+
assert_headers_equal(tar_dir_header("lib/bar", "", 0o644),
|
187
222
|
@dummyos.data[512 * 1, 512])
|
188
223
|
end
|
189
224
|
|
190
225
|
def test_write_data
|
191
226
|
@dummyos.reset
|
192
|
-
@os.add_file_simple(
|
227
|
+
@os.add_file_simple("lib/foo/bar", :mode => 0o644, :size => 10) do |f|
|
193
228
|
f.write @data
|
194
229
|
end
|
195
230
|
@os.flush
|
@@ -203,10 +238,10 @@ class TestTarWriter < Minitest::Test
|
|
203
238
|
if @unicode.respond_to?(:bytesize)
|
204
239
|
assert_equal 10, @unicode.size
|
205
240
|
assert_equal 20, @unicode.bytesize
|
206
|
-
@unicode.force_encoding(
|
241
|
+
@unicode.force_encoding("ascii-8bit")
|
207
242
|
end
|
208
243
|
|
209
|
-
file = [
|
244
|
+
file = ["lib/foo/b", 0xc3.chr, 0xa5.chr, "r"].join
|
210
245
|
|
211
246
|
@os.add_file_simple(file, :mode => 0o644, :size => 20) do |f|
|
212
247
|
f.write @unicode
|
@@ -219,10 +254,25 @@ class TestTarWriter < Minitest::Test
|
|
219
254
|
def test_file_size_is_checked
|
220
255
|
@dummyos.reset
|
221
256
|
assert_raises(Minitar::Writer::WriteBoundaryOverflow) do
|
222
|
-
@os.add_file_simple(
|
223
|
-
f.write
|
257
|
+
@os.add_file_simple("lib/foo/bar", :mode => 0o644, :size => 10) do |f|
|
258
|
+
f.write "1" * 100
|
224
259
|
end
|
225
260
|
end
|
226
|
-
@os.add_file_simple(
|
261
|
+
@os.add_file_simple("lib/foo/bar", :mode => 0o644, :size => 10) { |f| }
|
262
|
+
end
|
263
|
+
|
264
|
+
def test_symlink
|
265
|
+
@dummyos.reset
|
266
|
+
@os.symlink("lib/foo/bar", "lib/foo/baz", :mode => 0o644)
|
267
|
+
@os.flush
|
268
|
+
assert_headers_equal(tar_symlink_header("lib/foo/bar", "", 0o644, "lib/foo/baz"),
|
269
|
+
@dummyos.data[0, 512])
|
270
|
+
end
|
271
|
+
|
272
|
+
def test_symlink_target_size_is_checked
|
273
|
+
@dummyos.reset
|
274
|
+
assert_raises(Minitar::FileNameTooLong) do
|
275
|
+
@os.symlink("lib/foo/bar", "x" * 101)
|
276
|
+
end
|
227
277
|
end
|
228
278
|
end
|