summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfreddy2659 <50930342+freddy2659@users.noreply.github.com>2023-12-06 00:34:56 +0100
committerCalum Lind <calumlind+deluge@gmail.com>2024-01-21 16:18:29 +0100
commit7f70d6c6ff3d9a21fd33fd1097dd5b3dd8a16d4a (patch)
tree10a6194777914d8a05d23cabd8ebcb54e8ffdfff
parent[Docs] Bump sphinx version requirements (diff)
downloaddeluge-7f70d6c6ff3d9a21fd33fd1097dd5b3dd8a16d4a.tar.xz
deluge-7f70d6c6ff3d9a21fd33fd1097dd5b3dd8a16d4a.zip
[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
-rw-r--r--deluge/ui/web/json_api.py5
1 files changed, 4 insertions, 1 deletions
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)