Skip to content

Commit

Permalink
follow symlinks recursively when add entry to zip
Browse files Browse the repository at this point in the history
  • Loading branch information
Bo Yao committed Jun 26, 2017
1 parent 5d51aac commit 2063a76
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/vmdb/util.rb
Expand Up @@ -113,8 +113,11 @@ 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, zfile)
_log.info "Adding file: [#{entry}], size: [#{File.size(file)}], mtime: [#{mtime}]"
begin
entry, _mtime = add_zip_entry(zip, file, zfile)
rescue => e
_log.error "Failed to add file: [#{entry}]. Error information: #{e.message}"
end
end
end
zip.close
Expand All @@ -131,9 +134,13 @@ def self.add_zip_entry(zip, file_path, zfile)
ztime = Zip::DOSTime.at(mtime.to_i)
if File.directory?(file_path)
zip.mkdir(entry)
elsif File.symlink?(file_path)
zip_entry = Zip::Entry.new(zfile, entry, nil, nil, nil, nil, nil, nil, ztime)
zip.add(zip_entry, File.realpath(file_path))
else
zip_entry = Zip::Entry.new(zfile, entry, nil, nil, nil, nil, nil, nil, ztime)
zip.add(zip_entry, file_path)
_log.info "Adding file: [#{entry}], size: [#{File.size(file_path)}], mtime: [#{mtime}]"
end
return entry, mtime
end
Expand Down

0 comments on commit 2063a76

Please sign in to comment.