1616# under the License.
1717from __future__ import annotations
1818
19- import contextlib
2019import logging
2120from datetime import datetime , timedelta , timezone
2221from functools import reduce
@@ -89,12 +88,17 @@ def remove_orphaned_files(self, older_than: timedelta = timedelta(days=3), dry_r
8988 location = self .tbl .location ()
9089 orphaned_files = self .orphaned_files (location , older_than )
9190 logger .info (f"Found { len (orphaned_files )} orphaned files at { location } !" )
91+ deleted_files = set ()
92+ failed_to_delete_files = set ()
9293
9394 def _delete (file : str ) -> None :
9495 # don't error if the file doesn't exist
9596 # still catch ctrl-c, etc.
96- with contextlib . suppress ( Exception ) :
97+ try :
9798 self .tbl .io .delete (file )
99+ deleted_files .add (file )
100+ except Exception :
101+ failed_to_delete_files .add (file )
98102
99103 if orphaned_files :
100104 if dry_run :
@@ -104,4 +108,10 @@ def _delete(file: str) -> None:
104108 deletes = executor .map (_delete , orphaned_files )
105109 # exhaust
106110 list (deletes )
107- logger .info (f"Deleted { len (orphaned_files )} orphaned files at { location } !" )
111+ logger .info (f"Deleted { len (deleted_files )} orphaned files at { location } !" )
112+ logger .info (f"Files:\n { deleted_files } " )
113+ if failed_to_delete_files :
114+ logger .warning (f"Failed to delete { len (failed_to_delete_files )} orphaned files at { location } !" )
115+ logger .warning (f"Files:\n { failed_to_delete_files } " )
116+ else :
117+ logger .info (f"No orphaned files found at { location } !" )
0 commit comments