From 0b9c4c92e94eb9860e5cba736f9b4c51039120c1 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Thu, 28 Jan 2021 16:16:27 -0800 Subject: [PATCH] minidlna: Implement force upgrading from older version Fixes: #2026. Upgrade from 1.2.1+dfsg-1+b1 to 1.3.x. Tests: - Install version 1.2.1+dfsg-1+b1. Change the default media directory. Run unattended upgrades it will fail to upgrade. With the new patch, run apt update. This will force upgrade. After upgrade the earlier set media directory is retained. - Functional tests run. Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- plinth/modules/minidlna/__init__.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/plinth/modules/minidlna/__init__.py b/plinth/modules/minidlna/__init__.py index 1a0bf6ba7..74b084216 100644 --- a/plinth/modules/minidlna/__init__.py +++ b/plinth/modules/minidlna/__init__.py @@ -11,6 +11,7 @@ from plinth.modules.apache.components import Webserver from plinth.modules.backups.components import BackupRestore from plinth.modules.firewall.components import Firewall from plinth.modules.users.components import UsersAndGroups +from plinth.utils import Version from . import manifest @@ -103,3 +104,20 @@ def get_media_dir(): def set_media_dir(media_dir): """Set the media directory from which files will be scanned for sharing.""" actions.superuser_run('minidlna', ['set-media-dir', '--dir', media_dir]) + + +def force_upgrade(helper, packages): + """Force upgrade minidlna to resolve conffile prompt.""" + if 'minidlna' not in packages: + return False + + # Allow upgrade from 1.2.1+dfsg-1+b1 to 1.3.x + package = packages['minidlna'] + if Version(package['new_version']) > Version('1.4~'): + return False + + media_dir = get_media_dir() + helper.install(['minidlna'], force_configuration='new') + set_media_dir(media_dir) + + return True