Island: Modify delete_files_by_pattern -> delete_files_by_regex in LocalStorageFileRepository

This commit is contained in:
Shreya Malviya 2022-09-28 19:27:25 +05:30
parent c5d26749b7
commit 1c486c6571
1 changed files with 6 additions and 4 deletions

View File

@ -1,5 +1,6 @@
import glob
import logging import logging
import os
import re
import shutil import shutil
from pathlib import Path from pathlib import Path
from typing import BinaryIO from typing import BinaryIO
@ -56,8 +57,9 @@ class LocalStorageFileRepository(IFileRepository):
f'Error retrieving file "{unsafe_file_name}" from the repository: {err}' f'Error retrieving file "{unsafe_file_name}" from the repository: {err}'
) )
def delete_files_by_pattern(self, file_name_pattern: str): def delete_files_by_regex(self, file_name_regex: re.Pattern):
for file_name in glob.iglob(f"{self._storage_directory}/{file_name_pattern}"): for file_name in os.listdir(self._storage_directory):
if re.match(file_name_regex, file_name):
self.delete_file(file_name) self.delete_file(file_name)
def delete_file(self, unsafe_file_name: str): def delete_file(self, unsafe_file_name: str):