minitar 0.8 → 0.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -30,8 +30,8 @@ module Archive::Tar::Minitar
30
30
  def self.const_missing(c)
31
31
  case c
32
32
  when :FileOverflow
33
- warn 'Writer::BoundedWriteStream::FileOverflow has been renamed ' \
34
- 'to Writer::WriteBoundaryOverflow'
33
+ warn "Writer::BoundedWriteStream::FileOverflow has been renamed " \
34
+ "to Writer::WriteBoundaryOverflow"
35
35
  const_set :FileOverflow,
36
36
  Archive::Tar::Minitar::Writer::WriteBoundaryOverflow
37
37
  else
@@ -46,9 +46,9 @@ module Archive::Tar::Minitar
46
46
  attr_reader :written
47
47
 
48
48
  def initialize(io, limit)
49
- @io = io
50
- @limit = limit
51
- @written = 0
49
+ @io = io
50
+ @limit = limit
51
+ @written = 0
52
52
  end
53
53
 
54
54
  def write(data)
@@ -65,7 +65,7 @@ module Archive::Tar::Minitar
65
65
  def self.const_missing(c)
66
66
  case c
67
67
  when :BoundedStream
68
- warn 'BoundedStream has been renamed to BoundedWriteStream'
68
+ warn "BoundedStream has been renamed to BoundedWriteStream"
69
69
  const_set(:BoundedStream, BoundedWriteStream)
70
70
  else
71
71
  super
@@ -101,7 +101,7 @@ module Archive::Tar::Minitar
101
101
 
102
102
  # Creates and returns a new Writer object.
103
103
  def initialize(io)
104
- @io = io
104
+ @io = io
105
105
  @closed = false
106
106
  end
107
107
 
@@ -139,10 +139,10 @@ module Archive::Tar::Minitar
139
139
  raise ClosedStream if @closed
140
140
 
141
141
  header = {
142
- :mode => opts.fetch(:mode, 0o644),
143
- :mtime => opts.fetch(:mtime, nil),
144
- :gid => opts.fetch(:gid, nil),
145
- :uid => opts.fetch(:uid, nil)
142
+ :mode => opts.fetch(:mode, 0o644),
143
+ :mtime => opts.fetch(:mtime, nil),
144
+ :gid => opts.fetch(:gid, nil),
145
+ :uid => opts.fetch(:uid, nil)
146
146
  }
147
147
 
148
148
  data = opts.fetch(:data, nil)
@@ -151,12 +151,12 @@ module Archive::Tar::Minitar
151
151
  if block_given?
152
152
  if data
153
153
  raise ArgumentError,
154
- 'Too much data (opts[:data] and block_given?).'
154
+ "Too much data (opts[:data] and block_given?)."
155
155
  end
156
156
 
157
- raise ArgumentError, 'No size provided' unless size
157
+ raise ArgumentError, "No size provided" unless size
158
158
  else
159
- raise ArgumentError, 'No data provided' unless data
159
+ raise ArgumentError, "No data provided" unless data
160
160
 
161
161
  bytes = bytesize(data)
162
162
  size = bytes if size.nil? || size < bytes
@@ -164,7 +164,8 @@ module Archive::Tar::Minitar
164
164
 
165
165
  header[:size] = size
166
166
 
167
- write_header(name, header)
167
+ short_name, prefix, needs_long_name = split_name(name)
168
+ write_header(header, name, short_name, prefix, needs_long_name)
168
169
 
169
170
  os = BoundedWriteStream.new(@io, size)
170
171
  if block_given?
@@ -211,12 +212,15 @@ module Archive::Tar::Minitar
211
212
  raise Archive::Tar::Minitar::NonSeekableStream
212
213
  end
213
214
 
215
+ short_name, prefix, needs_long_name = split_name(name)
216
+
217
+ data_offset = needs_long_name ? 3 * 512 : 512
214
218
  init_pos = @io.pos
215
- @io.write("\0" * 512) # placeholder for the header
219
+ @io.write("\0" * data_offset) # placeholder for the header
216
220
 
217
221
  yield WriteOnlyStream.new(@io), opts
218
222
 
219
- size = @io.pos - (init_pos + 512)
223
+ size = @io.pos - (init_pos + data_offset)
220
224
  remainder = (512 - (size % 512)) % 512
221
225
  @io.write("\0" * remainder)
222
226
 
@@ -227,9 +231,11 @@ module Archive::Tar::Minitar
227
231
  :mtime => opts[:mtime],
