@@ -278,6 +278,7 @@ def download_project(
278278 local_dir : str ,
279279 filter_glob : str = None ,
280280 throw_on_error : bool = False ,
281+ skip_existing : bool = False ,
281282 show_progress : bool = False ,
282283 ) -> List [Dict ]:
283284 """Download the specified project files into the destination dir.
@@ -297,6 +298,7 @@ def download_project(
297298 local_dir ,
298299 filter_glob ,
299300 throw_on_error ,
301+ skip_existing ,
300302 show_progress ,
301303 )
302304
@@ -477,6 +479,7 @@ def download_files(
477479 local_dir : str ,
478480 filter_glob : str = None ,
479481 throw_on_error : bool = False ,
482+ skip_existing : bool = False ,
480483 show_progress : bool = False ,
481484 ) -> List [Dict ]:
482485 """Download project files.
@@ -489,6 +492,7 @@ def download_files(
489492 filter_glob (str, optional): Download only files matching the glob pattern. If None download all. Defaults to None.
490493 throw_on_error (bool, optional): Throw if download error occurres. Defaults to False.
491494 show_progress (bool, optional): Show progress bar in the console. Defaults to False.
495+ skip_existing (bool, optional): Skip files if they already exist locally with same sha256 hash. Defaults to False.
492496
493497 Raises:
494498 QFieldCloudException: if throw_on_error is True, throw an error if a download request fails.
@@ -504,6 +508,19 @@ def download_files(
504508 for file in files :
505509 if fnmatch .fnmatch (file ["name" ], filter_glob ):
506510 file ["status" ] = FileTransferStatus .PENDING
511+
512+ local_filename = Path (f'{ local_dir } /{ file ["name" ]} ' )
513+ if skip_existing and local_filename .exists ():
514+
515+ sha256_hash = hashlib .sha256 ()
516+ with open (local_filename , 'rb' ) as f :
517+ for byte_block in iter (lambda : f .read (4096 ),b"" ):
518+ sha256_hash .update (byte_block )
519+
520+ if file ['sha256' ] == sha256_hash .hexdigest ():
521+ logging .info (f'Skip file "{ file ["name" ]} " because it already exists locally' )
522+ continue
523+
507524 files_to_download .append (file )
508525
509526 for file in files_to_download :
0 commit comments