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

@@ -100,14 +100,16 @@ class Admin::BackupsController < Admin::AdminController
end
def upload_chunk
filename = params.fetch(:resumableFilename)
return render nothing:true, status: 415 unless filename.to_s.end_with?(".tar.gz")
filename = params.fetch(:resumableFilename)
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