From 0bf7519a8ac5a21b485bdcae7529ff1c26fcf442 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Fri, 16 Sep 2016 16:59:22 +0800 Subject: [PATCH] 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. --- lib/backup_restore/restorer.rb | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/backup_restore/restorer.rb b/lib/backup_restore/restorer.rb index 039936119a0..9089c61b4b9 100644 --- a/lib/backup_restore/restorer.rb +++ b/lib/backup_restore/restorer.rb @@ -114,18 +114,6 @@ module BackupRestore @meta_filename = File.join(@tmp_directory, BackupRestore::METADATA_FILE) @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 = [] @readonly_mode_was_enabled = Discourse.readonly_mode? end @@ -195,7 +183,7 @@ module BackupRestore log "Extracting metadata file..." @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 execute_command( 'tar', '--extract', '--file', @tar_filename, BackupRestore::METADATA_FILE, @@ -228,6 +216,18 @@ module BackupRestore end 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 log "Extracting dump file..."