From c159c484ec68333c73b1153ab8a36838b5191fd8 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Wed, 28 Aug 2019 22:05:22 -0700 Subject: [PATCH] backups: Improve handling borg errors - Use regular expression search instead of string search. - Fix issue with incorrect password error not getting recognized properly. Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- plinth/modules/backups/repository.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/plinth/modules/backups/repository.py b/plinth/modules/backups/repository.py index cac8cdea4..092f724b4 100644 --- a/plinth/modules/backups/repository.py +++ b/plinth/modules/backups/repository.py @@ -23,6 +23,7 @@ import io import json import logging import os +import re from uuid import uuid1 from django.utils.translation import ugettext_lazy as _ @@ -64,12 +65,9 @@ KNOWN_ERRORS = [{ BorgRepositoryDoesNotExistError, }, { - 'errors': [('passphrase supplied in BORG_PASSPHRASE or by ' - 'BORG_PASSCOMMAND is incorrect')], - 'message': - _('Incorrect encryption passphrase'), - 'raise_as': - BorgError, + 'errors': [('passphrase supplied in .* is incorrect')], + 'message': _('Incorrect encryption passphrase'), + 'raise_as': BorgError, }, { 'errors': [('Connection reset by peer')], @@ -255,7 +253,7 @@ class BaseBorgRepository(abc.ABC): caught_error = str(err) for known_error in KNOWN_ERRORS: for error in known_error['errors']: - if error in caught_error: + if re.search(error, caught_error): raise known_error['raise_as'](known_error['message']) raise err