A platform for community discussion. Free, open, simple.
Revert "FEATURE: admin/user exports are compressed using the zip format (#7784)"
romanrizzif89bd555763b
diff --git a/Gemfile b/Gemfileindex 85cabafff2c..b7507fed24c 100644--- a/Gemfile+++ b/Gemfile@@ -203,8 +203,6 @@ gem "sassc-rails"gem 'rotp'gem 'rqrcode'-gem 'rubyzip', require: false-gem 'sshkey', require: falsegem 'rchardet', require: falsediff --git a/Gemfile.lock b/Gemfile.lockindex f0faf0292b0..b81b19fa6a7 100644--- a/Gemfile.lock+++ b/Gemfile.lock@@ -351,7 +351,6 @@ GEMguess_html_encoding (>= 0.0.4)nokogiri (>= 1.6.0)ruby_dep (1.5.0)- rubyzip (1.2.3)safe_yaml (1.0.5)sanitize (5.0.0)crass (~> 1.0.2)@@ -517,7 +516,6 @@ DEPENDENCIESrubocopruby-profruby-readability- rubyzipsanitizesasscsassc-railsdiff --git a/app/assets/javascripts/admin/templates/modal/admin-install-theme.hbs b/app/assets/javascripts/admin/templates/modal/admin-install-theme.hbsindex 9a1e18d0e7f..153dbc9e8f1 100644--- a/app/assets/javascripts/admin/templates/modal/admin-install-theme.hbs+++ b/app/assets/javascripts/admin/templates/modal/admin-install-theme.hbs@@ -44,7 +44,7 @@{{#if local}}<div class="inputs">- <input onchange={{action "uploadLocaleFile"}} type="file" id="file-input" accept='.dcstyle.json,application/json,.tar.gz,application/x-gzip,.tar.zip,application/zip'><br>+ <input onchange={{action "uploadLocaleFile"}} type="file" id="file-input" accept='.dcstyle.json,application/json,.tar.gz,application/x-gzip'><br><span class="description">{{i18n 'admin.customize.theme.import_file_tip'}}</span></div>{{/if}}diff --git a/app/controllers/admin/themes_controller.rb b/app/controllers/admin/themes_controller.rbindex 4def5bd2149..5389269af87 100644--- a/app/controllers/admin/themes_controller.rb+++ b/app/controllers/admin/themes_controller.rb@@ -88,7 +88,7 @@ class Admin::ThemesController < Admin::AdminControllerrescue RemoteTheme::ImportError => erender_json_error e.messageend- elsif params[:bundle] || (params[:theme] && ["application/x-gzip", "application/gzip", "application/zip"].include?(params[:theme].content_type))+ elsif params[:bundle] || (params[:theme] && ["application/x-gzip", "application/gzip"].include?(params[:theme].content_type))# params[:bundle] used by theme CLI. params[:theme] used by admin UIbundle = params[:bundle] || params[:theme]theme_id = params[:theme_id]@@ -252,7 +252,6 @@ class Admin::ThemesController < Admin::AdminControllerexporter = ThemeStore::TgzExporter.new(@theme)file_path = exporter.package_filename-headers['Content-Length'] = File.size(file_path).to_ssend_data File.read(file_path),filename: File.basename(file_path),diff --git a/app/jobs/regular/export_csv_file.rb b/app/jobs/regular/export_csv_file.rbindex d8d3a7204ec..e1b57398c1a 100644--- a/app/jobs/regular/export_csv_file.rb+++ b/app/jobs/regular/export_csv_file.rb@@ -1,7 +1,6 @@# frozen_string_literal: truerequire 'csv'-require 'zip'require_dependency 'system_message'require_dependency 'upload_creator'@@ -54,19 +53,18 @@ module Jobs# ensure directory existsFileUtils.mkdir_p(UserExport.base_directory) unless Dir.exists?(UserExport.base_directory)- # Generate a compressed CSV file- csv_to_export = CSV.generate do |csv|+ # write to CSV file+ CSV.open(absolute_path, "w") do |csv|csv << get_header if @entity != "report"public_send(export_method).each { |d| csv << d }end- compressed_file_path = "#{absolute_path}.zip"- Zip::File.open(compressed_file_path, Zip::File::CREATE) do |zipfile|- zipfile.get_output_stream(file_name) { |f| f.puts csv_to_export }- end+ # compress CSV file+ system('gzip', '-5', absolute_path)# create uploadupload = nil+ compressed_file_path = "#{absolute_path}.gz"if File.exist?(compressed_file_path)File.open(compressed_file_path) do |file|diff --git a/config/locales/client.en.yml b/config/locales/client.en.ymlindex d450f80ff4e..aad6399c5f2 100644--- a/config/locales/client.en.yml+++ b/config/locales/client.en.yml@@ -3514,7 +3514,7 @@ en:delete_upload_confirm: "Delete this upload? (Theme CSS may stop working!)"import_web_tip: "Repository containing theme"import_web_advanced: "Advanced..."- import_file_tip: ".tar.gz, .tar.zip, or .dcstyle.json file containing theme"+ import_file_tip: ".tar.gz or .dcstyle.json file containing theme"is_private: "Theme is in a private git repository"remote_branch: "Branch name (optional)"public_key: "Grant the following public key access to the repo:"diff --git a/config/locales/server.en.yml b/config/locales/server.en.ymlindex 014c84bbb97..74a2b8ee614 100644--- a/config/locales/server.en.yml+++ b/config/locales/server.en.yml@@ -2668,7 +2668,7 @@ en:The above download link will be valid for 48 hours.- The data is compressed as a zip archive. If the archive does not extract itself when you open it, use the tool recommended here: https://www.7-zip.org/+ The data is compressed as a gzip archive. If the archive does not extract itself when you open it, use the tools recommended here: https://www.gzip.org/#faq4csv_export_failed:title: "CSV Export Failed"diff --git a/config/site_settings.yml b/config/site_settings.ymlindex f29155b64e5..1a9fbb94dd1 100644--- a/config/site_settings.yml+++ b/config/site_settings.yml@@ -1048,7 +1048,7 @@ files:list_type: compactexport_authorized_extensions:hidden: true- default: "zip"+ default: "gz"type: listlist_type: compactresponsive_post_image_sizes:diff --git a/lib/theme_store/tgz_exporter.rb b/lib/theme_store/tgz_exporter.rbindex d0d8cef27a7..824a874ab94 100644--- a/lib/theme_store/tgz_exporter.rb+++ b/lib/theme_store/tgz_exporter.rb@@ -1,7 +1,5 @@# frozen_string_literal: true-require 'zip'-module ThemeStore; endclass ThemeStore::TgzExporter@@ -60,19 +58,11 @@ class ThemeStore::TgzExporterprivatedef export_packageexport_to_folder-Dir.chdir(@temp_folder) dotar_filename = "#{@export_name}.tar"Discourse::Utils.execute_command('tar', '--create', '--file', tar_filename, @export_name, failure_message: "Failed to tar theme.")-- zip_filename = "#{tar_filename}.zip"- absolute_path = "#{@temp_folder}/#{tar_filename}"- Zip::File.open(zip_filename, Zip::File::CREATE) do |zipfile|- zipfile.add(tar_filename, absolute_path)- zipfile.close- end-- "#{absolute_path}.zip"+ Discourse::Utils.execute_command('gzip', '-5', tar_filename, failure_message: "Failed to gzip archive.")+ "#{@temp_folder}/#{tar_filename}.gz"endenddiff --git a/lib/theme_store/tgz_importer.rb b/lib/theme_store/tgz_importer.rbindex e6198ee46e7..5dfb0716e68 100644--- a/lib/theme_store/tgz_importer.rb+++ b/lib/theme_store/tgz_importer.rb@@ -1,7 +1,5 @@# frozen_string_literal: true-require 'zip'-module ThemeStore; endclass ThemeStore::TgzImporter@@ -15,21 +13,8 @@ class ThemeStore::TgzImporterdef import!FileUtils.mkdir(@temp_folder)-- if @filename.include?('.zip')- name = @filename.split('/').last.gsub('.zip', '')-- Dir.chdir(@temp_folder) do- Zip::File.open(@filename) do |zip_file|- zip_file.each { |entry| entry.extract(name) }- end-- Discourse::Utils.execute_command("tar", "-xvf", name, "--strip", "1")- end- else- Dir.chdir(@temp_folder) do- Discourse::Utils.execute_command("tar", "-xzvf", @filename, "--strip", "1")- end+ Dir.chdir(@temp_folder) do+ Discourse::Utils.execute_command("tar", "-xzvf", @filename, "--strip", "1")endrescue RuntimeErrorraise RemoteTheme::ImportError, I18n.t("themes.import_error.unpack_failed")diff --git a/spec/components/theme_store/tgz_exporter_spec.rb b/spec/components/theme_store/tgz_exporter_spec.rbindex 34dd280285d..b66bf6e1b08 100644--- a/spec/components/theme_store/tgz_exporter_spec.rb+++ b/spec/components/theme_store/tgz_exporter_spec.rb@@ -2,7 +2,6 @@require 'rails_helper'require 'theme_store/tgz_exporter'-require 'zip'describe ThemeStore::TgzExporter dolet!(:theme) do@@ -56,19 +55,13 @@ describe ThemeStore::TgzExporter dofilename = exporter.package_filenameFileUtils.cp(filename, dir)exporter.cleanup!- "#{dir}/discourse-header-icons.tar.zip"+ "#{dir}/discourse-header-icons.tar.gz"endit "exports the theme correctly" dopackage- file = 'discourse-header-icons.tar.zip'- dest = 'discourse-header-icons.tar'Dir.chdir("#{dir}") do- Zip::File.open(file) do |zip_file|- zip_file.each { |entry| entry.extract(dest) }- end-- `tar -xvf discourse-header-icons.tar 2> /dev/null`+ `tar -xzf discourse-header-icons.tar.gz`endDir.chdir("#{dir}/discourse-header-icons") dofolders = Dir.glob("**/*").reject { |f| File.file?(f) }@@ -128,7 +121,7 @@ describe ThemeStore::TgzExporter doexporter = ThemeStore::TgzExporter.new(theme)filename = exporter.package_filenameexporter.cleanup!- expect(filename).to end_with "/discourse-header-icons.tar.zip"+ expect(filename).to end_with "/discourse-header-icons.tar.gz"endenddiff --git a/spec/components/theme_store/tgz_importer_spec.rb b/spec/components/theme_store/tgz_importer_spec.rbindex ab2d982da6f..2986b1d2c9c 100644--- a/spec/components/theme_store/tgz_importer_spec.rb+++ b/spec/components/theme_store/tgz_importer_spec.rb@@ -4,46 +4,26 @@require 'rails_helper'require 'theme_store/tgz_importer'-require 'zip'describe ThemeStore::TgzImporter dobefore do@temp_folder = "#{Pathname.new(Dir.tmpdir).realpath}/discourse_theme_#{SecureRandom.hex}"-- FileUtils.mkdir(@temp_folder)- Dir.chdir(@temp_folder) do- FileUtils.mkdir('test/')- File.write("test/hello.txt", "hello world")- FileUtils.mkdir('test/a')- File.write("test/a/inner", "hello world inner")- endendafter doFileUtils.rm_rf @temp_folderend- it "can import a simple zipped theme" do- Dir.chdir(@temp_folder) do- `tar -cvf test.tar test/* 2> /dev/null`-- Zip::File.open('test.tar.zip', Zip::File::CREATE) do |zipfile|- zipfile.add('test.tar', "#{@temp_folder}/test.tar")- zipfile.close- end- end-- importer = ThemeStore::TgzImporter.new("#{@temp_folder}/test.tar.zip")- importer.import!-- expect(importer["hello.txt"]).to eq("hello world")- expect(importer["a/inner"]).to eq("hello world inner")+ it "can import a simple theme" do- importer.cleanup!- end+ FileUtils.mkdir(@temp_folder)- it "can import a simple gzipped theme" doDir.chdir(@temp_folder) do+ FileUtils.mkdir('test/')+ File.write("test/hello.txt", "hello world")+ FileUtils.mkdir('test/a')+ File.write("test/a/inner", "hello world inner")+`tar -cvzf test.tar.gz test/* 2> /dev/null`enddiff --git a/spec/components/validators/upload_validator_spec.rb b/spec/components/validators/upload_validator_spec.rbindex 9348c85e79a..e9a3dfe601a 100644--- a/spec/components/validators/upload_validator_spec.rb+++ b/spec/components/validators/upload_validator_spec.rb@@ -22,14 +22,14 @@ describe Validators::UploadValidator doit "allows 'gz' as extension when uploading export file" doSiteSetting.authorized_extensions = ""- expect(UploadCreator.new(csv_file, "#{filename}.zip", for_export: true).create_for(user.id)).to be_valid+ expect(UploadCreator.new(csv_file, "#{filename}.gz", for_export: true).create_for(user.id)).to be_validendit "allows uses max_export_file_size_kb when uploading export file" doSiteSetting.max_attachment_size_kb = "0"- SiteSetting.authorized_extensions = "zip"+ SiteSetting.authorized_extensions = "gz"- expect(UploadCreator.new(csv_file, "#{filename}.zip", for_export: true).create_for(user.id)).to be_valid+ expect(UploadCreator.new(csv_file, "#{filename}.gz", for_export: true).create_for(user.id)).to be_validenddescribe 'when allow_staff_to_upload_any_file_in_pm is true' dodiff --git a/spec/requests/admin/themes_controller_spec.rb b/spec/requests/admin/themes_controller_spec.rbindex 43cc16cd8b8..4f32a63e013 100644--- a/spec/requests/admin/themes_controller_spec.rb+++ b/spec/requests/admin/themes_controller_spec.rb@@ -51,10 +51,10 @@ describe Admin::ThemesController doexpect(response.status).to eq(200)# Save the output in a temp file (automatically cleaned up)- file = Tempfile.new('archive.tar.zip')+ file = Tempfile.new('archive.tar.gz')file.write(response.body)file.rewind- uploaded_file = Rack::Test::UploadedFile.new(file.path, "application/zip")+ uploaded_file = Rack::Test::UploadedFile.new(file.path, "application/x-gzip")# Now import it againexpect do