228
232
  :size => size,
229
233
  :gid => opts[:gid],
230
- :uid => opts[:uid],
234
+ :uid => opts[:uid]
231
235
  }
232
- write_header(name, header)
236
+
237
+ write_header(header, name, short_name, prefix, needs_long_name)
238
+
233
239
  @io.pos = final_pos
234
240
  end
235
241
 
@@ -239,13 +245,38 @@ module Archive::Tar::Minitar
239
245
 
240
246
  header = {
241
247
  :mode => opts[:mode],
242
- :typeflag => '5',
248
+ :typeflag => "5",
249
+ :size => 0,
250
+ :gid => opts[:gid],
251
+ :uid => opts[:uid],
252
+ :mtime => opts[:mtime]
253
+ }
254
+
255
+ short_name, prefix, needs_long_name = split_name(name)
256
+ write_header(header, name, short_name, prefix, needs_long_name)
257
+
258
+ nil
259
+ end
260
+
261
+ # Creates a symbolic link entry in the tar.
262
+ def symlink(name, link_target, opts = {})
263
+ raise ClosedStream if @closed
264
+
265
+ raise FileNameTooLong if link_target.size > 100
266
+
267
+ name, prefix = split_name(name)
268
+ header = {
269
+ :name => name,
270
+ :mode => opts[:mode],
271
+ :typeflag => "2",
243
272
  :size => 0,
273
+ :linkname => link_target,
244
274
  :gid => opts[:gid],
245
275
  :uid => opts[:uid],
246
276
  :mtime => opts[:mtime],
277
+ :prefix => prefix
247
278
  }
248
- write_header(name, header)
279
+ @io.write(PosixHeader.new(header))
249
280
  nil
250
281
  end
251
282
 
@@ -271,47 +302,45 @@ module Archive::Tar::Minitar
271
302
 
272
303
  private
273
304
 
274
- def write_header(long_name, header)
275
- short_name, prefix, needs_long_name = split_name(long_name)
276
-
305
+ def write_header(header, long_name, short_name, prefix, needs_long_name)
277
306
  if needs_long_name
278
307
  long_name_header = {
279
- :prefix => '',
308
+ :prefix => "",
280
309
  :name => PosixHeader::GNU_EXT_LONG_LINK,
281
- :typeflag => 'L',
282
- :size => long_name.length,
283
- :mode => 0,
310
+ :typeflag => "L",
311
+ :size => long_name.length + 1,
312
+ :mode => 0
284
313
  }
285
314
  @io.write(PosixHeader.new(long_name_header))
286
315
  @io.write(long_name)
287
316
  @io.write("\0" * (512 - (long_name.length % 512)))
288
317
  end
289
318
 
290
- new_header = header.merge({ :name => short_name, :prefix => prefix })
319
+ new_header = header.merge({:name => short_name, :prefix => prefix})
291
320
  @io.write(PosixHeader.new(new_header))
292
321
  end
293
322
 
294
323
  def split_name(name)
295
324
  if bytesize(name) <= 100
296
- prefix = ''
325
+ prefix = ""
297
326
  else
298
- parts = name.split(/\//)
327
+ parts = name.split("/")
299
328
  newname = parts.pop
300
329
 
301
- nxt = ''
330
+ nxt = ""
302
331
 
303
332
  loop do
304
- nxt = parts.pop || ''
333
+ nxt = parts.pop || ""
305
334
  break if bytesize(newname) + 1 + bytesize(nxt) >= 100
306
335
  newname = "#{nxt}/#{newname}"
307
336
  end
308
337
 
309
- prefix = (parts + [nxt]).join('/')
338
+ prefix = (parts + [nxt]).join("/")
310
339
 
311
340
  name = newname
312
341
  end
313
342
 
314
- [ name, prefix, (bytesize(name) > 100 || bytesize(prefix) > 155) ]
343
+ [name, prefix, bytesize(name) > 100 || bytesize(prefix) > 155]
315
344
  end
316
345
  end
317
346
  end
@@ -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 'fileutils'
9
- require 'rbconfig'
9
+ require "fileutils"
10
+ require "rbconfig"
10
11
 
11
- class << Archive::Tar #:nodoc:
12
- def const_missing(const) #:nodoc:
12
+ class << Archive::Tar # :nodoc:
13
+ def const_missing(const) # :nodoc:
13
14
  case const
14
15
  when :PosixHeader
15
- warn 'Archive::Tar::PosixHeader has been renamed to ' \
16
- 'Archive::Tar::Minitar::PosixHeader'
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 'set'
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 = '0.8'.freeze # :nodoc:
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 = 'r', &block)
110
+ def open(dest, mode = "r", &block)
110
111
  case mode
