Skip to content

Commit 9561434

Browse files
committed
(CODEMGMT-659) Change to use minitar entry's full_name
This commit changes from using the name field of minitar's entry to full_name. name has a 100 character limit and caused incomplete file names to be extracted.
1 parent 04905ac commit 9561434

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

lib/puppet_forge/tar/mini.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,13 @@ def validate_files(tarfile)
5252
file_lists = {:valid => [], :invalid => [], :symlinks => []}
5353
Archive::Tar::Minitar.open(tarfile).each do |entry|
5454
flag = entry.typeflag
55+
#require 'pry'; binding.pry
5556
if flag.nil? || flag =~ /[[:digit:]]/ && SYMLINK_FLAGS.include?(flag.to_i)
56-
file_lists[:symlinks] << entry.name
57+
file_lists[:symlinks] << entry.full_name
5758
elsif flag.nil? || flag =~ /[[:digit:]]/ && VALID_TAR_FLAGS.include?(flag.to_i)
58-
file_lists[:valid] << entry.name
59+
file_lists[:valid] << entry.full_name
5960
else
60-
file_lists[:invalid] << entry.name
61+
file_lists[:invalid] << entry.full_name
6162
end
6263
end
6364
file_lists

spec/unit/forge/tar/mini_spec.rb

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
describe PuppetForge::Tar::Mini do
44
let(:entry_class) do
55
Class.new do
6-
attr_accessor :typeflag, :name
7-
def initialize(name, typeflag)
6+
attr_accessor :typeflag, :name, :full_name
7+
def initialize(name, full_name, typeflag)
88
@name = name
9+
@full_name = full_name
910
@typeflag = typeflag
1011
end
1112
end
@@ -15,9 +16,9 @@ def initialize(name, typeflag)
1516
let(:sourcedir) { '/the/src/dir' }
1617
let(:destfile) { '/the/dest/file.tar.gz' }
1718
let(:minitar) { described_class.new }
18-
let(:tarfile_contents) { [entry_class.new('file', '0'), \
19-
entry_class.new('symlink', '2'), \
20-
entry_class.new('invalid', 'F')] }
19+
let(:tarfile_contents) { [entry_class.new('file', 'full_file', '0'), \
20+
entry_class.new('symlink', 'full_symlink', '2'), \
21+
entry_class.new('invalid', 'full_invalid', 'F')] }
2122

2223
it "unpacks a tar file" do
2324
unpacks_the_entry(:file_start, 'thefile')
@@ -66,13 +67,15 @@ def initialize(name, typeflag)
6667

6768
expect(Zlib::GzipReader).to receive(:open).with(sourcefile).and_yield(reader)
6869
expect(Archive::Tar::Minitar).to receive(:open).with(reader).and_return(tarfile_contents)
69-
expect(Archive::Tar::Minitar).to receive(:unpack).with(reader, destdir, ['file']).and_yield(:file_start, 'thefile', nil)
70-
70+
#expect(Archive::Tar::Minitar).to receive(:unpack).with(reader, destdir, ['file']).and_yield(:file_start, 'thefile', nil)
71+
72+
expect(Archive::Tar::Minitar).to receive(:unpack).with(reader, destdir, ['full_file']).and_yield(:file_start, 'thefile', nil)
73+
7174
file_lists = minitar.unpack(sourcefile, destdir)
7275

73-
expect(file_lists[:valid]).to eq(['file'])
74-
expect(file_lists[:invalid]).to eq(['invalid'])
75-
expect(file_lists[:symlinks]).to eq(['symlink'])
76+
expect(file_lists[:valid]).to eq(['full_file'])
77+
expect(file_lists[:invalid]).to eq(['full_invalid'])
78+
expect(file_lists[:symlinks]).to eq(['full_symlink'])
7679
end
7780

7881
def unpacks_the_entry(type, name)

0 commit comments

Comments
 (0)