Skip to content

Commit

Permalink
Set Zip Entry Utime Correctly
Browse files Browse the repository at this point in the history
The interface to change the utime on an entry in a zipfile has
changed between RubyZip 0.9.5 and 1.2.

Instead of calling zip.add with a filename and zip.file.utime with a File.mtime,
convert the mtime to a Zip::DOSTime, and create a new Zip Entry, setting the
time on the entry initializer.  Then call zip.add with the Entry rather than the name.
  • Loading branch information
jerryk55 committed Feb 29, 2016
1 parent 8090f60 commit 46155b3
Showing 1 changed file with 9 additions and 4 deletions.
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

0 comments on commit 46155b3

Please sign in to comment.