use `unlink(missing_ok=True)`

Combine the `if exists` and `unlink` in one step and avoid any race
conditions with the file disappearing in between them.

Co-Authored-By: Florian Bruhin <me@the-compiler.org>
This commit is contained in:
toofar 2024-11-10 15:47:39 +13:00
parent 4dd36aca04
commit a085e3caa0
1 changed files with 6 additions and 7 deletions

View File

@ -418,13 +418,12 @@ def _clear_webengine_permissions_json():
because Qt will load the file during that.
"""
permissions_file = pathlib.Path(standarddir.data()) / "webengine" / "permissions.json"
if permissions_file.exists():
try:
permissions_file.unlink()
except OSError as err:
log.init.warning(
f"Error while cleaning up webengine permissions file: {err}"
)
try:
permissions_file.unlink(missing_ok=True)
except OSError as err:
log.init.warning(
f"Error while cleaning up webengine permissions file: {err}"
)
def _init_default_profile():