From 7f70d6c6ff3d9a21fd33fd1097dd5b3dd8a16d4a Mon Sep 17 00:00:00 2001 From: freddy2659 <50930342+freddy2659@users.noreply.github.com> Date: Tue, 5 Dec 2023 15:34:56 -0800 Subject: [PATCH] [WebUI] Fix progress divide by 0 error with empty dir If a dir exists with no contents then the following error occurred: ``` Traceback (most recent call last): ... File "/usr/lib/python3.10/site-packages/deluge/ui/web/json_api.py", line 608, in _on_got_files dirinfo['progress'] = sum(progresses) / dirinfo['size'] * 100 builtins.ZeroDivisionError: float division by zero ``` Closes: https://github.com/deluge-torrent/deluge/pull/439 --- deluge/ui/web/json_api.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/deluge/ui/web/json_api.py b/deluge/ui/web/json_api.py index 3f256140e..ea8105db4 100644 --- a/deluge/ui/web/json_api.py +++ b/deluge/ui/web/json_api.py @@ -600,7 +600,10 @@ class WebApi(JSONComponent): progresses = dirinfo.setdefault('progresses', []) progresses.append(torrent_file['size'] * torrent_file['progress'] / 100) - dirinfo['progress'] = sum(progresses) / dirinfo['size'] * 100 + if dirinfo['size'] > 0: + dirinfo['progress'] = sum(progresses) / dirinfo['size'] * 100 + else: + dirinfo['progress'] = 100 dirinfo['path'] = dirname dirname = os.path.dirname(dirname)