[Log] Fix crash logging to Windows protected folder

Have the log dir be a protected windows folder and Deluge crashes.
Windows blocks access to the dir and so it fails. It will fail trying to write
to any protected folder. Should probably just pass on the error maybe
and maybe log to stdout and log a message saying access was blocked or
something.

    .\deluge-debug -L debug -l E:\Documents\deluge.log
    ...
    Failed to execute script 'deluge-debug-script' due to unhandled exception!

Closes: https://dev.deluge-torrent.org/ticket/3502
Closes: https://github.com/deluge-torrent/deluge/pull/358
This commit is contained in:
doadin 2022-02-02 18:12:23 -05:00 committed by Calum Lind
parent 222aeed2f3
commit 8b0c8392b6
No known key found for this signature in database
GPG Key ID: 90597A687B836BA3

View File

@ -155,7 +155,12 @@ def setup_logger(
handler_cls = getattr( handler_cls = getattr(
logging.handlers, 'WatchedFileHandler', logging.FileHandler logging.handlers, 'WatchedFileHandler', logging.FileHandler
) )
handler = handler_cls(filename, mode=filemode, encoding='utf-8') try:
handler = handler_cls(filename, mode=filemode, encoding='utf-8')
except FileNotFoundError:
handler = logging.StreamHandler(stream=output_stream)
log = logging.getLogger(__name__)
log.error(f'Unable to write to log file `{filename}`')
else: else:
handler = logging.StreamHandler(stream=output_stream) handler = logging.StreamHandler(stream=output_stream)