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 <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2019-08-29 14:45:09 -07:00 committed by James Valleroy
parent 9db1f186cd
commit 1d031c97f1
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808

View File

@ -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):