@@ -513,9 +513,17 @@ async def get_downloader(self, tree_id: bytes32, url: str) -> Optional[PluginRem
513
513
self .log .error (f"get_downloader could not get response: { type (e ).__name__ } : { e } " )
514
514
return None
515
515
516
- async def clean_old_full_tree_files (
517
- self , foldername : Path , tree_id : bytes32 , full_tree_first_publish_generation : int
518
- ) -> None :
516
+ async def clean_old_full_tree_files (self , tree_id : bytes32 ) -> None :
517
+ singleton_record : Optional [SingletonRecord ] = await self .wallet_rpc .dl_latest_singleton (tree_id , True )
518
+ if singleton_record is None :
519
+ return
520
+ await self ._update_confirmation_status (tree_id = tree_id )
521
+
522
+ root = await self .data_store .get_tree_root (tree_id = tree_id )
523
+ latest_generation = root .generation
524
+ full_tree_first_publish_generation = max (0 , latest_generation - self .maximum_full_file_count + 1 )
525
+ foldername = self .server_files_location
526
+
519
527
for generation in range (full_tree_first_publish_generation - 1 , 0 , - 1 ):
520
528
root = await self .data_store .get_tree_root (tree_id = tree_id , generation = generation )
521
529
file_exists = delete_full_file_if_exists (foldername , tree_id , root )
@@ -576,11 +584,6 @@ async def upload_files(self, tree_id: bytes32) -> None:
576
584
self .log .error (
577
585
f"Failed to upload files to, will retry later: { uploader } : { res_json } "
578
586
)
579
- await self .clean_old_full_tree_files (
580
- self .server_files_location ,
581
- tree_id ,
582
- full_tree_first_publish_generation ,
583
- )
584
587
except Exception as e :
585
588
self .log .error (f"Exception uploading files, will retry later: tree id { tree_id } " )
586
589
self .log .debug (f"Failed to upload files, cleaning local files: { type (e ).__name__ } : { e } " )
@@ -740,6 +743,7 @@ async def periodically_manage_data(self) -> None:
740
743
await self .update_subscriptions_from_wallet (subscription .tree_id )
741
744
await self .fetch_and_validate (subscription .tree_id )
742
745
await self .upload_files (subscription .tree_id )
746
+ await self .clean_old_full_tree_files (subscription .tree_id )
743
747
except Exception as e :
744
748
self .log .error (f"Exception while fetching data: { type (e )} { e } { traceback .format_exc ()} ." )
745
749
0 commit comments