syncthing: Fix app setup in Debian testing

Syncthing from Debian testing uses new config directory if the
legacy configuration folder doesn't exist.

Tests performed in stable and testing containers:
 - All syncthing tests pass when running twice.

Signed-off-by: Veiko Aasa <veiko17@disroot.org>
This commit is contained in:
Veiko Aasa 2024-10-10 09:42:34 +03:00
parent 7671f4a749
commit 56791df57e
No known key found for this signature in database
GPG Key ID: 478539CAE680674E
3 changed files with 23 additions and 10 deletions

View File

@ -48,7 +48,9 @@ clients = [{
backup = { backup = {
'secrets': { 'secrets': {
'directories': ['/var/lib/syncthing/.config'] 'directories': [
'/var/lib/syncthing/.config', '/var/lib/syncthing/.local'
]
}, },
'services': ['syncthing@syncthing'] 'services': ['syncthing@syncthing']
} }

View File

@ -14,14 +14,18 @@ from plinth import action_utils
from plinth.actions import privileged from plinth.actions import privileged
DATA_DIR = '/var/lib/syncthing' DATA_DIR = '/var/lib/syncthing'
CONF_FILE = DATA_DIR + '/.config/syncthing/config.xml' # legacy configuration file
CONF_FILE_LEGACY = DATA_DIR + '/.config/syncthing/config.xml'
# configuration file since Debian Trixie if '.config/syncthing' directory
# doesn't exist
CONF_FILE = DATA_DIR + '/.local/state/syncthing/config.xml'
def augeas_load(): def augeas_load(conf_file):
"""Initialize Augeas.""" """Initialize Augeas."""
aug = augeas.Augeas(flags=augeas.Augeas.NO_LOAD + aug = augeas.Augeas(flags=augeas.Augeas.NO_LOAD +
augeas.Augeas.NO_MODL_AUTOLOAD) augeas.Augeas.NO_MODL_AUTOLOAD)
aug.add_transform('Xml.lns', CONF_FILE) aug.add_transform('Xml.lns', conf_file)
aug.load() aug.load()
return aug return aug
@ -54,26 +58,30 @@ def setup():
def setup_config(): def setup_config():
"""Make configuration changes.""" """Make configuration changes."""
# wait until the configuration file is created by the syncthing daemon # wait until the configuration file is created by the syncthing daemon
conf_file_in_use = CONF_FILE
timeout = 300 timeout = 300
while timeout > 0: while timeout > 0:
if os.path.exists(CONF_FILE): if os.path.exists(CONF_FILE_LEGACY):
conf_file_in_use = CONF_FILE_LEGACY
break
elif os.path.exists(CONF_FILE):
break break
timeout = timeout - 1 timeout = timeout - 1
time.sleep(1) time.sleep(1)
aug = augeas_load() aug = augeas_load(conf_file_in_use)
# disable authentication missing notification as FreedomBox itself # disable authentication missing notification as FreedomBox itself
# provides authentication # provides authentication
auth_conf = ('/configuration/options/unackedNotificationID' auth_conf = ('/configuration/options/unackedNotificationID'
'[#text="authenticationUserAndPassword"]') '[#text="authenticationUserAndPassword"]')
conf_changed = bool(aug.remove('/files' + CONF_FILE + auth_conf)) conf_changed = bool(aug.remove('/files' + conf_file_in_use + auth_conf))
# disable usage reporting notification by declining reporting # disable usage reporting notification by declining reporting
# if the user has not made a choice yet # if the user has not made a choice yet
usage_conf = '/configuration/options/urAccepted/#text' usage_conf = '/configuration/options/urAccepted/#text'
if aug.get('/files' + CONF_FILE + usage_conf) == '0': if aug.get('/files' + conf_file_in_use + usage_conf) == '0':
aug.set('/files' + CONF_FILE + usage_conf, '-1') aug.set('/files' + conf_file_in_use + usage_conf, '-1')
conf_changed = True conf_changed = True
aug.save() aug.save()
@ -84,5 +92,7 @@ def setup_config():
@privileged @privileged
def uninstall(): def uninstall():
"""Remove configuration file when app is uninstalled.""" """Remove configuration directory when app is uninstalled."""
# legacy location
shutil.rmtree(DATA_DIR + '/.config', ignore_errors=True) shutil.rmtree(DATA_DIR + '/.config', ignore_errors=True)
shutil.rmtree(DATA_DIR + '/.local', ignore_errors=True)

View File

@ -48,6 +48,7 @@ class TestSyncthingApp(functional.BaseAppTests):
'test_syncthing') 'test_syncthing')
_remove_folder(session_browser, 'Test') _remove_folder(session_browser, 'Test')
time.sleep(1) # Helps with browsing away in next step
functional.backup_restore(session_browser, self.app_name, functional.backup_restore(session_browser, self.app_name,
'test_syncthing') 'test_syncthing')