diff --git a/plinth/modules/backups/views.py b/plinth/modules/backups/views.py index f176d6627..be58772e1 100644 --- a/plinth/modules/backups/views.py +++ b/plinth/modules/backups/views.py @@ -143,9 +143,11 @@ class UploadArchiveView(SuccessMessageMixin, FormView): context['title'] = _('Upload and restore a backup file') context['subsubmenu'] = subsubmenu try: - disk_info = storage.get_disk_info('/', self.request) - except (PlinthError, PermissionError): - logger.error('Error getting information about root partition.') + disk_info = storage.get_disk_info('/') + except PlinthError as exception: + logger.exception( + 'Error getting information about root partition: %s', + exception) else: # The maximum file size that can be uploaded and restored is at # most half of the available disk space: diff --git a/plinth/modules/storage/__init__.py b/plinth/modules/storage/__init__.py index 9bf86f1c0..3a4c0fc54 100644 --- a/plinth/modules/storage/__init__.py +++ b/plinth/modules/storage/__init__.py @@ -142,14 +142,13 @@ def get_filesystem_type(mount_point='/'): raise ValueError('No such mount point') -def get_disk_info(mountpoint, request): +def get_disk_info(mount_point): """Get information about the free space of a drive""" - if not is_user_admin(request, cached=True): - raise PermissionError disks = get_disks() - list_root = [disk for disk in disks if disk['mountpoint'] == mountpoint] + list_root = [disk for disk in disks if disk['mountpoint'] == mount_point] if not list_root: - raise PlinthError + raise PlinthError('Mount point {} not found.'.format(mount_point)) + percent_used = list_root[0]['percent_used'] free_bytes = list_root[0]['free'] free_gib = free_bytes / (1024**3) diff --git a/plinth/modules/storage/views.py b/plinth/modules/storage/views.py index 75cd70579..78f3a5b5e 100644 --- a/plinth/modules/storage/views.py +++ b/plinth/modules/storage/views.py @@ -32,7 +32,7 @@ from django.views.decorators.http import require_POST from plinth import actions from plinth.errors import PlinthError from plinth.modules import storage -from plinth.utils import format_lazy +from plinth.utils import format_lazy, is_user_admin from . import get_disk_info, get_error_message @@ -91,10 +91,14 @@ def expand_partition(request, device): def warn_about_low_disk_space(request): """Warn about insufficient space on root partition.""" + if not is_user_admin(request, cached=True): + return + try: - root_info = get_disk_info('/', request) - except (PlinthError, PermissionError): - logger.error('Error getting information about root partition.') + root_info = get_disk_info('/') + except PlinthError as exception: + logger.exception('Error getting information about root partition: %s', + exception) return message = format_lazy(