tor, torproxy: Avoid error if defaults file missing during uninstall

See:
https://discuss.freedombox.org/t/error-when-uninstalling-tor-and-tor-proxy/4295

sunil: Use pathlib.Path.unlink()

Tests:

- Install Tor and Tor Proxy. Uninstall both. Uninstall is succesful.

- Install Tor and Tor Proxy. Manually delete
  /var/run/tor-instances/*.defaults. Uninstall both apps. Uninstall is
  successful. A warning is printed in the logs.

Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
James Valleroy 2026-07-11 15:39:06 -04:00 committed by Sunil Mohan Adapa
parent fce97a871a
commit 10069c4e5d
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2
2 changed files with 7 additions and 3 deletions

View File

@ -494,5 +494,7 @@ def uninstall():
for directory in directories:
shutil.rmtree(directory, ignore_errors=True)
os.unlink(f'/var/run/tor-instances/{INSTANCE_NAME}.defaults')
defaults_file = f'/var/run/tor-instances/{INSTANCE_NAME}.defaults'
pathlib.Path(defaults_file).unlink(missing_ok=True)
action_utils.service_unmask(SERVICE_NAME)

View File

@ -2,7 +2,7 @@
"""Configure Tor Proxy service."""
import logging
import os
import pathlib
import shutil
from typing import Any
@ -190,5 +190,7 @@ def uninstall():
for directory in directories:
shutil.rmtree(directory, ignore_errors=True)
os.unlink(f'/var/run/tor-instances/{INSTANCE_NAME}.defaults')
defaults_file = f'/var/run/tor-instances/{INSTANCE_NAME}.defaults'
pathlib.Path(defaults_file).unlink(missing_ok=True)
action_utils.service_unmask(SERVICE_NAME)