From 11f58165ca34574cf23c088b1ff956e7523142e1 Mon Sep 17 00:00:00 2001 From: Karchnu Date: Sun, 14 Jun 2020 20:23:10 +0200 Subject: [PATCH] Better chunk print, bugfix. --- src/common/requests/transfer.cr | 2 ++ src/server/storage.cr | 19 +++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/common/requests/transfer.cr b/src/common/requests/transfer.cr index b974a68..9e16501 100644 --- a/src/common/requests/transfer.cr +++ b/src/common/requests/transfer.cr @@ -27,6 +27,8 @@ class FileStorage::Request user_data = filestoraged.get_user_data user.uid + puts "PutChunk request: #{@mid}, file #{@filedigest}, chunk: n=#{@chunk.n}, on=#{@chunk.on}, digest={@chunk.digest}" + filestoraged.storage.write_chunk self, user_data rescue e return Errors::GenericError.new @mid, e.to_s diff --git a/src/server/storage.cr b/src/server/storage.cr index 9593396..86a4780 100644 --- a/src/server/storage.cr +++ b/src/server/storage.cr @@ -108,9 +108,11 @@ class FileStorage::Storage else begin # Send the next remaining chunk to upload. - next_chunk = transfer_info.chunks.sort.first - return FileStorage::Errors::ChunkAlreadyUploaded.new mid, file_digest, next_chunk - rescue e : IndexError + chunks = transfer_info.chunks + if chunks.size != 0 + next_chunk = transfer_info.chunks.sort.first + return FileStorage::Errors::ChunkAlreadyUploaded.new mid, file_digest, next_chunk + end # In case the file was completely uploaded already. return FileStorage::Errors::FileFullyUploaded.new mid, path rescue e @@ -188,16 +190,21 @@ class FileStorage::Storage # First: check if the file already exists. transfer_info = @db_by_filedigest.get? file_digest if transfer_info.nil? + puts "new file: #{file_digest}" + # In case file informations aren't already registered # which is normal at this point. @db << TransferInfo.new user.uid, request.file else + puts "file already upload (at least partially): #{file_digest}" # File information already exists, request may be duplicated, # in this case: ignore the upload request. begin - next_chunk = transfer_info.chunks.sort.first - return FileStorage::Errors::FileExists.new mid, path, next_chunk - rescue e : IndexError + chunks = transfer_info.chunks + if chunks.size != 0 + next_chunk = chunks.sort.first + return FileStorage::Errors::FileExists.new mid, path, next_chunk + end # In case the file was completely uploaded already. return FileStorage::Errors::FileFullyUploaded.new mid, path rescue e