Skip to content

Commit

Permalink
Merge pull request #6938 from jerryk55/rubyzip_1.1
Browse files Browse the repository at this point in the history
Upgrade RubyZip Gem to 1.2
  • Loading branch information
jrafanie committed Feb 29, 2016
2 parents 5b5e179 + 93766ab commit bb62d68
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
3 changes: 2 additions & 1 deletion gems/pending/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ gem "ovirt", "~>0.7.2", :require => false
gem "pg", "~>0.18.2", :require => false
gem "psych", "~>2.0.12"
gem "rest-client", "=2.0.0.rc1", :require => false
gem "rubyzip", "=0.9.5", :require => false # TODO: Review 0.9.7 breaking log collection in FB14646
gem "rubyzip", "~>1.2.0", :require => false
gem "zip-zip", "~>0.3.0", :require => false
gem "rufus-lru", "~>1.0.3", :require => false
gem "sys-uname", "~>1.0.1", :require => false
gem "trollop", "~>2.0", :require => false
Expand Down
13 changes: 9 additions & 4 deletions lib/vmdb/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def self.zip_logs(zip_filename, dirs, userid = "system")
dirs.each do |dir|
dir = Rails.root.join(dir) unless Pathname.new(dir).absolute?
Dir.glob(dir).each do |file|
entry, mtime = add_zip_entry(zip, file)
entry, mtime = add_zip_entry(zip, file, zfile)
_log.info "Adding file: [#{entry}], size: [#{File.size(file)}], mtime: [#{mtime}]"
end
end
Expand All @@ -126,11 +126,16 @@ def self.zip_logs(zip_filename, dirs, userid = "system")
private

# TODO: Make a class out of this so we don't have to pass around the zip.
def self.add_zip_entry(zip, file_path)
def self.add_zip_entry(zip, file_path, zfile)
entry = zip_entry_from_path(file_path)
mtime = File.mtime(file_path)
File.directory?(file_path) ? zip.mkdir(entry) : zip.add(entry, file_path)
zip.file.utime(mtime, entry)
ztime = Zip::DOSTime.at(mtime.to_i)
if File.directory?(file_path)
zip.mkdir(entry)
else
zip_entry = Zip::Entry.new(zfile, entry, nil, nil, nil, nil, nil, nil, ztime)
zip.add(zip_entry, file_path)
end
return entry, mtime
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def setup_version_xml(v)
fd = double(:original_filename => "dummy.zip", :read => "junk", :eof => true, :close => true)
import_file = File.expand_path(File.join(Rails.root, "tmp/miq_automate_engine", "dummy.zip"))
expect { MiqAeDatastore.upload(fd, "dummy.zip") }
.to raise_error(/end of central directory signature not found/)
.to raise_error(/has zero size. Did you mean to pass the create flag?/)
expect(File.exist?(import_file)).to be_falsey
end

Expand Down
12 changes: 6 additions & 6 deletions spec/lib/vmdb/util_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,20 @@ def self.assert_zip_entry_from_path(expected_entry, path)
end

it ".add_zip_entry" do
require 'zip/zipfilesystem'
file = "/var/log/messages.log"
entry = "ROOT/var/log/messages.log"
mtime = Time.parse("2013-09-24 09:00:45 -0400")
expect(File).to receive(:mtime).with(file).and_return(mtime)
expect(File).to receive(:directory?).with(file).and_return(false)
expect(described_class).to receive(:zip_entry_from_path).with(file).and_return(entry)

zip = double
expect(zip).to receive(:add).with(entry, file)
zip = double
ztime = Zip::DOSTime.at(mtime.to_i)
zip_entry = Zip::Entry.new(zip, entry, nil, nil, nil, nil, nil, nil, ztime)
expect(zip).to receive(:add).with(zip_entry, file)
zip_file = double
expect(zip_file).to receive(:utime).with(mtime, entry)
expect(zip).to receive(:file).and_return(zip_file)

expect(described_class.add_zip_entry(zip, file)).to eq([entry, mtime])
expect(described_class.add_zip_entry(zip, file, zip_file)).to eq([entry, mtime])
end

it ".get_evm_log_for_date" do
Expand Down

0 comments on commit bb62d68

Please sign in to comment.