Skip to content

Commit 2f9092a

Browse files
committed
Add support for minitar 1.x
Update puppet to support minitar 1.0 which contains breaking changes. Note this important warning from https://github.com/halostatue/minitar Minitar does not perform validation of path names provided to the convenience classes Minitar::Output and Minitar::Input, which use Kernel.open for their underlying implementations when not given an IO-like object. As a result we always pass a reader/writer to the unpack/pack methods respectively.
1 parent 700c826 commit 2f9092a

File tree

5 files changed

+19
-19
lines changed

5 files changed

+19
-19
lines changed

Diff for: Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ group(:features) do
2727
gem 'hocon', '~> 1.0', require: false
2828
# requires native libshadow headers/libs
2929
#gem 'ruby-shadow', '~> 2.5', require: false, platforms: [:ruby]
30-
gem 'minitar', '~> 0.9', require: false
30+
gem 'minitar', '~> 1.0', require: false
3131
gem 'msgpack', '~> 1.2', require: false
3232
gem 'rdoc', ['~> 6.0', '< 6.4.0'], require: false, platforms: [:ruby]
3333
# requires native augeas headers/libs

Diff for: lib/puppet/feature/base.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
# We have Hiera
4848
Puppet.features.add(:hiera, :libs => ["hiera"])
4949

50-
Puppet.features.add(:minitar, :libs => ["archive/tar/minitar"])
50+
Puppet.features.add(:minitar, :libs => ["minitar"])
5151

5252
# We can manage symlinks
5353
Puppet.features.add(:manages_symlinks) do

Diff for: lib/puppet/module_tool/tar/mini.rb

+13-13
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,12 @@
33
class Puppet::ModuleTool::Tar::Mini
44
def unpack(sourcefile, destdir, _)
55
Zlib::GzipReader.open(sourcefile) do |reader|
6-
# puppet doesn't have a hard dependency on minitar, so we
7-
# can't be certain which version is installed. If it's 0.9
8-
# or above then we can prevent minitar from fsync'ing each
9-
# extracted file and directory, otherwise fallback to the
10-
# old behavior
11-
args = [reader, destdir, find_valid_files(reader)]
12-
spec = Gem::Specification.find_by_name('minitar')
13-
if spec && spec.version >= Gem::Version.new('0.9')
14-
args << { :fsync => false }
15-
end
16-
Archive::Tar::Minitar.unpack(*args) do |action, name, stats|
6+
files = find_valid_files(reader)
7+
8+
# Never pass a source file as a string to unpack, otherwise minitar will
9+
# call Kernel.open on it, which could invoke shell commands. Always pass a
10+
# reader that responds to `:read`
11+
Minitar.unpack(reader, destdir, files, fsync: false) do |action, name, stats|
1712
case action
1813
when :dir
1914
validate_entry(destdir, name)
@@ -33,7 +28,10 @@ def unpack(sourcefile, destdir, _)
3328

3429
def pack(sourcedir, destfile)
3530
Zlib::GzipWriter.open(destfile) do |writer|
36-
Archive::Tar::Minitar.pack(sourcedir, writer) do |step, name, stats|
31+
# Never pass the destination file as a string to pack, otherwise minitar
32+
# will call Kernel.open on it, which could invoke shell commands. Always
33+
# pass a writer that responds to `:write`
34+
Minitar.pack(sourcedir, writer) do |step, name, stats|
3735
# TODO smcclellan 2017-10-31 Set permissions here when this yield block
3836
# executes before the header is written. As it stands, the `stats`
3937
# argument isn't mutable in a way that will effect the desired mode for
@@ -93,7 +91,9 @@ def set_default_user_and_group!(stats)
9391
# tar format info: https://pic.dhe.ibm.com/infocenter/zos/v1r13/index.jsp?topic=%2Fcom.ibm.zos.r13.bpxa500%2Ftaf.htm
9492
# pax format info: https://pic.dhe.ibm.com/infocenter/zos/v1r13/index.jsp?topic=%2Fcom.ibm.zos.r13.bpxa500%2Fpxarchfm.htm
9593
def find_valid_files(tarfile)
96-
Archive::Tar::Minitar.open(tarfile).collect do |entry|
94+
raise ArgumentError, "Cannot list files from '#{tarfile}', because the object does not implement a 'read' method" unless tarfile.respond_to?(:read)
95+
96+
Minitar.open(tarfile).collect do |entry|
9797
flag = entry.typeflag
9898
if flag.nil? || flag =~ /[[:digit:]]/ && (0..7).cover?(flag.to_i)
9999
entry.full_name

Diff for: puppet.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ Gem::Specification.new do |spec|
3939
if platform == 'x64-mingw32' || platform == 'x86-mingw32'
4040
# ffi 1.16.0 - 1.16.2 are broken on Windows
4141
spec.add_runtime_dependency('ffi', '>= 1.15.5', '< 1.17.0', '!= 1.16.0', '!= 1.16.1', '!= 1.16.2')
42-
spec.add_runtime_dependency('minitar', '~> 0.9')
42+
spec.add_runtime_dependency('minitar', '~> 1.0')
4343
end
4444
end

Diff for: spec/unit/module_tool/tar/mini_spec.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def initialize(mode = 0100)
6161

6262
expect(Zlib::GzipWriter).to receive(:open).with(destfile).and_yield(writer)
6363
stats = {:mode => 0222}
64-
expect(Archive::Tar::Minitar).to receive(:pack).with(sourcedir, writer).and_yield(:file_start, 'abc', stats)
64+
expect(Minitar).to receive(:pack).with(sourcedir, writer).and_yield(:file_start, 'abc', stats)
6565

6666
minitar.pack(sourcedir, destfile)
6767
end
@@ -70,7 +70,7 @@ def initialize(mode = 0100)
7070
writer = double('GzipWriter')
7171

7272
expect(Zlib::GzipWriter).to receive(:open).with(destfile).and_yield(writer)
73-
expect(Archive::Tar::Minitar).to receive(:pack).with(sourcedir, writer).
73+
expect(Minitar).to receive(:pack).with(sourcedir, writer).
7474
and_yield(:file_start, 'abc', {:entry => MockFileStatEntry.new(nil)})
7575

7676
minitar.pack(sourcedir, destfile)
@@ -82,7 +82,7 @@ def unpacks_the_entry(type, name, mode = 0100)
8282
expect(Zlib::GzipReader).to receive(:open).with(sourcefile).and_yield(reader)
8383
expect(minitar).to receive(:find_valid_files).with(reader).and_return([name])
8484
entry = MockFileStatEntry.new(mode)
85-
expect(Archive::Tar::Minitar).to receive(:unpack).with(reader, destdir, [name], {:fsync => false}).
85+
expect(Minitar).to receive(:unpack).with(reader, destdir, [name], {:fsync => false}).
8686
and_yield(type, name, {:entry => entry})
8787
entry
8888
end

0 commit comments

Comments
 (0)