@@ -121,7 +121,13 @@ def download_project_async(mc, project_path, directory, project_version=None):
121121 mp .log .info (f"--- start download { project_path } " )
122122
123123 try :
124- project_info = mc .project_info (project_path , version = project_version )
124+ # check whether we download the latest version or not
125+ latest_proj_info = mc .project_info (project_path )
126+ if project_version :
127+ project_info = mc .project_info (project_path , version = project_version )
128+ else :
129+ project_info = latest_proj_info
130+
125131 except ClientError :
126132 _cleanup_failed_download (directory , mp )
127133 raise
@@ -135,7 +141,8 @@ def download_project_async(mc, project_path, directory, project_version=None):
135141 for file in project_info ['files' ]:
136142 file ['version' ] = version
137143 items = _download_items (file , directory )
138- update_tasks .append (UpdateTask (file ['path' ], items ))
144+ is_latest_version = project_version == latest_proj_info ["version" ]
145+ update_tasks .append (UpdateTask (file ['path' ], items , latest_version = is_latest_version ))
139146
140147 # make a single list of items to download
141148 total_size = 0
@@ -234,10 +241,11 @@ class UpdateTask:
234241 """
235242
236243 # TODO: methods other than COPY
237- def __init__ (self , file_path , download_queue_items , destination_file = None ):
244+ def __init__ (self , file_path , download_queue_items , destination_file = None , latest_version = True ):
238245 self .file_path = file_path
239246 self .destination_file = destination_file
240247 self .download_queue_items = download_queue_items
248+ self .latest_version = latest_version
241249
242250 def apply (self , directory , mp ):
243251 """ assemble downloaded chunks into a single file """
@@ -251,8 +259,10 @@ def apply(self, directory, mp):
251259 dest_file_path = self .destination_file
252260 os .makedirs (file_dir , exist_ok = True )
253261
262+ # ignore check if we download not-latest version of gpkg file (possibly reconstructed on server on demand)
263+ check_size = self .latest_version or not mp .is_versioned_file (self .file_path )
254264 # merge chunks together (and delete them afterwards)
255- file_to_merge = FileToMerge (dest_file_path , self .download_queue_items )
265+ file_to_merge = FileToMerge (dest_file_path , self .download_queue_items , check_size )
256266 file_to_merge .merge ()
257267
258268 # Make a copy of the file to meta dir only if there is no user-specified path for the file.
@@ -483,9 +493,10 @@ class FileToMerge:
483493 to the temporary file containing its data. Calling merge() will create the destination file
484494 and remove the temporary files of the chunks
485495 """
486- def __init__ (self , dest_file , downloaded_items ):
496+ def __init__ (self , dest_file , downloaded_items , size_check = True ):
487497 self .dest_file = dest_file # full path to the destination file to be created
488498 self .downloaded_items = downloaded_items # list of pieces of the destination file to be merged
499+ self .size_check = size_check # whether we want to do merged file size check
489500
490501 def merge (self ):
491502 with open (self .dest_file , 'wb' ) as final :
@@ -494,6 +505,8 @@ def merge(self):
494505 shutil .copyfileobj (chunk , final )
495506 os .remove (item .download_file_path )
496507
508+ if not self .size_check :
509+ return
497510 expected_size = sum (item .size for item in self .downloaded_items )
498511 if os .path .getsize (self .dest_file ) != expected_size :
499512 os .remove (self .dest_file )
@@ -574,7 +587,11 @@ def download_file_async(mc, project_dir, file_path, output_file, version):
574587 project_path = mp .metadata ["name" ]
575588 ver_info = f"at version { version } " if version is not None else "at latest version"
576589 mp .log .info (f"Getting { file_path } { ver_info } " )
577- project_info = mc .project_info (project_path , version = version )
590+ latest_proj_info = mc .project_info (project_path )
591+ if version :
592+ project_info = mc .project_info (project_path , version = version )
593+ else :
594+ project_info = latest_proj_info
578595 mp .log .info (f"Got project info. version { project_info ['version' ]} " )
579596
580597 # set temporary directory for download
@@ -587,7 +604,8 @@ def download_file_async(mc, project_dir, file_path, output_file, version):
587604 if file ["path" ] == file_path :
588605 file ['version' ] = version
589606 items = _download_items (file , temp_dir )
590- task = UpdateTask (file ['path' ], items , output_file )
607+ is_latest_version = version == latest_proj_info ["version" ]
608+ task = UpdateTask (file ['path' ], items , output_file , latest_version = is_latest_version )
591609 download_list .extend (task .download_queue_items )
592610 for item in task .download_queue_items :
593611 total_size += item .size
0 commit comments