111
- when 'r'
112
+ when "r"
112
113
  Input.open(dest, &block)
113
- when 'w'
114
+ when "w"
114
115
  Output.open(dest, &block)
115
116
  else
116
- raise 'Unknown open mode for Archive::Tar::Minitar.open.'
117
+ raise "Unknown open mode for Archive::Tar::Minitar.open."
117
118
  end
118
119
  end
119
120
 
120
- def const_missing(c) #:nodoc:
121
+ def const_missing(c) # :nodoc:
121
122
  case c
122
123
  when :BlockRequired
123
- warn 'This constant has been removed.'
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? #:nodoc:
131
- RbConfig::CONFIG['host_os'] =~ /^(mswin|mingw|cygwin)/
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) #:yields action, name, stats:
169
- if outputter.kind_of?(Archive::Tar::Minitar::Output)
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.kind_of?(Hash)
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] ||= stat.mode
185
- stats[:mtime] ||= stat.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] = nil
190
- stats[:gid] = nil
190
+ stats[:uid] = nil
191
+ stats[:gid] = nil
191
192
  else
192
- stats[:uid] ||= stat.uid
193
- stats[:gid] ||= stat.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, 'rb') do |ff|
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 %q(Don't yet know how to pack this type of file.)
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; all
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 'find'
226
+ require "find"
226
227
  Output.open(dest) do |outp|
227
- if src.kind_of?(Array)
228
+ if src.is_a?(Array)
228
229
  src.each do |entry|
229
- if dir?(entry) and recurse_dirs
230
+ if dir?(entry) && recurse_dirs
230
231
  Find.find(entry) do |ee|
231
232
  pack_file(ee, outp, &block)
232
233
  end
@@ -245,17 +246,17 @@ module Archive::Tar::Minitar
245
246
  # A convenience method to unpack files from +src+ into the directory
246
247
  # specified by +dest+. Only those files named explicitly in +files+
247
248
  # will be extracted.
248
- def unpack(src, dest, files = [], &block)
249
+ def unpack(src, dest, files = [], options = {}, &block)
249
250
  Input.open(src) do |inp|
250
- if File.exist?(dest) and !dir?(dest)
251
- raise %q(Can't unpack to a non-directory.)
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? or files.include?(entry.full_name)
258
- inp.extract_entry(dest, entry, &block)
258
+ if files.empty? || files.include?(entry.full_name)
259
+ inp.extract_entry(dest, entry, options, &block)
259
260
  end
260
261
  end
261
262
  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 ||= [ :pos, :pos=, :seek, :rewind ]
273
- methods = [ methods ] unless methods.kind_of?(Array)
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 'set'
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 ''.respond_to?(:bytesize)
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 'archive/tar/minitar/posix_header'
309
- require 'archive/tar/minitar/input'
310
- require 'archive/tar/minitar/output'
309
+ require "archive/tar/minitar/posix_header"
310
+ require "archive/tar/minitar/input"
311
+ require "archive/tar/minitar/output"
@@ -1,3 +1,3 @@
1
1
  # coding: utf-8
2
2
 
3
- require 'archive/tar/minitar'
3
+ require "archive/tar/minitar"
data/lib/minitar.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # coding: utf-8
2
2
 
3
- require 'archive/tar/minitar'
3
+ require "archive/tar/minitar"
4
4
 
5
5
  if defined?(::Minitar) && ::Minitar != Archive::Tar::Minitar
6
6
  warn <<-EOS
@@ -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
@@ -1,11 +1,12 @@
1
- # -*- ruby encoding: utf-8 -*-
1
+ # frozen_string_literal: true
2
2
 
3
- require 'fileutils'
4
- require 'minitar'
3
+ require "fileutils"
4
+ require "minitar"
5
5
 
6
- gem 'minitest'
7
- require 'minitest/autorun'
6
+ gem "minitest"
7
+ require "minitest/autorun"
8
+ require "minitest/focus"
8
9
 
9
- Dir.glob(File.join(File.dirname(__FILE__), 'support/*.rb')).each do |support|
10
+ Dir.glob(File.join(File.dirname(__FILE__), "support/*.rb")).sort.each do |support|
10
11
  require support
11
12
  end