@@ -304,9 +304,15 @@ def download_filepath(self, filepath_hash):
304304 :return: hash (UUID) of the contents of the downloaded file or Nones
305305 """
306306
307- def _need_checksum (local_filepath ):
307+ def _need_checksum (local_filepath , expected_size ):
308308 limit = config .get ("filepath_checksum_size_limit" )
309- return limit is None or Path (local_filepath ).stat ().st_size < limit
309+ actual_size = Path (local_filepath ).stat ().st_size
310+ if expected_size != actual_size :
311+ # this should never happen without outside interference
312+ raise DataJointError (
313+ f"'{ local_filepath } ' downloaded but size did not match."
314+ )
315+ return limit is None or actual_size < limit
310316
311317 if filepath_hash is not None :
312318 relative_filepath , contents_hash , size = (
@@ -316,27 +322,24 @@ def _need_checksum(local_filepath):
316322 local_filepath = Path (self .spec ["stage" ]).absolute () / relative_filepath
317323
318324 file_exists = Path (local_filepath ).is_file () and (
319- not _need_checksum (local_filepath )
325+ not _need_checksum (local_filepath , size )
320326 or uuid_from_file (local_filepath ) == contents_hash
321327 )
322328
323329 if not file_exists :
324330 self ._download_file (external_path , local_filepath )
325- if _need_checksum (local_filepath ):
326- if uuid_from_file (local_filepath ) != contents_hash :
327- # this should never happen without outside interference
328- raise DataJointError (
329- f"'{ local_filepath } ' downloaded but did not pass checksum."
330- )
331- if not _need_checksum (local_filepath ):
332- logger .warning (
333- f"Skipped checksum for file with hash: { contents_hash } , and path: { local_filepath } "
334- )
335- if size != Path (local_filepath ).stat ().st_size :
331+ if (
332+ _need_checksum (local_filepath , size )
333+ and uuid_from_file (local_filepath ) != contents_hash
334+ ):
336335 # this should never happen without outside interference
337336 raise DataJointError (
338- f"'{ local_filepath } ' downloaded but size is not the same (skipped checksum due to config) ."
337+ f"'{ local_filepath } ' downloaded but did not pass checksum."
339338 )
339+ if not _need_checksum (local_filepath , size ):
340+ logger .warning (
341+ f"Skipped checksum for file with hash: { contents_hash } , and path: { local_filepath } "
342+ )
340343 return str (local_filepath ), contents_hash
341344
342345 # --- UTILITIES ---
0 commit comments