From 1c486c65717307293b0270fe49fd8f5a96d56f14 Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Wed, 28 Sep 2022 19:27:25 +0530 Subject: [PATCH] Island: Modify delete_files_by_pattern -> delete_files_by_regex in LocalStorageFileRepository --- .../cc/repository/local_storage_file_repository.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/monkey/monkey_island/cc/repository/local_storage_file_repository.py b/monkey/monkey_island/cc/repository/local_storage_file_repository.py index 840ab1701..7f7be398c 100644 --- a/monkey/monkey_island/cc/repository/local_storage_file_repository.py +++ b/monkey/monkey_island/cc/repository/local_storage_file_repository.py @@ -1,5 +1,6 @@ -import glob import logging +import os +import re import shutil from pathlib import Path from typing import BinaryIO @@ -56,9 +57,10 @@ class LocalStorageFileRepository(IFileRepository): f'Error retrieving file "{unsafe_file_name}" from the repository: {err}' ) - def delete_files_by_pattern(self, file_name_pattern: str): - for file_name in glob.iglob(f"{self._storage_directory}/{file_name_pattern}"): - self.delete_file(file_name) + def delete_files_by_regex(self, file_name_regex: re.Pattern): + for file_name in os.listdir(self._storage_directory): + if re.match(file_name_regex, file_name): + self.delete_file(file_name) def delete_file(self, unsafe_file_name: str): try: