FEATURE: warn the user when there is not enough space on disk to upload a backup

This commit is contained in:
Régis Hanol 2014-02-26 19:38:06 +01:00
parent c6bc324259
commit 043901ef46
3 changed files with 14 additions and 4 deletions

View file

@ -101,13 +101,15 @@ class Admin::BackupsController < Admin::AdminController
def upload_chunk
filename = params.fetch(:resumableFilename)
return render nothing:true, status: 415 unless filename.to_s.end_with?(".tar.gz")
total_size = params.fetch(:resumableTotalSize).to_i
return render status: 415, text: I18n.t("backup.backup_file_should_be_tar_gz") unless filename.to_s.end_with?(".tar.gz")
return render status: 415, text: I18n.t("backup.not_enough_space_on_disk") unless has_enough_space_on_disk?(total_size)
file = params.fetch(:file)
identifier = params.fetch(:resumableIdentifier)
chunk_number = params.fetch(:resumableChunkNumber).to_i
chunk_size = params.fetch(:resumableChunkSize).to_i
total_size = params.fetch(:resumableTotalSize).to_i
current_chunk_size = params.fetch(:resumableCurrentChunkSize).to_i
# path to chunk file
@ -130,4 +132,10 @@ class Admin::BackupsController < Admin::AdminController
render nothing: true
end
private
def has_enough_space_on_disk?(size)
`df -l . | tail -1 | tr -s ' ' | cut -d ' ' -f 4`.to_i > size
end
end

View file

@ -1345,7 +1345,7 @@ en:
text: "UPLOAD"
uploading: "UPLOADING"
success: "'{{filename}}' has successfully been uploaded."
error: "There has been an error ({{message}}) while uploading '{{filename}}'"
error: "There has been an error while uploading '{{filename}}': {{message}}"
operations:
is_running: "An operation is currently running..."
failed: "The {{operation}} failed. Please check the logs."

View file

@ -27,6 +27,8 @@ en:
backup:
operation_already_running: "An operation is currently running. Can't start a new job right now."
backup_file_should_be_tar_gz: "The backup file should be a .tar.gz archive."
not_enough_space_on_disk: "There is not enough space on disk to upload this backup."
read_only_mode_enabled: "The site is in read only mode. Interactions are disabled."