From 1170e438a3578ab53d01d4b4db1af5f069182684 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Fri, 15 Jan 2021 15:42:02 -0800 Subject: [PATCH] backups: repository: Introduce a prepare method Useful for abstracting the mount() operation that is not available on non-remote repositories. - On non-remote repositories do nothing. - On remote repositories, mount the location in preparation for operations on the repository. Tests performed: - When an SSH repository is unmounted before a schedule backup, it is automatically mounted for listing, backup and cleanup at scheduled time. Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- plinth/modules/backups/repository.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/plinth/modules/backups/repository.py b/plinth/modules/backups/repository.py index 13e4aad46..8d7aa91c9 100644 --- a/plinth/modules/backups/repository.py +++ b/plinth/modules/backups/repository.py @@ -126,6 +126,10 @@ class BaseBorgRepository(abc.ABC): """Return the repository that the backups action script should use.""" return self._path + @staticmethod + def prepare(): + """Prepare the repository for operations.""" + def get_info(self): """Return Borg information about a repository.""" output = self.run(['info', '--path', self.borg_path]) @@ -373,6 +377,13 @@ class SshBorgRepository(BaseBorgRepository): """ return self._mountpoint + def prepare(self): + """Prepare the repository for operations by mounting.""" + if not self.is_usable(): + raise errors.SshfsError('Remote host not verified') + + self.mount() + @property def hostname(self): """Return hostname from the remote path."""