From 8a3bdd9b0ecf787bbdeb421936ce60a705b863c7 Mon Sep 17 00:00:00 2001 From: emilsvennesson Date: Sat, 5 Oct 2024 20:09:11 +0200 Subject: [PATCH 1/3] catch fnf errors in utils --- lib/inputstreamhelper/utils.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/inputstreamhelper/utils.py b/lib/inputstreamhelper/utils.py index 16b6bd1b..a7353050 100644 --- a/lib/inputstreamhelper/utils.py +++ b/lib/inputstreamhelper/utils.py @@ -355,9 +355,13 @@ 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)) + except FileNotFoundError as e: + log(4, f'Error removing tree: {e}') def parse_version(vstring): From 4bbbae912fa08d90a020e0baf538b77aa2ee82f0 Mon Sep 17 00:00:00 2001 From: emilsvennesson Date: Sat, 5 Oct 2024 21:13:58 +0200 Subject: [PATCH 2/3] return rmtree remove result --- lib/inputstreamhelper/utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/inputstreamhelper/utils.py b/lib/inputstreamhelper/utils.py index a7353050..dba2cbe9 100644 --- a/lib/inputstreamhelper/utils.py +++ b/lib/inputstreamhelper/utils.py @@ -360,8 +360,10 @@ def remove_tree(path): try: rmtree(compat_path(path)) + return True except FileNotFoundError as e: - log(4, f'Error removing tree: {e}') + log(4, f"Error removing tree: {e}") + return False def parse_version(vstring): From d53b923cc3f23b50d460ee311aea3b8dafa52719 Mon Sep 17 00:00:00 2001 From: emilsvennesson Date: Sat, 5 Oct 2024 21:14:20 +0200 Subject: [PATCH 3/3] break out on failed backup removal --- lib/inputstreamhelper/widevine/widevine.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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