From 248e401988256d20e408c38556b98922426f8589 Mon Sep 17 00:00:00 2001 From: Jakub Kadlcik Date: Sep 16 2019 22:07:12 +0000 Subject: backend: expect removed directories while trying to list them While recursively walking through the results directory, expect that some of the directories may be deleted in the meantime. With this change, I was able to successfully finish a run of the `copr_print_results_to_delete.py` script on the production instance. --- diff --git a/backend/run/copr_print_results_to_delete.py b/backend/run/copr_print_results_to_delete.py index 4aef83b..b70080c 100755 --- a/backend/run/copr_print_results_to_delete.py +++ b/backend/run/copr_print_results_to_delete.py @@ -19,27 +19,30 @@ def main(): for ownername in os.listdir(config.destdir): ownerpath = os.path.join(config.destdir, ownername) - for projectname in os.listdir(ownerpath): - projectpath = os.path.join(ownerpath, projectname) - - # It may be a good idea, to not DoS attack the frontend - # Set whatever number of seconds is necessary - time.sleep(0) - - # If a project doesn't exist in frontend, it should be removed - try: - client.project_proxy.get(ownername=ownername, projectname=projectname) - except CoprNoResultException: - print(projectpath) - continue - - # If a chroot is not enabled in the project, it should be removed - for chroot in os.listdir(projectpath): - if chroot in ["srpm-builds", "modules"]: - continue - if not is_outdated_to_be_deleted(get_chroot_safe(client, ownername, projectname, chroot)): + try: + for projectname in os.listdir(ownerpath): + projectpath = os.path.join(ownerpath, projectname) + + # It may be a good idea, to not DoS attack the frontend + # Set whatever number of seconds is necessary + time.sleep(0) + + # If a project doesn't exist in frontend, it should be removed + try: + client.project_proxy.get(ownername=ownername, projectname=projectname) + except CoprNoResultException: + print(projectpath) continue - print(os.path.join(projectpath, chroot)) + + # If a chroot is not enabled in the project, it should be removed + for chroot in os.listdir(projectpath): + if chroot in ["srpm-builds", "modules"]: + continue + if not is_outdated_to_be_deleted(get_chroot_safe(client, ownername, projectname, chroot)): + continue + print(os.path.join(projectpath, chroot)) + except NotADirectoryError as ex: + print(str(ex)) def get_chroot_safe(client, ownername, projectname, chrootname):