From 1d031c97f19dfbde2ab04a732600b18af419e998 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Thu, 29 Aug 2019 14:45:09 -0700 Subject: [PATCH] backups: Don't show used disk choices when adding disk repo - Without this users can create multiple repositories for the same disk location. Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- plinth/modules/backups/forms.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/plinth/modules/backups/forms.py b/plinth/modules/backups/forms.py index e8ec09088..0ee35be3c 100644 --- a/plinth/modules/backups/forms.py +++ b/plinth/modules/backups/forms.py @@ -19,6 +19,7 @@ Forms for backups module. """ import logging +import os import re import subprocess @@ -162,9 +163,24 @@ encryption_fields = [ def get_disk_choices(): """Returns a list of all available partitions except the root partition.""" - return [(device['mount_point'], - device['label'] if device['label'] else device['mount_point']) - for device in get_disks() if device['mount_point'] != '/'] + repositories = get_repositories() + existing_paths = [ + repository.path for repository in repositories + if repository.storage_type == 'disk' + ] + choices = [] + for device in get_disks(): + if device['mount_point'] == '/': + continue + + path = os.path.join(device['mount_point'], 'FreedomBoxBackups') + if path in existing_paths: + continue + + name = device['label'] if device['label'] else device['mount_point'] + choices.append((device['mount_point'], name)) + + return choices class AddRepositoryForm(EncryptedBackupsMixin, forms.Form):