From 6681e4023198ca7c6c3cc634779e01ac3edae616 Mon Sep 17 00:00:00 2001 From: Xavier-Do Date: Wed, 4 Dec 2019 11:26:54 +0100 Subject: [PATCH] [FIX] runbot: better source cleaing A build can sometimes fail and be stuck in a running state without corresponding sources. In this case, source are not gc anymore This commit fixes that by always applying gc even when an inconsistency is detected. --- runbot/models/repo.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/runbot/models/repo.py b/runbot/models/repo.py index 0dbf1f76..d17cf9f7 100644 --- a/runbot/models/repo.py +++ b/runbot/models/repo.py @@ -647,17 +647,16 @@ class runbot_repo(models.Model): # we are comparing cannot_be_deleted_path with to keep to sensure that the algorithm is working, we want to avoid to erase file by mistake # note: it is possible that a parent_build is in testing without checkouting sources, but it should be exceptions if to_delete: - if cannot_be_deleted_path == to_keep: - to_delete = list(to_delete) - to_keep = list(to_keep) - cannot_be_deleted_path = list(cannot_be_deleted_path) - for source_dir in to_delete: - _logger.info('Deleting source: %s' % source_dir) - assert 'static' in source_dir - shutil.rmtree(source_dir) - _logger.info('%s/%s source folder where deleted (%s kept)' % (len(to_delete), len(to_delete+to_keep), len(to_keep))) - else: + if cannot_be_deleted_path != to_keep: _logger.warning('Inconsistency between sources and database: \n%s \n%s' % (cannot_be_deleted_path-to_keep, to_keep-cannot_be_deleted_path)) + to_delete = list(to_delete) + to_keep = list(to_keep) + cannot_be_deleted_path = list(cannot_be_deleted_path) + for source_dir in to_delete: + _logger.info('Deleting source: %s' % source_dir) + assert 'static' in source_dir + shutil.rmtree(source_dir) + _logger.info('%s/%s source folder where deleted (%s kept)' % (len(to_delete), len(to_delete+to_keep), len(to_keep))) except: _logger.error('An exception occured while cleaning sources')