From dc897c0bb9951b25e6685ad59a23dcfc8a604fa4 Mon Sep 17 00:00:00 2001 From: Jack Wilson Date: Sun, 7 Apr 2019 16:31:21 +1000 Subject: [PATCH 1/2] Catch OSError in prune_dirs Since `fnmatch_all` can raise `OSError`s, and we were already silently giving up in `prune_dirs` on some of these exception, just do more of the same. --- beets/util/__init__.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/beets/util/__init__.py b/beets/util/__init__.py index f3dedcb41..f5ad2da22 100644 --- a/beets/util/__init__.py +++ b/beets/util/__init__.py @@ -283,13 +283,13 @@ def prune_dirs(path, root=None, clutter=('.DS_Store', 'Thumbs.db')): continue clutter = [bytestring_path(c) for c in clutter] match_paths = [bytestring_path(d) for d in os.listdir(directory)] - if fnmatch_all(match_paths, clutter): - # Directory contains only clutter (or nothing). - try: + try: + if fnmatch_all(match_paths, clutter): + # Directory contains only clutter (or nothing). shutil.rmtree(directory) - except OSError: + else: break - else: + except OSError: break From 27599410e80b8941321319ae8479a1380bf94791 Mon Sep 17 00:00:00 2001 From: Carl Suster Date: Sun, 7 Apr 2019 16:39:28 +1000 Subject: [PATCH 2/2] Changelog for #3209 --- docs/changelog.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index b2c8437b6..43b6b20f6 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -195,6 +195,8 @@ Fixes: is long. Thanks to :user:`ray66`. :bug:`3207` :bug:`2752` +* Fix an unhandled exception when pruning empty directories. + :bug:`1996` :bug:`3209` .. _python-itunes: https://github.com/ocelma/python-itunes