rubocop: fix various style issues.
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
class StorageManager::SFTP < StorageManager
|
||||
DEFAULT_PERMISSIONS = 0644
|
||||
DEFAULT_PERMISSIONS = 0o644
|
||||
|
||||
# http://net-ssh.github.io/net-ssh/Net/SSH.html#method-c-start
|
||||
DEFAULT_SSH_OPTIONS = {
|
||||
timeout: 10,
|
||||
logger: Rails.logger,
|
||||
verbose: :fatal,
|
||||
non_interactive: true,
|
||||
non_interactive: true
|
||||
}
|
||||
|
||||
attr_reader :hosts, :ssh_options
|
||||
@@ -22,22 +22,20 @@ class StorageManager::SFTP < StorageManager
|
||||
dest_backup_path = dest_path + "-" + SecureRandom.uuid + ".bak"
|
||||
|
||||
each_host do |host, sftp|
|
||||
begin
|
||||
sftp.upload!(file.path, temp_upload_path)
|
||||
sftp.setstat!(temp_upload_path, permissions: DEFAULT_PERMISSIONS)
|
||||
sftp.upload!(file.path, temp_upload_path)
|
||||
sftp.setstat!(temp_upload_path, permissions: DEFAULT_PERMISSIONS)
|
||||
|
||||
# `rename!` can't overwrite existing files, so if a file already exists
|
||||
# at dest_path we move it out of the way first.
|
||||
force { sftp.rename!(dest_path, dest_backup_path) }
|
||||
force { sftp.rename!(temp_upload_path, dest_path) }
|
||||
rescue StandardError => e
|
||||
# if anything fails, try to move the original file back in place (if it was moved).
|
||||
force { sftp.rename!(dest_backup_path, dest_path) }
|
||||
raise Error, e
|
||||
ensure
|
||||
force { sftp.remove!(temp_upload_path) }
|
||||
force { sftp.remove!(dest_backup_path) }
|
||||
end
|
||||
# `rename!` can't overwrite existing files, so if a file already exists
|
||||
# at dest_path we move it out of the way first.
|
||||
force { sftp.rename!(dest_path, dest_backup_path) }
|
||||
force { sftp.rename!(temp_upload_path, dest_path) }
|
||||
rescue StandardError => e
|
||||
# if anything fails, try to move the original file back in place (if it was moved).
|
||||
force { sftp.rename!(dest_backup_path, dest_path) }
|
||||
raise Error, e
|
||||
ensure
|
||||
force { sftp.remove!(temp_upload_path) }
|
||||
force { sftp.remove!(dest_backup_path) }
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user