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/lib/archive/tar/minitar.rb
CHANGED
@@ -2,18 +2,19 @@
|
|
2
2
|
|
3
3
|
##
|
4
4
|
module Archive; end
|
5
|
+
|
5
6
|
##
|
6
7
|
module Archive::Tar; end
|
7
8
|
|
8
|
-
require
|
9
|
-
require
|
9
|
+
require "fileutils"
|
10
|
+
require "rbconfig"
|
10
11
|
|
11
|
-
class << Archive::Tar
|
12
|
-
def const_missing(const)
|
12
|
+
class << Archive::Tar # :nodoc:
|
13
|
+
def const_missing(const) # :nodoc:
|
13
14
|
case const
|
14
15
|
when :PosixHeader
|
15
|
-
warn
|
16
|
-
|
16
|
+
warn "Archive::Tar::PosixHeader has been renamed to " \
|
17
|
+
"Archive::Tar::Minitar::PosixHeader"
|
17
18
|
const_set :PosixHeader, Archive::Tar::Minitar::PosixHeader
|
18
19
|
else
|
19
20
|
super
|
@@ -29,7 +30,7 @@ class << Archive::Tar #:nodoc:
|
|
29
30
|
end
|
30
31
|
|
31
32
|
def modules
|
32
|
-
require
|
33
|
+
require "set"
|
33
34
|
@modules ||= Set.new
|
34
35
|
end
|
35
36
|
end
|
@@ -73,7 +74,7 @@ end
|
|
73
74
|
# tar.close
|
74
75
|
# end
|
75
76
|
module Archive::Tar::Minitar
|
76
|
-
VERSION =
|
77
|
+
VERSION = "0.12".freeze # :nodoc:
|
77
78
|
|
78
79
|
# The base class for any minitar error.
|
79
80
|
Error = Class.new(::StandardError)
|
@@ -99,36 +100,36 @@ module Archive::Tar::Minitar
|
|
99
100
|
# corrupted <tt>stat()</tt> call on Windows.
|
100
101
|
def dir?(path)
|
101
102
|
# rubocop:disable Style/CharacterLiteral
|
102
|
-
File.directory?(path[-1] == ?/ ? path : "#{path}/")
|
103
|
+
File.directory?((path[-1] == ?/) ? path : "#{path}/")
|
103
104
|
# rubocop:enable Style/CharacterLiteral
|
104
105
|
end
|
105
106
|
|
106
107
|
# A convenience method for wrapping Archive::Tar::Minitar::Input.open
|
107
108
|
# (mode +r+) and Archive::Tar::Minitar::Output.open (mode +w+). No other
|
108
109
|
# modes are currently supported.
|
109
|
-
def open(dest, mode =
|
110
|
+
def open(dest, mode = "r", &block)
|
110
111
|
case mode
|
111
|
-
when
|
112
|
+
when "r"
|
112
113
|
Input.open(dest, &block)
|
113
|
-
when
|
114
|
+
when "w"
|
114
115
|
Output.open(dest, &block)
|
115
116
|
else
|
116
|
-
raise
|
117
|
+
raise "Unknown open mode for Archive::Tar::Minitar.open."
|
117
118
|
end
|
118
119
|
end
|
119
120
|
|
120
|
-
def const_missing(c)
|
121
|
+
def const_missing(c) # :nodoc:
|
121
122
|
case c
|
122
123
|
when :BlockRequired
|
123
|
-
warn
|
124
|
+
warn "This constant has been removed."
|
124
125
|
const_set(:BlockRequired, Class.new(StandardError))
|
125
126
|
else
|
126
127
|
super
|
127
128
|
end
|
128
129
|
end
|
129
130
|
|
130
|
-
def windows?
|
131
|
-
RbConfig::CONFIG[
|
131
|
+
def windows? # :nodoc:
|
132
|
+
RbConfig::CONFIG["host_os"] =~ /^(mswin|mingw|cygwin)/
|
132
133
|
end
|
133
134
|
|
134
135
|
# A convenience method to pack the file provided. +entry+ may either be a
|
@@ -165,39 +166,39 @@ module Archive::Tar::Minitar
|
|
165
166
|
# <tt>:uid</tt>:: The user owner of the file. (+nil+ on Windows.)
|
166
167
|
# <tt>:gid</tt>:: The group owner of the file. (+nil+ on Windows.)
|
167
168
|
# <tt>:mtime</tt>:: The modification Time of the file.
|
168
|
-
def pack_file(entry, outputter)
|
169
|
-
if outputter.
|
169
|
+
def pack_file(entry, outputter) # :yields action, name, stats:
|
170
|
+
if outputter.is_a?(Archive::Tar::Minitar::Output)
|
170
171
|
outputter = outputter.tar
|
171
172
|
end
|
172
173
|
|
173
174
|
stats = {}
|
174
175
|
|
175
|
-
if entry.
|
176
|
+
if entry.is_a?(Hash)
|
176
177
|
name = entry[:name]
|
177
178
|
entry.each { |kk, vv| stats[kk] = vv unless vv.nil? }
|
178
179
|
else
|
179
180
|
name = entry
|
180
181
|
end
|
181
182
|
|
182
|
-
name = name.sub(%r{\./},
|
183
|
+
name = name.sub(%r{\./}, "")
|
183
184
|
stat = File.stat(name)
|
184
|
-
stats[:mode]
|
185
|
-
stats[:mtime]
|
185
|
+
stats[:mode] ||= stat.mode
|
186
|
+
stats[:mtime] ||= stat.mtime
|
186
187
|
stats[:size] = stat.size
|
187
188
|
|
188
189
|
if windows?
|
189
|
-
stats[:uid]
|
190
|
-
stats[:gid]
|
190
|
+
stats[:uid] = nil
|
191
|
+
stats[:gid] = nil
|
191
192
|
else
|
192
|
-
stats[:uid]
|
193
|
-
stats[:gid]
|
193
|
+
stats[:uid] ||= stat.uid
|
194
|
+
stats[:gid] ||= stat.gid
|
194
195
|
end
|
195
196
|
|
196
197
|
if File.file?(name)
|
197
198
|
outputter.add_file_simple(name, stats) do |os|
|
198
199
|
stats[:current] = 0
|
199
200
|
yield :file_start, name, stats if block_given?
|
200
|
-
File.open(name,
|
201
|
+
File.open(name, "rb") do |ff|
|
201
202
|
until ff.eof?
|
202
203
|
stats[:currinc] = os.write(ff.read(4096))
|
203
204
|
stats[:current] += stats[:currinc]
|
@@ -210,7 +211,7 @@ module Archive::Tar::Minitar
|
|
210
211
|
yield :dir, name, stats if block_given?
|
211
212
|
outputter.mkdir(name, stats)
|
212
213
|
else
|
213
|
-
raise
|
214
|
+
raise "Don't yet know how to pack this type of file."
|
214
215
|
end
|
215
216
|
end
|
216
217
|
|
@@ -219,14 +220,14 @@ module Archive::Tar::Minitar
|
|
219
220
|
# the resulting Archive::Tar::Minitar::Output stream; if +recurse_dirs+ is
|
220
221
|
# true, then directories will be recursed.
|
221
222
|
#
|
222
|
-
# If +src+ is an Array, it will be treated as the result of Find.find;
|
223
|
-
# files matching will be packed.
|
223
|
+
# If +src+ is not an Array, it will be treated as the result of Find.find;
|
224
|
+
# all files matching will be packed.
|
224
225
|
def pack(src, dest, recurse_dirs = true, &block)
|
225
|
-
require
|
226
|
+
require "find"
|
226
227
|
Output.open(dest) do |outp|
|
227
|
-
if src.
|
228
|
+
if src.is_a?(Array)
|
228
229
|
src.each do |entry|
|
229
|
-
if dir?(entry)
|
230
|
+
if dir?(entry) && recurse_dirs
|
230
231
|
Find.find(entry) do |ee|
|
231
232
|
pack_file(ee, outp, &block)
|
232
233
|
end
|
@@ -247,14 +248,14 @@ module Archive::Tar::Minitar
|
|
247
248
|
# will be extracted.
|
248
249
|
def unpack(src, dest, files = [], options = {}, &block)
|
249
250
|
Input.open(src) do |inp|
|
250
|
-
if File.exist?(dest)
|
251
|
-
raise
|
251
|
+
if File.exist?(dest) && !dir?(dest)
|
252
|
+
raise "Can't unpack to a non-directory."
|
252
253
|
end
|
253
254
|
|
254
255
|
FileUtils.mkdir_p(dest) unless File.exist?(dest)
|
255
256
|
|
256
257
|
inp.each do |entry|
|
257
|
-
if files.empty?
|
258
|
+
if files.empty? || files.include?(entry.full_name)
|
258
259
|
inp.extract_entry(dest, entry, options, &block)
|
259
260
|
end
|
260
261
|
end
|
@@ -269,8 +270,8 @@ module Archive::Tar::Minitar
|
|
269
270
|
io.stat.file?
|
270
271
|
else
|
271
272
|
# Duck-type the rest of this.
|
272
|
-
methods ||= [
|
273
|
-
methods = [
|
273
|
+
methods ||= [:pos, :pos=, :seek, :rewind]
|
274
|
+
methods = [methods] unless methods.is_a?(Array)
|
274
275
|
methods.all? { |m| io.respond_to?(m) }
|
275
276
|
end
|
276
277
|
end
|
@@ -284,7 +285,7 @@ module Archive::Tar::Minitar
|
|
284
285
|
end
|
285
286
|
|
286
287
|
def modules
|
287
|
-
require
|
288
|
+
require "set"
|
288
289
|
@modules ||= Set.new
|
289
290
|
end
|
290
291
|
end
|
@@ -293,7 +294,7 @@ module Archive::Tar::Minitar
|
|
293
294
|
module ByteSize # :nodoc:
|
294
295
|
private
|
295
296
|
|
296
|
-
if
|
297
|
+
if "".respond_to?(:bytesize)
|
297
298
|
def bytesize(item)
|
298
299
|
item.bytesize
|
299
300
|
end
|
@@ -305,6 +306,6 @@ module Archive::Tar::Minitar
|
|
305
306
|
end
|
306
307
|
end
|
307
308
|
|
308
|
-
require
|
309
|
-
require
|
310
|
-
require
|
309
|
+
require "archive/tar/minitar/posix_header"
|
310
|
+
require "archive/tar/minitar/input"
|
311
|
+
require "archive/tar/minitar/output"
|
data/lib/archive-tar-minitar.rb
CHANGED
data/lib/minitar.rb
CHANGED
@@ -0,0 +1,64 @@
|
|
1
|
+
# A Hoe plug-in to provide a second, linked gemspec, for a gem that has been
|
2
|
+
# deprecated in favour of a modern name. (The name is an artifact of Hoe's
|
3
|
+
# plugin loading.)
|
4
|
+
module Hoe::Deprecated_Gem # standard:disable Naming/ClassAndModuleCamelCase
|
5
|
+
def linked_spec(spec)
|
6
|
+
permitted_classes = %w[
|
7
|
+
Symbol Time Date Gem::Dependency Gem::Platform Gem::Requirement
|
8
|
+
Gem::Specification Gem::Version Gem::Version::Requirement
|
9
|
+
YAML::Syck::DefaultKey Syck::DefaultKey
|
10
|
+
]
|
11
|
+
permitted_symbols = %w[development runtime]
|
12
|
+
atm = begin
|
13
|
+
YAML.safe_load(
|
14
|
+
YAML.dump(spec),
|
15
|
+
:permitted_classes => permitted_classes,
|
16
|
+
:permitted_symbols => permitted_symbols,
|
17
|
+
:aliases => true
|
18
|
+
)
|
19
|
+
rescue
|
20
|
+
YAML.safe_load(
|
21
|
+
YAML.dump(spec), permitted_classes, permitted_symbols, true
|
22
|
+
)
|
23
|
+
end
|
24
|
+
atm.name = "archive-tar-minitar"
|
25
|
+
d = %('#{atm.name}' has been deprecated; just install '#{spec.name}'.)
|
26
|
+
atm.description = "#{d} #{spec.description}"
|
27
|
+
atm.summary = atm.post_install_message = d
|
28
|
+
atm.files.delete_if do |f|
|
29
|
+
f !~ %r{lib/archive-tar-minitar\.rb}
|
30
|
+
end
|
31
|
+
atm.extra_rdoc_files.clear
|
32
|
+
atm.rdoc_options.clear
|
33
|
+
atm.dependencies.clear
|
34
|
+
|
35
|
+
version = Gem::Version.new(spec.version.segments.first(2).join("."))
|
36
|
+
|
37
|
+
atm.add_dependency(spec.name, "~> #{version}")
|
38
|
+
atm.add_dependency(%(#{spec.name}-cli), "~> #{version}")
|
39
|
+
|
40
|
+
unless @include_all
|
41
|
+
[:signing_key, :cert_chain].each { |name|
|
42
|
+
atm.send(:"#{name}=", atm.default_value(name))
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
atm
|
47
|
+
end
|
48
|
+
|
49
|
+
def define_deprecated_gem_tasks
|
50
|
+
gemspec = spec.name + ".gemspec"
|
51
|
+
atmspec = "archive-tar-minitar.gemspec"
|
52
|
+
|
53
|
+
file atmspec => gemspec do
|
54
|
+
File.open(atmspec, "w") { |f| f.write(linked_spec(spec).to_ruby) }
|
55
|
+
end
|
56
|
+
|
57
|
+
task :gemspec => atmspec
|
58
|
+
|
59
|
+
Gem::PackageTask.new linked_spec(spec) do |pkg|
|
60
|
+
pkg.need_tar = @need_tar
|
61
|
+
pkg.need_zip = @need_zip
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/test/minitest_helper.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "fileutils"
|
4
|
+
require "minitar"
|
5
5
|
|
6
|
-
gem
|
7
|
-
require
|
6
|
+
gem "minitest"
|
7
|
+
require "minitest/autorun"
|
8
|
+
require "minitest/focus"
|
8
9
|
|
9
|
-
Dir.glob(File.join(File.dirname(__FILE__),
|
10
|
+
Dir.glob(File.join(File.dirname(__FILE__), "support/*.rb")).sort.each do |support|
|
10
11
|
require support
|
11
12
|
end
|
@@ -4,7 +4,7 @@ module TarTestHelpers
|
|
4
4
|
include Archive::Tar::Minitar::ByteSize
|
5
5
|
|
6
6
|
Field = Struct.new(:name, :offset, :length)
|
7
|
-
def self.Field(name, length)
|
7
|
+
def self.Field(name, length)
|
8
8
|
@offset ||= 0
|
9
9
|
field = Field.new(name, @offset, length)
|
10
10
|
@offset += length
|
@@ -15,38 +15,38 @@ module TarTestHelpers
|
|
15
15
|
|
16
16
|
private
|
17
17
|
|
18
|
-
FIELDS = {}
|
19
|
-
FIELD_ORDER = []
|
20
|
-
|
21
|
-
Field(
|
22
|
-
Field(
|
23
|
-
Field(
|
24
|
-
Field(
|
25
|
-
Field(
|
26
|
-
Field(
|
27
|
-
Field(
|
28
|
-
Field(
|
29
|
-
Field(
|
30
|
-
Field(
|
31
|
-
Field(
|
32
|
-
Field(
|
33
|
-
Field(
|
34
|
-
Field(
|
35
|
-
Field(
|
36
|
-
Field(
|
37
|
-
|
38
|
-
BLANK_CHECKSUM =
|
18
|
+
FIELDS = {}
|
19
|
+
FIELD_ORDER = []
|
20
|
+
|
21
|
+
Field("name", 100)
|
22
|
+
Field("mode", 8)
|
23
|
+
Field("uid", 8)
|
24
|
+
Field("gid", 8)
|
25
|
+
Field("size", 12)
|
26
|
+
Field("mtime", 12)
|
27
|
+
Field("checksum", 8)
|
28
|
+
Field("typeflag", 1)
|
29
|
+
Field("linkname", 100)
|
30
|
+
Field("magic", 6)
|
31
|
+
Field("version", 2)
|
32
|
+
Field("uname", 32)
|
33
|
+
Field("gname", 32)
|
34
|
+
Field("devmajor", 8)
|
35
|
+
Field("devminor", 8)
|
36
|
+
Field("prefix", 155)
|
37
|
+
|
38
|
+
BLANK_CHECKSUM = " " * 8
|
39
39
|
NULL_100 = "\0" * 100
|
40
|
-
USTAR = "ustar\0"
|
41
|
-
DOUBLE_ZERO =
|
40
|
+
USTAR = "ustar\0"
|
41
|
+
DOUBLE_ZERO = "00"
|
42
42
|
|
43
43
|
def assert_headers_equal(expected, actual)
|
44
44
|
FIELD_ORDER.each do |field|
|
45
|
-
message = if field ==
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
45
|
+
message = if field == "checksum"
|
46
|
+
"Header checksums are expected to match."
|
47
|
+
else
|
48
|
+
"Header field #{field} is expected to match."
|
49
|
+
end
|
50
50
|
|
51
51
|
offset = FIELDS[field].offset
|
52
52
|
length = FIELDS[field].length
|
@@ -66,40 +66,44 @@ module TarTestHelpers
|
|
66
66
|
end
|
67
67
|
|
68
68
|
def tar_file_header(fname, dname, mode, length)
|
69
|
-
update_checksum(header(
|
69
|
+
update_checksum(header("0", fname, dname, length, mode))
|
70
70
|
end
|
71
71
|
|
72
72
|
def tar_dir_header(name, prefix, mode)
|
73
|
-
update_checksum(header(
|
73
|
+
update_checksum(header("5", name, prefix, 0, mode))
|
74
74
|
end
|
75
75
|
|
76
|
-
def
|
76
|
+
def tar_symlink_header(name, prefix, mode, target)
|
77
|
+
update_checksum(header("2", name, prefix, 0, mode, target))
|
78
|
+
end
|
79
|
+
|
80
|
+
def header(type, fname, dname, length, mode, link_name = "")
|
77
81
|
raw_header(type,
|
78
82
|
asciiz(fname, 100),
|
79
83
|
asciiz(dname, 155),
|
80
84
|
z(to_oct(length, 11)),
|
81
|
-
z(to_oct(mode, 7))
|
82
|
-
|
85
|
+
z(to_oct(mode, 7)),
|
86
|
+
asciiz(link_name, 100))
|
83
87
|
end
|
84
88
|
|
85
|
-
def raw_header(type, fname, dname, length, mode)
|
89
|
+
def raw_header(type, fname, dname, length, mode, link_name = "")
|
86
90
|
arr = [
|
87
91
|
fname, mode, z(to_oct(nil, 7)), z(to_oct(nil, 7)),
|
88
92
|
length, z(to_oct(0, 11)), BLANK_CHECKSUM, type,
|
89
|
-
|
93
|
+
asciiz(link_name, 100), USTAR, DOUBLE_ZERO, asciiz("", 32), asciiz("", 32),
|
90
94
|
z(to_oct(nil, 7)), z(to_oct(nil, 7)), dname
|
91
95
|
]
|
92
96
|
|
93
|
-
h = arr.join.bytes.to_a.pack(
|
97
|
+
h = arr.join.bytes.to_a.pack("C100C8C8C8C12C12C8CC100C6C2C32C32C8C8C155")
|
94
98
|
ret = h + "\0" * (512 - bytesize(h))
|
95
99
|
assert_equal(512, bytesize(ret))
|
96
100
|
ret
|
97
101
|
end
|
98
102
|
|
99
103
|
def update_checksum(header)
|
100
|
-
header[FIELDS[
|
104
|
+
header[FIELDS["checksum"].offset, FIELDS["checksum"].length] =
|
101
105
|
# inject(:+) was introduced in which version?
|
102
|
-
sp(z(to_oct(header.unpack(
|
106
|
+
sp(z(to_oct(header.unpack("C*").inject { |a, e| a + e }, 6)))
|
103
107
|
header
|
104
108
|
end
|
105
109
|
|
@@ -116,7 +120,7 @@ module TarTestHelpers
|
|
116
120
|
end
|
117
121
|
|
118
122
|
def sp(s)
|
119
|
-
s +
|
123
|
+
s + " "
|
120
124
|
end
|
121
125
|
|
122
126
|
def z(s)
|
@@ -124,7 +128,7 @@ module TarTestHelpers
|
|
124
128
|
end
|
125
129
|
|
126
130
|
def mode_string(value)
|
127
|
-
|
131
|
+
"%04o" % (value & 0o777)
|
128
132
|
end
|
129
133
|
|
130
134
|
Minitest::Test.send(:include, self)
|
data/test/test_tar_header.rb
CHANGED
@@ -1,79 +1,79 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "minitest_helper"
|
4
4
|
|
5
5
|
class TestTarHeader < Minitest::Test
|
6
6
|
def test_arguments_are_checked
|
7
7
|
ph = Archive::Tar::Minitar::PosixHeader
|
8
8
|
assert_raises(ArgumentError) {
|
9
|
-
ph.new(:name =>
|
9
|
+
ph.new(:name => "", :size => "", :mode => "")
|
10
10
|
}
|
11
11
|
assert_raises(ArgumentError) {
|
12
|
-
ph.new(:name =>
|
12
|
+
ph.new(:name => "", :size => "", :prefix => "")
|
13
13
|
}
|
14
14
|
assert_raises(ArgumentError) {
|
15
|
-
ph.new(:name =>
|
15
|
+
ph.new(:name => "", :prefix => "", :mode => "")
|
16
16
|
}
|
17
17
|
assert_raises(ArgumentError) {
|
18
|
-
ph.new(:prefix =>
|
18
|
+
ph.new(:prefix => "", :size => "", :mode => "")
|
19
19
|
}
|
20
20
|
end
|
21
21
|
|
22
22
|
def test_basic_headers
|
23
23
|
header = {
|
24
|
-
:name =>
|
24
|
+
:name => "bla",
|
25
25
|
:mode => 0o12345,
|
26
26
|
:size => 10,
|
27
|
-
:prefix =>
|
28
|
-
:typeflag =>
|
27
|
+
:prefix => "",
|
28
|
+
:typeflag => "0"
|
29
29
|
}
|
30
|
-
assert_headers_equal(tar_file_header(
|
30
|
+
assert_headers_equal(tar_file_header("bla", "", 0o12345, 10),
|
31
31
|
Archive::Tar::Minitar::PosixHeader.new(header).to_s)
|
32
32
|
|
33
33
|
header = {
|
34
|
-
:name =>
|
34
|
+
:name => "bla",
|
35
35
|
:mode => 0o12345,
|
36
36
|
:size => 0,
|
37
|
-
:prefix =>
|
38
|
-
:typeflag =>
|
37
|
+
:prefix => "",
|
38
|
+
:typeflag => "5"
|
39
39
|
}
|
40
|
-
assert_headers_equal(tar_dir_header(
|
40
|
+
assert_headers_equal(tar_dir_header("bla", "", 0o12345),
|
41
41
|
Archive::Tar::Minitar::PosixHeader.new(header).to_s)
|
42
42
|
end
|
43
43
|
|
44
44
|
def test_long_name_works
|
45
45
|
header = {
|
46
|
-
:name =>
|
46
|
+
:name => "a" * 100, :mode => 0o12345, :size => 10, :prefix => ""
|
47
47
|
}
|
48
|
-
assert_headers_equal(tar_file_header(
|
48
|
+
assert_headers_equal(tar_file_header("a" * 100, "", 0o12345, 10),
|
49
49
|
Archive::Tar::Minitar::PosixHeader.new(header).to_s)
|
50
50
|
header = {
|
51
|
-
:name =>
|
51
|
+
:name => "a" * 100, :mode => 0o12345, :size => 10, :prefix => "bb" * 60
|
52
52
|
}
|
53
|
-
assert_headers_equal(tar_file_header(
|
53
|
+
assert_headers_equal(tar_file_header("a" * 100, "bb" * 60, 0o12345, 10),
|
54
54
|
Archive::Tar::Minitar::PosixHeader.new(header).to_s)
|
55
55
|
end
|
56
56
|
|
57
57
|
def test_from_stream
|
58
|
-
header = tar_file_header(
|
58
|
+
header = tar_file_header("a" * 100, "", 0o12345, 10)
|
59
59
|
header = StringIO.new(header)
|
60
60
|
h = Archive::Tar::Minitar::PosixHeader.from_stream(header)
|
61
|
-
assert_equal(
|
61
|
+
assert_equal("a" * 100, h.name)
|
62
62
|
assert_equal(0o12345, h.mode)
|
63
63
|
assert_equal(10, h.size)
|
64
|
-
assert_equal(
|
65
|
-
assert_equal(
|
64
|
+
assert_equal("", h.prefix)
|
65
|
+
assert_equal("ustar", h.magic)
|
66
66
|
end
|
67
67
|
|
68
68
|
def test_from_stream_with_evil_name
|
69
|
-
header = tar_file_header("a \0" + "\0" * 97,
|
69
|
+
header = tar_file_header("a \0" + "\0" * 97, "", 0o12345, 10)
|
70
70
|
header = StringIO.new(header)
|
71
71
|
h = Archive::Tar::Minitar::PosixHeader.from_stream header
|
72
|
-
assert_equal(
|
72
|
+
assert_equal("a ", h.name)
|
73
73
|
end
|
74
74
|
|
75
75
|
def test_valid_with_valid_header
|
76
|
-
header = tar_file_header(
|
76
|
+
header = tar_file_header("a" * 100, "", 0o12345, 10)
|
77
77
|
header = StringIO.new(header)
|
78
78
|
h = Archive::Tar::Minitar::PosixHeader.from_stream header
|
79
79
|
|
@@ -81,8 +81,8 @@ class TestTarHeader < Minitest::Test
|
|
81
81
|
end
|
82
82
|
|
83
83
|
def test_from_stream_with_no_strict_octal
|
84
|
-
header = tar_file_header(
|
85
|
-
io
|
84
|
+
header = tar_file_header("a" * 100, "", 0o12345, -1213)
|
85
|
+
io = StringIO.new(header)
|
86
86
|
|
87
87
|
assert_raises(ArgumentError) do
|
88
88
|
Archive::Tar::Minitar::PosixHeader.from_stream(io)
|
@@ -91,14 +91,13 @@ class TestTarHeader < Minitest::Test
|
|
91
91
|
|
92
92
|
def test_from_stream_with_octal_wrapped_by_spaces
|
93
93
|
header = raw_header(0,
|
94
|
-
asciiz(
|
95
|
-
asciiz(
|
94
|
+
asciiz("a" * 100, 100),
|
95
|
+
asciiz("", 155),
|
96
96
|
" 1213\0",
|
97
|
-
z(to_oct(0o12345, 7))
|
98
|
-
)
|
97
|
+
z(to_oct(0o12345, 7)))
|
99
98
|
|
100
99
|
header = update_checksum(header)
|
101
|
-
io
|
100
|
+
io = StringIO.new(header)
|
102
101
|
header = Archive::Tar::Minitar::PosixHeader.from_stream(io)
|
103
102
|
|
104
103
|
assert_equal(651, header.size)
|