mirror of
https://github.com/mastodon/mastodon.git
synced 2024-08-20 21:08:15 -07:00
Extract methods for file movement in CLI::Upgrade
(#25120)
This commit is contained in:
parent
56c0babc0b
commit
937dc42f10
2 changed files with 25 additions and 23 deletions
|
@ -75,12 +75,6 @@ Metrics/AbcSize:
|
||||||
- 'lib/mastodon/cli/*.rb'
|
- 'lib/mastodon/cli/*.rb'
|
||||||
- db/*migrate/**/*
|
- db/*migrate/**/*
|
||||||
|
|
||||||
# Reason:
|
|
||||||
# https://docs.rubocop.org/rubocop/cops_metrics.html#metricsblocknesting
|
|
||||||
Metrics/BlockNesting:
|
|
||||||
Exclude:
|
|
||||||
- 'lib/mastodon/cli/*.rb'
|
|
||||||
|
|
||||||
# Reason: Currently disabled in .rubocop_todo.yml
|
# Reason: Currently disabled in .rubocop_todo.yml
|
||||||
# https://docs.rubocop.org/rubocop/cops_metrics.html#metricscyclomaticcomplexity
|
# https://docs.rubocop.org/rubocop/cops_metrics.html#metricscyclomaticcomplexity
|
||||||
Metrics/CyclomaticComplexity:
|
Metrics/CyclomaticComplexity:
|
||||||
|
|
|
@ -125,27 +125,12 @@ module Mastodon::CLI
|
||||||
progress.log("Moving #{previous_path} to #{upgraded_path}") if options[:verbose]
|
progress.log("Moving #{previous_path} to #{upgraded_path}") if options[:verbose]
|
||||||
|
|
||||||
begin
|
begin
|
||||||
unless dry_run?
|
move_previous_to_upgraded
|
||||||
FileUtils.mkdir_p(File.dirname(upgraded_path))
|
|
||||||
FileUtils.mv(previous_path, upgraded_path)
|
|
||||||
|
|
||||||
begin
|
|
||||||
FileUtils.rmdir(File.dirname(previous_path), parents: true)
|
|
||||||
rescue Errno::ENOTEMPTY
|
|
||||||
# OK
|
|
||||||
end
|
|
||||||
end
|
|
||||||
rescue => e
|
rescue => e
|
||||||
progress.log(pastel.red("Error processing #{previous_path}: #{e}"))
|
progress.log(pastel.red("Error processing #{previous_path}: #{e}"))
|
||||||
success = false
|
success = false
|
||||||
|
|
||||||
unless dry_run?
|
remove_directory
|
||||||
begin
|
|
||||||
FileUtils.rmdir(File.dirname(upgraded_path), parents: true)
|
|
||||||
rescue Errno::ENOTEMPTY
|
|
||||||
# OK
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -155,5 +140,28 @@ module Mastodon::CLI
|
||||||
attachment.instance_write(:storage_schema_version, previous_storage_schema_version)
|
attachment.instance_write(:storage_schema_version, previous_storage_schema_version)
|
||||||
success
|
success
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def move_previous_to_upgraded(previous_path, upgraded_path)
|
||||||
|
return if dry_run?
|
||||||
|
|
||||||
|
FileUtils.mkdir_p(File.dirname(upgraded_path))
|
||||||
|
FileUtils.mv(previous_path, upgraded_path)
|
||||||
|
|
||||||
|
begin
|
||||||
|
FileUtils.rmdir(File.dirname(previous_path), parents: true)
|
||||||
|
rescue Errno::ENOTEMPTY
|
||||||
|
# OK
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def remove_directory(path)
|
||||||
|
return if dry_run?
|
||||||
|
|
||||||
|
begin
|
||||||
|
FileUtils.rmdir(File.dirname(path), parents: true)
|
||||||
|
rescue Errno::ENOTEMPTY
|
||||||
|
# OK
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue