[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
This commit is contained in:
freddy2659 2023-12-05 15:34:56 -08:00 committed by Calum Lind
parent b7450b5082
commit 7f70d6c6ff
No known key found for this signature in database
GPG Key ID: 90597A687B836BA3
1 changed files with 4 additions and 1 deletions

View File

@ -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)