From 35880a437007ceff4c0294252d676c368ce40c95 Mon Sep 17 00:00:00 2001 From: Mateusz Masiarz Date: Sun, 24 Sep 2023 16:56:26 +0200 Subject: [PATCH] Delete cached tests after contest type change --- src/sinol_make/commands/run/__init__.py | 3 +-- src/sinol_make/helpers/cache.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/sinol_make/commands/run/__init__.py b/src/sinol_make/commands/run/__init__.py index 3bc4d649..54dbe951 100644 --- a/src/sinol_make/commands/run/__init__.py +++ b/src/sinol_make/commands/run/__init__.py @@ -935,7 +935,6 @@ def set_group_result(solution, group, result): self.possible_score ) - if self.args.apply_suggestions: for solution in diff.removed_solutions: del config_expected_scores[solution] @@ -951,7 +950,6 @@ def set_group_result(solution, group, result): else: config_expected_scores[solution] = diff.new_expected_scores[solution] - self.config["sinol_expected_scores"] = self.convert_status_to_string(config_expected_scores) util.save_config(self.config) print(util.info("Saved suggested expected scores description.")) @@ -1129,6 +1127,7 @@ def run(self, args): print("Task: %s (tag: %s)" % (title, self.ID)) self.cpus = args.cpus or mp.cpu_count() cache.save_to_cache_extra_compilation_files(self.config.get("extra_compilation_files", []), self.ID) + cache.check_if_contest_type_changed(self.config.get("contest_type", "default")) checker = package_util.get_files_matching_pattern(self.ID, f'{self.ID}chk.*') if len(checker) != 0: diff --git a/src/sinol_make/helpers/cache.py b/src/sinol_make/helpers/cache.py index 5d9a6993..8a63af58 100644 --- a/src/sinol_make/helpers/cache.py +++ b/src/sinol_make/helpers/cache.py @@ -100,3 +100,23 @@ def save_to_cache_extra_compilation_files(extra_compilation_files, task_id): info.md5sum = md5sum info.save(file_path) + + +def check_if_contest_type_changed(contest_type): + """ + Checks if contest type has changed and removes all cached test results if it has. + :param contest_type: Contest type + """ + try: + with open(paths.get_cache_path("contest_type"), 'r') as cache_file: + cache_contest_type = cache_file.read().strip() + if cache_contest_type != contest_type: + for solution in os.listdir(paths.get_cache_path('md5sums')): + info = get_cache_file(solution) + info.tests = {} + info.save(solution) + except FileNotFoundError: + pass + os.makedirs(paths.get_cache_path(), exist_ok=True) + with open(paths.get_cache_path("contest_type"), 'w') as cache_file: + cache_file.write(contest_type)