minitar 1.0.2 → 1.1.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/CHANGELOG.md +285 -0
- data/CONTRIBUTING.md +273 -0
- data/CONTRIBUTORS.md +27 -0
- data/LICENCE.md +39 -0
- data/Manifest.txt +29 -6
- data/README.md +70 -0
- data/Rakefile +74 -19
- data/SECURITY.md +64 -0
- data/docs/ruby.txt +3 -3
- data/lib/minitar/input.rb +69 -56
- data/lib/minitar/output.rb +34 -22
- data/lib/minitar/pax_header.rb +111 -0
- data/lib/minitar/posix_header.rb +96 -57
- data/lib/minitar/reader.rb +65 -70
- data/lib/minitar/version.rb +5 -0
- data/lib/minitar/writer.rb +50 -88
- data/lib/minitar.rb +60 -64
- data/licenses/bsdl.txt +20 -0
- data/licenses/dco.txt +34 -0
- data/licenses/ruby.txt +52 -0
- data/test/fixtures/issue_46.tar.gz +0 -0
- data/test/fixtures/issue_62.tar.gz +0 -0
- data/test/fixtures/tar_input.tgz +0 -0
- data/test/fixtures/test_input_non_strict_octal.tgz +0 -0
- data/test/fixtures/test_input_relative.tgz +0 -0
- data/test/fixtures/test_input_space_octal.tgz +0 -0
- data/test/fixtures/test_minitar.tar.gz +0 -0
- data/test/minitest_helper.rb +12 -1
- data/test/support/minitar_test_helpers/fixtures.rb +38 -0
- data/test/support/minitar_test_helpers/header.rb +130 -0
- data/test/support/minitar_test_helpers/tarball.rb +324 -0
- data/test/support/minitar_test_helpers.rb +36 -0
- data/test/test_filename_boundary_conditions.rb +74 -0
- data/test/test_gnu_tar_compatibility.rb +92 -0
- data/test/test_integration_pack_unpack_cycle.rb +38 -0
- data/test/test_issue_46.rb +5 -23
- data/test/test_issue_62.rb +50 -0
- data/test/test_minitar.rb +168 -39
- data/test/test_pax_header.rb +104 -0
- data/test/test_pax_support.rb +66 -0
- data/test/test_tar_header.rb +289 -75
- data/test/test_tar_input.rb +14 -61
- data/test/test_tar_output.rb +7 -9
- data/test/test_tar_reader.rb +17 -18
- data/test/test_tar_writer.rb +105 -126
- metadata +95 -89
- data/Contributing.md +0 -94
- data/History.md +0 -236
- data/Licence.md +0 -15
- data/README.rdoc +0 -92
- data/test/support/tar_test_helpers.rb +0 -134
- /data/{Code-of-Conduct.md → CODE_OF_CONDUCT.md} +0 -0
data/lib/minitar/writer.rb
CHANGED
@@ -1,40 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Minitar
|
2
4
|
# The class that writes a tar format archive to a data stream.
|
3
5
|
class Writer
|
4
|
-
# The exception raised when the user attempts to write more data to
|
5
|
-
# BoundedWriteStream than has been allocated.
|
6
|
+
# The exception raised when the user attempts to write more data to
|
7
|
+
# a BoundedWriteStream than has been allocated.
|
6
8
|
WriteBoundaryOverflow = Class.new(StandardError)
|
7
9
|
|
8
|
-
# A stream wrapper that can only be written to. Any attempt to read
|
9
|
-
#
|
10
|
+
# A stream wrapper that can only be written to. Any attempt to read from this
|
11
|
+
# restricted stream will result in a NameError being thrown.
|
10
12
|
class WriteOnlyStream
|
11
13
|
def initialize(io)
|
12
14
|
@io = io
|
13
15
|
end
|
14
16
|
|
15
|
-
def write(data)
|
16
|
-
@io.write(data)
|
17
|
-
end
|
17
|
+
def write(data) = @io.write(data)
|
18
18
|
end
|
19
19
|
|
20
|
-
private_constant :WriteOnlyStream
|
20
|
+
private_constant :WriteOnlyStream
|
21
21
|
|
22
22
|
# A WriteOnlyStream that also has a size limit.
|
23
23
|
class BoundedWriteStream < WriteOnlyStream
|
24
|
-
|
25
|
-
case c
|
26
|
-
when :FileOverflow
|
27
|
-
warn "Writer::BoundedWriteStream::FileOverflow has been renamed " \
|
28
|
-
"to Writer::WriteBoundaryOverflow"
|
29
|
-
const_set :FileOverflow,
|
30
|
-
Minitar::Writer::WriteBoundaryOverflow
|
31
|
-
else
|
32
|
-
super
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
# The maximum number of bytes that may be written to this data
|
37
|
-
# stream.
|
24
|
+
# The maximum number of bytes that may be written to this data stream.
|
38
25
|
attr_reader :limit
|
39
26
|
# The current total number of bytes written to this data stream.
|
40
27
|
attr_reader :written
|
@@ -54,25 +41,14 @@ class Minitar
|
|
54
41
|
end
|
55
42
|
end
|
56
43
|
|
57
|
-
private_constant :BoundedWriteStream
|
58
|
-
|
59
|
-
def self.const_missing(c)
|
60
|
-
case c
|
61
|
-
when :BoundedStream
|
62
|
-
warn "BoundedStream has been renamed to BoundedWriteStream"
|
63
|
-
const_set(:BoundedStream, BoundedWriteStream)
|
64
|
-
else
|
65
|
-
super
|
66
|
-
end
|
67
|
-
end
|
44
|
+
private_constant :BoundedWriteStream
|
68
45
|
|
69
|
-
# With no associated block, +Writer::open+ is a synonym for +Writer::new+.
|
70
|
-
#
|
71
|
-
#
|
72
|
-
#
|
73
|
-
# of the block.
|
46
|
+
# With no associated block, +Writer::open+ is a synonym for +Writer::new+. If the
|
47
|
+
# optional code block is given, it will be passed the new _writer_ as an argument and
|
48
|
+
# the Writer object will automatically be closed when the block terminates. In this
|
49
|
+
# instance, +Writer::open+ returns the value of the block.
|
74
50
|
#
|
75
|
-
# call-seq:
|
51
|
+
# :call-seq:
|
76
52
|
# w = Minitar::Writer.open(STDOUT)
|
77
53
|
# w.add_file_simple('foo.txt', :size => 3)
|
78
54
|
# w.close
|
@@ -80,12 +56,12 @@ class Minitar
|
|
80
56
|
# Minitar::Writer.open(STDOUT) do |w|
|
81
57
|
# w.add_file_simple('foo.txt', :size => 3)
|
82
58
|
# end
|
83
|
-
def self.open(io) # :yields Writer
|
59
|
+
def self.open(io) # :yields: Writer
|
84
60
|
writer = new(io)
|
85
61
|
return writer unless block_given?
|
86
62
|
|
87
|
-
# This exception context must remain, otherwise the stream closes on open
|
88
|
-
#
|
63
|
+
# This exception context must remain, otherwise the stream closes on open even if
|
64
|
+
# a block is not given.
|
89
65
|
begin
|
90
66
|
yield writer
|
91
67
|
ensure
|
@@ -100,36 +76,35 @@ class Minitar
|
|
100
76
|
end
|
101
77
|
|
102
78
|
# Adds a file to the archive as +name+. The data can be provided in the
|
103
|
-
# <tt>opts[:data]</tt> or provided to a BoundedWriteStream that is
|
104
|
-
#
|
79
|
+
# <tt>opts[:data]</tt> or provided to a BoundedWriteStream that is yielded to the
|
80
|
+
# provided block.
|
105
81
|
#
|
106
|
-
# If <tt>opts[:data]</tt> is provided, all other values to +opts+ are
|
107
|
-
#
|
108
|
-
#
|
82
|
+
# If <tt>opts[:data]</tt> is provided, all other values to +opts+ are optional. If the
|
83
|
+
# data is provided to the yielded BoundedWriteStream, <tt>opts[:size]</tt> must be
|
84
|
+
# provided.
|
109
85
|
#
|
110
86
|
# Valid parameters to +opts+ are:
|
111
87
|
#
|
112
88
|
# <tt>:data</tt>:: Optional. The data to write to the archive.
|
113
|
-
# <tt>:mode</tt>:: The Unix file permissions mode value. If not
|
114
|
-
#
|
115
|
-
# <tt>:size</tt>:: The size, in bytes. If <tt>:data</tt> is provided,
|
116
|
-
#
|
117
|
-
# the size of the data
|
118
|
-
# padding (if it is greater than the size of the data
|
89
|
+
# <tt>:mode</tt>:: The Unix file permissions mode value. If not provided, defaults to
|
90
|
+
# 0o644.
|
91
|
+
# <tt>:size</tt>:: The size, in bytes. If <tt>:data</tt> is provided, this parameter
|
92
|
+
# may be ignored (if it is less than the size of the data provided)
|
93
|
+
# or used to add padding (if it is greater than the size of the data
|
119
94
|
# provided).
|
120
95
|
# <tt>:uid</tt>:: The Unix file owner user ID number.
|
121
96
|
# <tt>:gid</tt>:: The Unix file owner group ID number.
|
122
97
|
# <tt>:mtime</tt>:: File modification time, interpreted as an integer.
|
123
98
|
#
|
124
|
-
# An exception will be raised if the Writer is already closed, or if
|
125
|
-
#
|
99
|
+
# An exception will be raised if the Writer is already closed, or if more data is
|
100
|
+
# written to the BoundedWriteStream than expected.
|
126
101
|
#
|
127
|
-
# call-seq:
|
102
|
+
# :call-seq:
|
128
103
|
# writer.add_file_simple('foo.txt', :data => "bar")
|
129
104
|
# writer.add_file_simple('foo.txt', :size => 3) do |w|
|
130
105
|
# w.write("bar")
|
131
106
|
# end
|
132
|
-
def add_file_simple(name, opts = {}) # :yields BoundedWriteStream
|
107
|
+
def add_file_simple(name, opts = {}) # :yields: BoundedWriteStream
|
133
108
|
raise ClosedStream if @closed
|
134
109
|
|
135
110
|
header = {
|
@@ -143,11 +118,7 @@ class Minitar
|
|
143
118
|
size = opts.fetch(:size, nil)
|
144
119
|
|
145
120
|
if block_given?
|
146
|
-
if data
|
147
|
-
raise ArgumentError,
|
148
|
-
"Too much data (opts[:data] and block_given?)."
|
149
|
-
end
|
150
|
-
|
121
|
+
raise ArgumentError, "Too much data (opts[:data] and block_given?)." if data
|
151
122
|
raise ArgumentError, "No size provided" unless size
|
152
123
|
else
|
153
124
|
raise ArgumentError, "No data provided" unless data
|
@@ -175,36 +146,32 @@ class Minitar
|
|
175
146
|
end
|
176
147
|
|
177
148
|
# Adds a file to the archive as +name+. The data can be provided in the
|
178
|
-
# <tt>opts[:data]</tt> or provided to a yielded +WriteOnlyStream+. The
|
179
|
-
#
|
180
|
-
# to the stream.
|
149
|
+
# <tt>opts[:data]</tt> or provided to a yielded +WriteOnlyStream+. The size of the
|
150
|
+
# file will be determined from the amount of data written to the stream.
|
181
151
|
#
|
182
152
|
# Valid parameters to +opts+ are:
|
183
153
|
#
|
184
|
-
# <tt>:mode</tt>:: The Unix file permissions mode value. If not
|
185
|
-
#
|
154
|
+
# <tt>:mode</tt>:: The Unix file permissions mode value. If not provided, defaults to
|
155
|
+
# 0o644.
|
186
156
|
# <tt>:uid</tt>:: The Unix file owner user ID number.
|
187
157
|
# <tt>:gid</tt>:: The Unix file owner group ID number.
|
188
158
|
# <tt>:mtime</tt>:: File modification time, interpreted as an integer.
|
189
159
|
# <tt>:data</tt>:: Optional. The data to write to the archive.
|
190
160
|
#
|
191
|
-
# If <tt>opts[:data]</tt> is provided, this acts the same as
|
192
|
-
#
|
193
|
-
#
|
161
|
+
# If <tt>opts[:data]</tt> is provided, this acts the same as #add_file_simple.
|
162
|
+
# Otherwise, the file's size will be determined from the amount of data written to the
|
163
|
+
# stream.
|
194
164
|
#
|
195
|
-
# For #add_file to be used without <tt>opts[:data]</tt>, the Writer
|
196
|
-
#
|
197
|
-
# #add_file_simple must be used.
|
165
|
+
# For #add_file to be used without <tt>opts[:data]</tt>, the Writer must be wrapping
|
166
|
+
# a stream object that is seekable. Otherwise, #add_file_simple must be used.
|
198
167
|
#
|
199
168
|
# +opts+ may be modified during the writing of the file to the stream.
|
200
|
-
def add_file(name, opts = {}, &) # :yields WriteOnlyStream, +opts
|
169
|
+
def add_file(name, opts = {}, &) # :yields: WriteOnlyStream, +opts+
|
201
170
|
raise ClosedStream if @closed
|
202
171
|
|
203
172
|
return add_file_simple(name, opts, &) if opts[:data]
|
204
173
|
|
205
|
-
unless Minitar.seekable?(@io)
|
206
|
-
raise Minitar::NonSeekableStream
|
207
|
-
end
|
174
|
+
raise Minitar::NonSeekableStream unless Minitar.seekable?(@io)
|
208
175
|
|
209
176
|
short_name, prefix, needs_long_name = split_name(name)
|
210
177
|
|
@@ -255,7 +222,6 @@ class Minitar
|
|
255
222
|
# Creates a symbolic link entry in the tar.
|
256
223
|
def symlink(name, link_target, opts = {})
|
257
224
|
raise ClosedStream if @closed
|
258
|
-
|
259
225
|
raise FileNameTooLong if link_target.size > 100
|
260
226
|
|
261
227
|
name, prefix = split_name(name)
|
@@ -270,24 +236,20 @@ class Minitar
|
|
270
236
|
mtime: opts[:mtime],
|
271
237
|
prefix: prefix
|
272
238
|
}
|
273
|
-
@io.write(PosixHeader.new(header))
|
239
|
+
@io.write(PosixHeader.new(header).to_s)
|
274
240
|
nil
|
275
241
|
end
|
276
242
|
|
277
|
-
# Passes the #flush method to the wrapped stream, used for buffered
|
278
|
-
# streams.
|
243
|
+
# Passes the #flush method to the wrapped stream, used for buffered streams.
|
279
244
|
def flush
|
280
245
|
raise ClosedStream if @closed
|
281
246
|
@io.flush if @io.respond_to?(:flush)
|
282
247
|
end
|
283
248
|
|
284
249
|
# Returns false if the writer is open.
|
285
|
-
def closed?
|
286
|
-
@closed
|
287
|
-
end
|
250
|
+
def closed? = @closed
|
288
251
|
|
289
|
-
# Closes the Writer. This does not close the underlying wrapped output
|
290
|
-
# stream.
|
252
|
+
# Closes the Writer. This does not close the underlying wrapped output stream.
|
291
253
|
def close
|
292
254
|
return if @closed
|
293
255
|
@io.write("\0" * 1024)
|
@@ -305,13 +267,13 @@ class Minitar
|
|
305
267
|
size: long_name.length + 1,
|
306
268
|
mode: 0
|
307
269
|
}
|
308
|
-
@io.write(PosixHeader.new(long_name_header))
|
270
|
+
@io.write(PosixHeader.new(long_name_header).to_s)
|
309
271
|
@io.write(long_name)
|
310
272
|
@io.write("\0" * (512 - (long_name.length % 512)))
|
311
273
|
end
|
312
274
|
|
313
275
|
new_header = header.merge({name: short_name, prefix: prefix})
|
314
|
-
@io.write(PosixHeader.new(new_header))
|
276
|
+
@io.write(PosixHeader.new(new_header).to_s)
|
315
277
|
end
|
316
278
|
|
317
279
|
def split_name(name)
|
data/lib/minitar.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "fileutils"
|
2
4
|
require "rbconfig"
|
5
|
+
require "rbconfig/sizeof"
|
3
6
|
|
4
7
|
# == Synopsis
|
5
8
|
#
|
@@ -8,8 +11,8 @@ require "rbconfig"
|
|
8
11
|
# require 'zlib'
|
9
12
|
# require 'minitar'
|
10
13
|
#
|
11
|
-
# # Packs everything that matches Find.find('tests').
|
12
|
-
# #
|
14
|
+
# # Packs everything that matches Find.find('tests'). test.tar will automatically be
|
15
|
+
# # closed by Minitar.pack.
|
13
16
|
# Minitar.pack('tests', File.open('test.tar', 'wb'))
|
14
17
|
#
|
15
18
|
# # Unpacks 'test.tar' to 'x', creating 'x' if necessary.
|
@@ -23,11 +26,10 @@ require "rbconfig"
|
|
23
26
|
# # test.tgz will be closed automatically.
|
24
27
|
# Minitar.unpack(Zlib::GzipReader.new(File.open('test.tgz', 'rb')), 'x')
|
25
28
|
#
|
26
|
-
# As the case above shows, one need not write to a file. However, it will
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
# Output object and the wrapped data stream object.
|
29
|
+
# As the case above shows, one need not write to a file. However, it will sometimes
|
30
|
+
# require that one dive a little deeper into the API, as in the case of StringIO objects.
|
31
|
+
# Note that I'm not providing a block with Minitar::Output, as Minitar::Output#close
|
32
|
+
# automatically closes both the Output object and the wrapped data stream object.
|
31
33
|
#
|
32
34
|
# begin
|
33
35
|
# sgz = Zlib::GzipWriter.new(StringIO.new(""))
|
@@ -40,52 +42,51 @@ require "rbconfig"
|
|
40
42
|
# tar.close
|
41
43
|
# end
|
42
44
|
class Minitar
|
43
|
-
VERSION = "1.0.2".freeze # :nodoc:
|
44
|
-
|
45
45
|
# The base class for any minitar error.
|
46
46
|
Error = Class.new(::StandardError)
|
47
47
|
# Raised when a wrapped data stream class is not seekable.
|
48
48
|
NonSeekableStream = Class.new(Error)
|
49
|
-
# The exception raised when operations are performed on a stream that has
|
50
|
-
#
|
49
|
+
# The exception raised when operations are performed on a stream that has previously
|
50
|
+
# been closed.
|
51
51
|
ClosedStream = Class.new(Error)
|
52
|
-
# The exception raised when a filename exceeds 256 bytes in length, the
|
53
|
-
#
|
52
|
+
# The exception raised when a filename exceeds 256 bytes in length, the maximum
|
53
|
+
# supported by the standard Tar format.
|
54
54
|
FileNameTooLong = Class.new(Error)
|
55
|
-
# The exception raised when a data stream ends before the amount of data
|
56
|
-
#
|
55
|
+
# The exception raised when a data stream ends before the amount of data expected in the
|
56
|
+
# archive's PosixHeader.
|
57
57
|
UnexpectedEOF = Class.new(StandardError)
|
58
|
-
# The exception raised when a file contains a relative path in secure mode
|
59
|
-
#
|
58
|
+
# The exception raised when a file contains a relative path in secure mode (the default
|
59
|
+
# for this version).
|
60
60
|
SecureRelativePathError = Class.new(Error)
|
61
61
|
# The exception raised when a file contains an invalid Posix header.
|
62
62
|
InvalidTarStream = Class.new(Error)
|
63
63
|
end
|
64
64
|
|
65
65
|
class << Minitar
|
66
|
-
# Tests if +path+ refers to a directory. Fixes an apparently
|
67
|
-
#
|
66
|
+
# Tests if +path+ refers to a directory. Fixes an apparently corrupted <tt>stat()</tt>
|
67
|
+
# call on Windows.
|
68
68
|
def dir?(path)
|
69
|
-
|
69
|
+
path = "#{path}/" unless path.to_s.end_with?("/")
|
70
|
+
File.directory?(path)
|
70
71
|
end
|
71
72
|
|
72
|
-
# A convenience method for wrapping Minitar::Input.open
|
73
|
-
#
|
74
|
-
# modes are currently supported.
|
73
|
+
# A convenience method for wrapping Minitar::Input.open (mode +r+ or +rb) and
|
74
|
+
# Minitar::Output.open (mode +w+ or +wb+). No other modes are currently supported.
|
75
75
|
def open(dest, mode = "r", &)
|
76
76
|
case mode
|
77
|
-
when "r"
|
77
|
+
when "r", "rb"
|
78
78
|
Minitar::Input.open(dest, &)
|
79
|
-
when "w"
|
80
|
-
Minitar::Output.open(dest, &
|
79
|
+
when "w", "wb"
|
80
|
+
Minitar::Output.open(dest, &)
|
81
81
|
else
|
82
|
-
raise "Unknown open mode for Minitar.open."
|
82
|
+
raise ArgumentError, "Unknown open mode for Minitar.open."
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
|
-
def windows? # :nodoc:
|
87
|
-
|
88
|
-
|
86
|
+
def windows? = # :nodoc:
|
87
|
+
RUBY_PLATFORM =~ /^(?:cyginw|mingw|mswin)/i ||
|
88
|
+
RbConfig::CONFIG["host_os"].to_s =~ /^(cygwin|mingw|mswin|windows)/i ||
|
89
|
+
File::ALT_SEPARATOR == "\\"
|
89
90
|
|
90
91
|
# A convenience method to pack the provided +data+ as a file named +entry+. +entry+ may
|
91
92
|
# either be a name or a Hash with the fields described below. When only a name is
|
@@ -100,10 +101,8 @@ class << Minitar
|
|
100
101
|
#
|
101
102
|
# If +data+ is +nil+, a directory will be created. Use an empty String for a normal
|
102
103
|
# empty file.
|
103
|
-
def pack_as_file(entry, data, outputter) # :yields action, name, stats
|
104
|
-
if outputter.is_a?(Minitar::Output)
|
105
|
-
outputter = outputter.tar
|
106
|
-
end
|
104
|
+
def pack_as_file(entry, data, outputter) # :yields: action, name, stats
|
105
|
+
outputter = outputter.tar if outputter.is_a?(Minitar::Output)
|
107
106
|
|
108
107
|
stats = {
|
109
108
|
gid: nil,
|
@@ -114,8 +113,11 @@ class << Minitar
|
|
114
113
|
}
|
115
114
|
|
116
115
|
if entry.is_a?(Hash)
|
117
|
-
name = entry
|
118
|
-
entry.each_pair {
|
116
|
+
name = entry[:name]
|
117
|
+
entry.each_pair {
|
118
|
+
next if _1 == :name
|
119
|
+
stats[_1] = _2 unless _2.nil?
|
120
|
+
}
|
119
121
|
else
|
120
122
|
name = entry
|
121
123
|
end
|
@@ -151,33 +153,27 @@ class << Minitar
|
|
151
153
|
# <tt>:gid</tt>:: The group owner of the file. (Ignored on Windows.)
|
152
154
|
# <tt>:mtime</tt>:: The modification Time of the file.
|
153
155
|
#
|
154
|
-
# During packing, if a block is provided, #pack_file yields an +action+
|
155
|
-
#
|
156
|
-
#
|
156
|
+
# During packing, if a block is provided, #pack_file yields an +action+ Symbol, the full
|
157
|
+
# name of the file being packed, and a Hash of statistical information, just as with
|
158
|
+
# Minitar::Input#extract_entry.
|
157
159
|
#
|
158
160
|
# The +action+ will be one of:
|
159
161
|
# <tt>:dir</tt>:: The +entry+ is a directory.
|
160
|
-
# <tt>:file_start</tt>:: The +entry+ is a file; the extract of the
|
161
|
-
#
|
162
|
-
# <tt>:file_progress</tt>:: Yielded every 4096 bytes during the extract
|
163
|
-
# of the +entry+.
|
162
|
+
# <tt>:file_start</tt>:: The +entry+ is a file; the extract of the file is just
|
163
|
+
# beginning.
|
164
|
+
# <tt>:file_progress</tt>:: Yielded every 4096 bytes during the extract of the +entry+.
|
164
165
|
# <tt>:file_done</tt>:: Yielded when the +entry+ is completed.
|
165
166
|
#
|
166
167
|
# The +stats+ hash contains the following keys:
|
167
|
-
# <tt>:current</tt>:: The current total number of bytes read in the
|
168
|
-
#
|
169
|
-
# <tt>:
|
170
|
-
# cycle.
|
171
|
-
# <tt>:name</tt>:: The filename to be packed into the tarchive.
|
172
|
-
# *REQUIRED*.
|
168
|
+
# <tt>:current</tt>:: The current total number of bytes read in the +entry+.
|
169
|
+
# <tt>:currinc</tt>:: The current number of bytes read in this read cycle.
|
170
|
+
# <tt>:name</tt>:: The filename to be packed into the tarchive. *REQUIRED*.
|
173
171
|
# <tt>:mode</tt>:: The mode to be applied.
|
174
172
|
# <tt>:uid</tt>:: The user owner of the file. (+nil+ on Windows.)
|
175
173
|
# <tt>:gid</tt>:: The group owner of the file. (+nil+ on Windows.)
|
176
174
|
# <tt>:mtime</tt>:: The modification Time of the file.
|
177
|
-
def pack_file(entry, outputter) # :yields action, name, stats
|
178
|
-
if outputter.is_a?(Minitar::Output)
|
179
|
-
outputter = outputter.tar
|
180
|
-
end
|
175
|
+
def pack_file(entry, outputter) # :yields: action, name, stats
|
176
|
+
outputter = outputter.tar if outputter.is_a?(Minitar::Output)
|
181
177
|
|
182
178
|
stats = {}
|
183
179
|
|
@@ -223,13 +219,12 @@ class << Minitar
|
|
223
219
|
end
|
224
220
|
end
|
225
221
|
|
226
|
-
# A convenience method to pack files specified by +src+ into +dest+. If
|
227
|
-
#
|
228
|
-
#
|
229
|
-
# true, then directories will be recursed.
|
222
|
+
# A convenience method to pack files specified by +src+ into +dest+. If +src+ is an
|
223
|
+
# Array, then each file detailed therein will be packed into the resulting
|
224
|
+
# Minitar::Output stream; if +recurse_dirs+ is true, then directories will be recursed.
|
230
225
|
#
|
231
|
-
# If +src+ is not an Array, it will be treated as the result of Find.find;
|
232
|
-
#
|
226
|
+
# If +src+ is not an Array, it will be treated as the result of Find.find; all files
|
227
|
+
# matching will be packed.
|
233
228
|
def pack(src, dest, recurse_dirs = true, &block)
|
234
229
|
require "find"
|
235
230
|
Minitar::Output.open(dest) do |outp|
|
@@ -251,9 +246,8 @@ class << Minitar
|
|
251
246
|
end
|
252
247
|
end
|
253
248
|
|
254
|
-
# A convenience method to unpack files from +src+ into the directory
|
255
|
-
#
|
256
|
-
# will be extracted.
|
249
|
+
# A convenience method to unpack files from +src+ into the directory specified by
|
250
|
+
# +dest+. Only those files named explicitly in +files+ will be extracted.
|
257
251
|
def unpack(src, dest, files = [], options = {}, &block)
|
258
252
|
Minitar::Input.open(src) do |inp|
|
259
253
|
if File.exist?(dest) && !dir?(dest)
|
@@ -272,8 +266,8 @@ class << Minitar
|
|
272
266
|
|
273
267
|
# Check whether +io+ can seek without errors.
|
274
268
|
def seekable?(io, methods = nil)
|
275
|
-
# The IO class throws an exception at runtime if we try to change
|
276
|
-
#
|
269
|
+
# The IO class throws an exception at runtime if we try to change position on
|
270
|
+
# a non-regular file.
|
277
271
|
if io.respond_to?(:stat)
|
278
272
|
io.stat.file?
|
279
273
|
else
|
@@ -286,5 +280,7 @@ class << Minitar
|
|
286
280
|
end
|
287
281
|
|
288
282
|
require "minitar/posix_header"
|
283
|
+
require "minitar/pax_header"
|
289
284
|
require "minitar/input"
|
290
285
|
require "minitar/output"
|
286
|
+
require "minitar/version"
|
data/licenses/bsdl.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Redistribution and use in source and binary forms, with or without
|
2
|
+
modification, are permitted provided that the following conditions are met:
|
3
|
+
|
4
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
5
|
+
list of conditions and the following disclaimer.
|
6
|
+
|
7
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
8
|
+
this list of conditions and the following disclaimer in the documentation
|
9
|
+
and/or other materials provided with the distribution.
|
10
|
+
|
11
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
12
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
13
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
14
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
15
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
16
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
17
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
18
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
19
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
20
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/licenses/dco.txt
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
Developer Certificate of Origin
|
2
|
+
Version 1.1
|
3
|
+
|
4
|
+
Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
|
5
|
+
|
6
|
+
Everyone is permitted to copy and distribute verbatim copies of this
|
7
|
+
license document, but changing it is not allowed.
|
8
|
+
|
9
|
+
|
10
|
+
Developer's Certificate of Origin 1.1
|
11
|
+
|
12
|
+
By making a contribution to this project, I certify that:
|
13
|
+
|
14
|
+
(a) The contribution was created in whole or in part by me and I
|
15
|
+
have the right to submit it under the open source license
|
16
|
+
indicated in the file; or
|
17
|
+
|
18
|
+
(b) The contribution is based upon previous work that, to the best
|
19
|
+
of my knowledge, is covered under an appropriate open source
|
20
|
+
license and I have the right under that license to submit that
|
21
|
+
work with modifications, whether created in whole or in part
|
22
|
+
by me, under the same open source license (unless I am
|
23
|
+
permitted to submit under a different license), as indicated
|
24
|
+
in the file; or
|
25
|
+
|
26
|
+
(c) The contribution was provided directly to me by some other
|
27
|
+
person who certified (a), (b) or (c) and I have not modified
|
28
|
+
it.
|
29
|
+
|
30
|
+
(d) I understand and agree that this project and the contribution
|
31
|
+
are public and that a record of the contribution (including all
|
32
|
+
personal information I submit with it, including my sign-off) is
|
33
|
+
maintained indefinitely and may be redistributed consistent with
|
34
|
+
this project or the open source license(s) involved.
|
data/licenses/ruby.txt
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
1. You may make and give away verbatim copies of the source form of the
|
2
|
+
software without restriction, provided that you duplicate all of the
|
3
|
+
original copyright notices and associated disclaimers.
|
4
|
+
|
5
|
+
2. You may modify your copy of the software in any way, provided that
|
6
|
+
you do at least ONE of the following:
|
7
|
+
|
8
|
+
a. place your modifications in the Public Domain or otherwise
|
9
|
+
make them Freely Available, such as by posting said
|
10
|
+
modifications to Usenet or an equivalent medium, or by allowing
|
11
|
+
the author to include your modifications in the software.
|
12
|
+
|
13
|
+
b. use the modified software only within your corporation or
|
14
|
+
organization.
|
15
|
+
|
16
|
+
c. give non-standard binaries non-standard names, with
|
17
|
+
instructions on where to get the original software distribution.
|
18
|
+
|
19
|
+
d. make other distribution arrangements with the author.
|
20
|
+
|
21
|
+
3. You may distribute the software in object code or binary form,
|
22
|
+
provided that you do at least ONE of the following:
|
23
|
+
|
24
|
+
a. distribute the binaries and library files of the software,
|
25
|
+
together with instructions (in the manual page or equivalent)
|
26
|
+
on where to get the original distribution.
|
27
|
+
|
28
|
+
b. accompany the distribution with the machine-readable source of
|
29
|
+
the software.
|
30
|
+
|
31
|
+
c. give non-standard binaries non-standard names, with
|
32
|
+
instructions on where to get the original software distribution.
|
33
|
+
|
34
|
+
d. make other distribution arrangements with the author.
|
35
|
+
|
36
|
+
4. You may modify and include the part of the software into any other
|
37
|
+
software (possibly commercial). But some files in the distribution
|
38
|
+
are not written by the author, so that they are not under these terms.
|
39
|
+
|
40
|
+
For the list of those files and their copying conditions, see the
|
41
|
+
file LEGAL.
|
42
|
+
|
43
|
+
5. The scripts and library files supplied as input to or produced as
|
44
|
+
output from the software do not automatically fall under the
|
45
|
+
copyright of the software, but belong to whomever generated them,
|
46
|
+
and may be sold commercially, and may be aggregated with this
|
47
|
+
software.
|
48
|
+
|
49
|
+
6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
|
50
|
+
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
51
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
52
|
+
PURPOSE.
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/test/minitest_helper.rb
CHANGED
@@ -1,10 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "fileutils"
|
2
4
|
require "minitar"
|
5
|
+
require "pathname"
|
6
|
+
require "stringio"
|
7
|
+
require "zlib"
|
3
8
|
|
4
9
|
gem "minitest"
|
5
10
|
require "minitest/autorun"
|
6
11
|
require "minitest/focus"
|
7
12
|
|
8
|
-
|
13
|
+
if ENV["STRICT"] != "false"
|
14
|
+
$VERBOSE = true
|
15
|
+
Warning[:deprecated] = true
|
16
|
+
require "minitest/error_on_warning"
|
17
|
+
end
|
18
|
+
|
19
|
+
Dir.glob(File.join(__dir__, "support/**/*.rb")).sort.each do |support|
|
9
20
|
require support
|
10
21
|
end
|