cleanup_files

Function cleanup_files 

Source
pub async fn cleanup_files(
    target_links: &BTreeMap<String, String>,
    procurement_type: &ProcurementType,
    should_cleanup: bool,
    config: &ResolvedConfig,
) -> AppResult<()>
Expand description

Deletes ZIP files and extracted directories after processing.

This function removes temporary files created during the download and extraction phases, keeping only the final Parquet files. It’s typically called after successful parsing to free up disk space.

§Behavior

For each period in target_links, this function:

  • Deletes the ZIP file: {extract_dir}/{period}.zip
  • Deletes the extracted directory: {extract_dir}/{period}/ (recursively removes all XML/Atom files)

§Arguments

  • target_links - Map of period strings to URLs (determines which files to delete)
  • procurement_type - Procurement type determining the extraction directory
  • should_cleanup - If false, the function returns immediately without deleting anything
  • config - Resolved configuration containing directory paths

§Error Handling

Individual deletion errors are logged as warnings but do not fail the entire operation. The function continues processing remaining files even if some deletions fail.