backups: Avoid creating duplicate SSH remotes

Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
This commit is contained in:
Joseph Nuthalapati committed 2019-07-03 12:40:51 +05:30
1 parent e618e08fe7
commit fb67c60a84
1 file changed
+6 -1
+6 -1
View File
@@ -154,7 +154,12 @@ class AddRepositoryForm(forms.Form):
path = cleaned_data.get("repository")
credentials = self.get_credentials()
# Validate remote
# Avoid creation of duplicate ssh remotes
for storage in network_storage.get_storages().values():
if storage['path'] == path:
raise forms.ValidationError(
_('Remote backup repository already exists.'))
user_at_host, dir_path = path.split(':')
username, hostname = user_at_host.split('@')
dir_path = dir_path.replace('~', f'/home/{username}')