diff --git a/lib/inputstreamhelper/utils.py b/lib/inputstreamhelper/utils.py index 16b6bd1b..dba2cbe9 100644 --- a/lib/inputstreamhelper/utils.py +++ b/lib/inputstreamhelper/utils.py @@ -355,9 +355,15 @@ def hardlink(src, dest): def remove_tree(path): - """Remove an entire directory tree""" + """Remove an entire directory tree and log any file not found errors.""" from shutil import rmtree - rmtree(compat_path(path)) + + try: + rmtree(compat_path(path)) + return True + except FileNotFoundError as e: + log(4, f"Error removing tree: {e}") + return False def parse_version(vstring): diff --git a/lib/inputstreamhelper/widevine/widevine.py b/lib/inputstreamhelper/widevine/widevine.py index a480fd4f..566eedf4 100644 --- a/lib/inputstreamhelper/widevine/widevine.py +++ b/lib/inputstreamhelper/widevine/widevine.py @@ -194,7 +194,11 @@ def remove_old_backups(bpath): while len(versions) > max_backups + 1: remove_version = str(versions[1] if versions[0] == parse_version(installed_version) else versions[0]) log(0, 'Removing oldest backup which is not installed: {version}', version=remove_version) - remove_tree(os.path.join(bpath, remove_version)) + removed = remove_tree(os.path.join(bpath, remove_version)) + if not removed: + log(4, 'Failed to remove {version} backup.', version=remove_version) + break + versions = sorted([parse_version(version) for version in listdir(bpath)]) return