diff options
author | Toon Claes <toon@gitlab.com> | 2019-02-28 19:57:34 +0100 |
---|---|---|
committer | Toon Claes <toon@gitlab.com> | 2019-02-28 19:57:34 +0100 |
commit | 62d7990b9bb30cf33ed87017c5c633d1cccc75c2 (patch) | |
tree | c3e1b69c58a412ba1c6f50a0337a23d9f9d6e1a4 /lib/backup/manager.rb | |
parent | f6453eca992a9c142268e78ac782cef98110d183 (diff) | |
download | gitlab-ce-tc-standard-gem.tar.gz |
Ran standardrb --fix on the whole codebasetc-standard-gem
Inspired by https://twitter.com/searls/status/1101137953743613952 I
decided to try https://github.com/testdouble/standard on our codebase.
It's opinionated, but at least it's a _standard_.
Diffstat (limited to 'lib/backup/manager.rb')
-rw-r--r-- | lib/backup/manager.rb | 60 |
1 files changed, 30 insertions, 30 deletions
diff --git a/lib/backup/manager.rb b/lib/backup/manager.rb index 06b0338b1ed..52fbbbda382 100644 --- a/lib/backup/manager.rb +++ b/lib/backup/manager.rb @@ -4,7 +4,7 @@ module Backup class Manager ARCHIVES_TO_BACKUP = %w[uploads builds artifacts pages lfs registry].freeze FOLDERS_TO_BACKUP = %w[repositories db].freeze - FILE_NAME_SUFFIX = '_gitlab_backup.tar'.freeze + FILE_NAME_SUFFIX = "_gitlab_backup.tar" attr_reader :progress @@ -18,18 +18,18 @@ module Backup Dir.chdir(backup_path) do File.open("#{backup_path}/backup_information.yml", "w+") do |file| - file << backup_information.to_yaml.gsub(/^---\n/, '') + file << backup_information.to_yaml.gsub(/^---\n/, "") end # create archive progress.print "Creating backup archive: #{tar_file} ... " # Set file permissions on open to prevent chmod races. - tar_system_options = { out: [tar_file, 'w', Gitlab.config.backup.archive_permissions] } - if Kernel.system('tar', '-cf', '-', *backup_contents, tar_system_options) + tar_system_options = {out: [tar_file, "w", Gitlab.config.backup.archive_permissions]} + if Kernel.system("tar", "-cf", "-", *backup_contents, tar_system_options) progress.puts "done".color(:green) else puts "creating archive #{tar_file} failed".color(:red) - raise Backup::Error, 'Backup failed' + raise Backup::Error, "Backup failed" end upload @@ -55,7 +55,7 @@ module Backup progress.puts "done".color(:green) else puts "uploading backup to #{remote_directory} failed".color(:red) - raise Backup::Error, 'Backup failed' + raise Backup::Error, "Backup failed" end end @@ -69,7 +69,7 @@ module Backup progress.puts "done".color(:green) else puts "deleting tmp directory '#{dir}' failed".color(:red) - raise Backup::Error, 'Backup failed' + raise Backup::Error, "Backup failed" end end end @@ -118,35 +118,35 @@ module Backup progress.puts "Please make sure that file name ends with #{FILE_NAME_SUFFIX}" exit 1 elsif backup_file_list.many? && ENV["BACKUP"].nil? - progress.puts 'Found more than one backup:' + progress.puts "Found more than one backup:" # print list of available backups progress.puts " " + available_timestamps.join("\n ") - progress.puts 'Please specify which one you want to restore:' - progress.puts 'rake gitlab:backup:restore BACKUP=timestamp_of_backup' + progress.puts "Please specify which one you want to restore:" + progress.puts "rake gitlab:backup:restore BACKUP=timestamp_of_backup" exit 1 end - tar_file = if ENV['BACKUP'].present? - "#{ENV['BACKUP']}#{FILE_NAME_SUFFIX}" - else - backup_file_list.first - end + tar_file = if ENV["BACKUP"].present? + "#{ENV["BACKUP"]}#{FILE_NAME_SUFFIX}" + else + backup_file_list.first + end unless File.exist?(tar_file) progress.puts "The backup file #{tar_file} does not exist!" exit 1 end - progress.print 'Unpacking backup ... ' + progress.print "Unpacking backup ... " - unless Kernel.system(*%W(tar -xf #{tar_file})) - progress.puts 'unpacking backup failed'.color(:red) - exit 1 + if Kernel.system("tar", "-xf", tar_file.to_s) + progress.puts "done".color(:green) else - progress.puts 'done'.color(:green) + progress.puts "unpacking backup failed".color(:red) + exit 1 end - ENV["VERSION"] = "#{settings[:db_version]}" if settings[:db_version].to_i > 0 + ENV["VERSION"] = settings[:db_version].to_s if settings[:db_version].to_i > 0 # restoring mismatching backups can lead to unexpected problems if settings[:gitlab_version] != Gitlab::VERSION @@ -164,12 +164,12 @@ module Backup end def tar_version - tar_version, _ = Gitlab::Popen.popen(%w(tar --version)) - tar_version.dup.force_encoding('locale').split("\n").first + tar_version, _ = Gitlab::Popen.popen(%w[tar --version]) + tar_version.dup.force_encoding("locale").split("\n").first end def skipped?(item) - settings[:skipped] && settings[:skipped].include?(item) || disabled_features.include?(item) + settings[:skipped]&.include?(item) || disabled_features.include?(item) end private @@ -183,7 +183,7 @@ module Backup end def available_timestamps - @backup_file_list.map {|item| item.gsub("#{FILE_NAME_SUFFIX}", "")} + @backup_file_list.map {|item| item.gsub(FILE_NAME_SUFFIX.to_s, "")} end def connect_to_remote_directory(connection_settings) @@ -205,8 +205,8 @@ module Backup end def remote_target - if ENV['DIRECTORY'] - File.join(ENV['DIRECTORY'], tar_file) + if ENV["DIRECTORY"] + File.join(ENV["DIRECTORY"], tar_file) else tar_file end @@ -226,7 +226,7 @@ module Backup def disabled_features features = [] - features << 'registry' unless Gitlab.config.registry.enabled + features << "registry" unless Gitlab.config.registry.enabled features end @@ -235,7 +235,7 @@ module Backup end def tar_file - @tar_file ||= "#{backup_information[:backup_created_at].strftime('%s_%Y_%m_%d_')}#{backup_information[:gitlab_version]}#{FILE_NAME_SUFFIX}" + @tar_file ||= "#{backup_information[:backup_created_at].strftime("%s_%Y_%m_%d_")}#{backup_information[:gitlab_version]}#{FILE_NAME_SUFFIX}" end def backup_information @@ -245,7 +245,7 @@ module Backup gitlab_version: Gitlab::VERSION, tar_version: tar_version, installation_type: Gitlab::INSTALLATION_TYPE, - skipped: ENV["SKIP"] + skipped: ENV["SKIP"], } end end |