FIX: tar --list against a .tar.gz file takes too long.

This resulted in requests being blocked for an extended amount
of time when initializing the restorer.
This commit is contained in:
Guo Xiang Tan 2016-09-16 16:59:22 +08:00
parent a04dadf9b4
commit 0bf7519a8a

View File

@ -114,18 +114,6 @@ module BackupRestore
@meta_filename = File.join(@tmp_directory, BackupRestore::METADATA_FILE) @meta_filename = File.join(@tmp_directory, BackupRestore::METADATA_FILE)
@is_archive = !(@filename =~ /.sql.gz$/) @is_archive = !(@filename =~ /.sql.gz$/)
# For backwards compatibility
@dump_filename =
if @is_archive
if system('tar', '--list', '--file', @source_filename, BackupRestore::OLD_DUMP_FILE)
File.join(@tmp_directory, BackupRestore::OLD_DUMP_FILE)
else
File.join(@tmp_directory, BackupRestore::DUMP_FILE)
end
else
File.join(@tmp_directory, @filename)
end
@logs = [] @logs = []
@readonly_mode_was_enabled = Discourse.readonly_mode? @readonly_mode_was_enabled = Discourse.readonly_mode?
end end
@ -195,7 +183,7 @@ module BackupRestore
log "Extracting metadata file..." log "Extracting metadata file..."
@metadata = @metadata =
if system('tar', '--list', '--file', @source_filename, BackupRestore::METADATA_FILE) if system('tar', '--list', '--file', @tar_filename, BackupRestore::METADATA_FILE)
FileUtils.cd(@tmp_directory) do FileUtils.cd(@tmp_directory) do
execute_command( execute_command(
'tar', '--extract', '--file', @tar_filename, BackupRestore::METADATA_FILE, 'tar', '--extract', '--file', @tar_filename, BackupRestore::METADATA_FILE,
@ -228,6 +216,18 @@ module BackupRestore
end end
def extract_dump def extract_dump
@dump_filename =
if @is_archive
# For backwards compatibility
if system('tar', '--list', '--file', @tar_filename, BackupRestore::OLD_DUMP_FILE)
File.join(@tmp_directory, BackupRestore::OLD_DUMP_FILE)
else
File.join(@tmp_directory, BackupRestore::DUMP_FILE)
end
else
File.join(@tmp_directory, @filename)
end
return unless @is_archive return unless @is_archive
log "Extracting dump file..." log "Extracting dump file..."