From 56791df57e2e6226436005a4e2a9aa15211f612f Mon Sep 17 00:00:00 2001 From: Veiko Aasa Date: Thu, 10 Oct 2024 09:42:34 +0300 Subject: [PATCH] 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 --- plinth/modules/syncthing/manifest.py | 4 ++- plinth/modules/syncthing/privileged.py | 28 +++++++++++++------ .../syncthing/tests/test_functional.py | 1 + 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/plinth/modules/syncthing/manifest.py b/plinth/modules/syncthing/manifest.py index 0c65840bd..82fab9d6c 100644 --- a/plinth/modules/syncthing/manifest.py +++ b/plinth/modules/syncthing/manifest.py @@ -48,7 +48,9 @@ clients = [{ backup = { 'secrets': { - 'directories': ['/var/lib/syncthing/.config'] + 'directories': [ + '/var/lib/syncthing/.config', '/var/lib/syncthing/.local' + ] }, 'services': ['syncthing@syncthing'] } diff --git a/plinth/modules/syncthing/privileged.py b/plinth/modules/syncthing/privileged.py index 8648af17e..f6b505c53 100644 --- a/plinth/modules/syncthing/privileged.py +++ b/plinth/modules/syncthing/privileged.py @@ -14,14 +14,18 @@ from plinth import action_utils from plinth.actions import privileged 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.""" aug = augeas.Augeas(flags=augeas.Augeas.NO_LOAD + augeas.Augeas.NO_MODL_AUTOLOAD) - aug.add_transform('Xml.lns', CONF_FILE) + aug.add_transform('Xml.lns', conf_file) aug.load() return aug @@ -54,26 +58,30 @@ def setup(): def setup_config(): """Make configuration changes.""" # wait until the configuration file is created by the syncthing daemon + conf_file_in_use = CONF_FILE timeout = 300 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 timeout = timeout - 1 time.sleep(1) - aug = augeas_load() + aug = augeas_load(conf_file_in_use) # disable authentication missing notification as FreedomBox itself # provides authentication auth_conf = ('/configuration/options/unackedNotificationID' '[#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 # if the user has not made a choice yet usage_conf = '/configuration/options/urAccepted/#text' - if aug.get('/files' + CONF_FILE + usage_conf) == '0': - aug.set('/files' + CONF_FILE + usage_conf, '-1') + if aug.get('/files' + conf_file_in_use + usage_conf) == '0': + aug.set('/files' + conf_file_in_use + usage_conf, '-1') conf_changed = True aug.save() @@ -84,5 +92,7 @@ def setup_config(): @privileged 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 + '/.local', ignore_errors=True) diff --git a/plinth/modules/syncthing/tests/test_functional.py b/plinth/modules/syncthing/tests/test_functional.py index e4aa90ef7..8d1804089 100644 --- a/plinth/modules/syncthing/tests/test_functional.py +++ b/plinth/modules/syncthing/tests/test_functional.py @@ -48,6 +48,7 @@ class TestSyncthingApp(functional.BaseAppTests): 'test_syncthing') _remove_folder(session_browser, 'Test') + time.sleep(1) # Helps with browsing away in next step functional.backup_restore(session_browser, self.app_name, 'test_syncthing')