mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-23 00:46:23 +00:00
fix: mejorar gestión de zip
This commit is contained in:
parent
1059ab5501
commit
51e11d38e4
1 changed files with 42 additions and 11 deletions
|
@ -14,24 +14,43 @@ class DeployZip < Deploy
|
|||
# y generar un zip accesible públicamente.
|
||||
#
|
||||
# rubocop:disable Metrics/MethodLength
|
||||
def deploy
|
||||
def deploy(output: false)
|
||||
FileUtils.rm_f path
|
||||
|
||||
time_start
|
||||
Dir.chdir(destination) do
|
||||
Zip::File.open(path, Zip::File::CREATE) do |z|
|
||||
Dir.glob('./**/**').each do |f|
|
||||
File.directory?(f) ? z.mkdir(f) : z.add(f, f)
|
||||
Zip::File.open(path, Zip::File::CREATE) do |zip|
|
||||
Dir.glob(File.join(destination, '**', '**')).each do |file|
|
||||
entry = Pathname.new(file).relative_path_from(destination).to_s
|
||||
|
||||
if File.directory? file
|
||||
log "Creando directorio #{entry}", output
|
||||
|
||||
zip.mkdir(entry)
|
||||
else
|
||||
log "Comprimiendo #{entry}", output
|
||||
zip.add(entry, file)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
time_stop
|
||||
|
||||
File.exist?(path).tap do |status|
|
||||
build_stats.create action: 'zip',
|
||||
seconds: time_spent_in_seconds,
|
||||
bytes: size
|
||||
bytes: size,
|
||||
log: @log.join("\n"),
|
||||
status: status
|
||||
end
|
||||
rescue Zip::Error => e
|
||||
ExceptionNotifier.notify_exception(e, data: { site: site.name })
|
||||
|
||||
File.exist? path
|
||||
build_stats.create action: 'zip',
|
||||
seconds: 0,
|
||||
bytes: 0,
|
||||
log: @log.join("\n"),
|
||||
status: false
|
||||
|
||||
false
|
||||
end
|
||||
# rubocop:enable Metrics/MethodLength
|
||||
|
||||
|
@ -43,8 +62,9 @@ class DeployZip < Deploy
|
|||
File.size path
|
||||
end
|
||||
|
||||
# @return [String]
|
||||
def destination
|
||||
File.join(Rails.root, '_deploy', site.hostname)
|
||||
Rails.root.join('_deploy', site.hostname).realpath.to_s
|
||||
end
|
||||
|
||||
def file
|
||||
|
@ -58,4 +78,15 @@ class DeployZip < Deploy
|
|||
def path
|
||||
File.join(destination, file)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# @param :line [String]
|
||||
# @param :output [Boolean]
|
||||
def log(line, output)
|
||||
@log ||= []
|
||||
@log << line
|
||||
|
||||
puts line if output
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue