Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

catch fnf error in remove_tree gracefully #576

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/inputstreamhelper/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 5 additions & 1 deletion lib/inputstreamhelper/widevine/widevine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading