From 854f383172b016fa3be76bc50f790b3b5b8751b8 Mon Sep 17 00:00:00 2001 From: Karchnu Date: Mon, 8 Jun 2020 20:03:17 +0200 Subject: [PATCH] Send the number of the next chunk to be uploaded. --- src/common/requests/errors.cr | 4 ++-- src/server/storage.cr | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/common/requests/errors.cr b/src/common/requests/errors.cr index 5dd0ccd..65171f6 100644 --- a/src/common/requests/errors.cr +++ b/src/common/requests/errors.cr @@ -20,9 +20,9 @@ class FileStorage::Errors property mid : String property reason = "Chunk already present" property filedigest : String - property chunk : Chunk + property next_chunk : Int32 - def initialize(@mid, @filedigest, @chunk) + def initialize(@mid, @filedigest, @next_chunk) end end FileStorage.errors << ChunkAlreadyUploaded diff --git a/src/server/storage.cr b/src/server/storage.cr index 23a0d6d..5ad8a05 100644 --- a/src/server/storage.cr +++ b/src/server/storage.cr @@ -105,8 +105,9 @@ class FileStorage::Storage if transfer_info.chunks.select do |v| v == chunk_number end.size == 1 write_a_chunk file_digest, chunk_size, chunk_number, data else - # TODO: send the remaining chunks to upload. - raise "non existent chunk or already uploaded" + # Send the next remaining chunk to upload. + next_chunk = transfer_info.chunks.sort.first + return FileStorage::Errors::ChunkAlreadyUploaded.new mid, file_digest, next_chunk end remove_chunk_from_db transfer_info, chunk_number