From eb2b068176a203b5e1b09fd4c912bd7441c21664 Mon Sep 17 00:00:00 2001 From: Fabio Erculiani Date: Sun, 4 Sep 2011 10:49:59 +0200 Subject: [PATCH] [entropy.client] clean_downloaded_packages: catch exception if branch_dir is not a dir At the same time, also improve fault tolerance of get_removable_packages() --- .../entropy/client/interfaces/methods.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/libraries/entropy/client/interfaces/methods.py b/libraries/entropy/client/interfaces/methods.py index 5fdd4d047..39a11aeb4 100644 --- a/libraries/entropy/client/interfaces/methods.py +++ b/libraries/entropy/client/interfaces/methods.py @@ -1203,12 +1203,23 @@ class RepositoryMixin: def get_removable_packages(): removable_pkgs = set() for pkg_dir in repo_pkgs_dirs: - if not os.path.isdir(pkg_dir): + try: + pkg_dir_list = os.listdir(pkg_dir) + except OSError as err: + if err.errno not in (errno.ENOTDIR, errno.ENOENT): + raise + # pkg_dir is not a dir or doesn't exist continue - for branch in os.listdir(pkg_dir): + for branch in pkg_dir_list: branch_dir = os.path.join(pkg_dir, branch) - dir_repo_pkgs = set((os.path.join(branch_dir, x) \ - for x in os.listdir(branch_dir))) + try: + dir_repo_pkgs = set((os.path.join(branch_dir, x) \ + for x in os.listdir(branch_dir))) + except OSError as err: + if err.errno not in (errno.ENOTDIR, errno.ENOENT): + raise + # branch_dir is not a dir or doesn't exist + continue # filter out hostile paths dir_repo_pkgs = set((x for x in dir_repo_pkgs \ if os.path.realpath(x).startswith(branch_dir) \