From 29ce3261afc67f13e8921edd35af67db43686bab Mon Sep 17 00:00:00 2001
From: Cristiano Urban <cristiano.urban@inaf.it>
Date: Fri, 14 Apr 2023 09:11:07 +0200
Subject: [PATCH] Avoid final empty block creation when file size is greater
 than block size.

Signed-off-by: Cristiano Urban <cristiano.urban@inaf.it>
---
 transfer_service/retrieve_executor.py | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/transfer_service/retrieve_executor.py b/transfer_service/retrieve_executor.py
index 1d14072..fa3b15c 100644
--- a/transfer_service/retrieve_executor.py
+++ b/transfer_service/retrieve_executor.py
@@ -14,7 +14,7 @@
 # * loop on each block and retrieve data
 #   - if the storage type is 'cold' (tape) perform a recall operation
 #     before the copy and a migrate operation after the copy
-#   - check if data associated to a VOSpace node has been copied 
+#   - check if data associated to a VOSpace node has been copied
 #     every time a block is retrieved
 #   - recursively update the 'async_trans' flag
 # * cleanup
@@ -191,16 +191,14 @@ class RetrieveExecutor(TaskExecutor):
                 #self.totalSize += fileSize
                 # check if the file is larger than a block size
                 if fileSize > self.maxBlockSize:
-                    # if the current block is not empty, "close" it, otherwise
-                    # use it and then create a new block
+                    # if the current block is not empty, "close" it,
+                    # otherwise use it
                     if blockSize > 0:
                         blockIdx += 1
                         fileInfo["blockIdx"] = blockIdx
-                        blockIdx += 1
                     else:
                         fileInfo["blockIdx"] = blockIdx
-                        blockIdx += 1
-                    blockSize = 0
+                    blockSize = self.maxBlockSize
                 else:
                     # the file can be contained by a block, so check if
                     # the file size plus the current block fill is lower
-- 
GitLab