storage: Use mount info instead of disk info for free space warning

Tests:

- In a container, fill up space. Start FreedomBox in develop mode wait 3 minutes
for storage warning to show.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa authored and James Valleroy committed 2020-06-27 11:00:50 -04:00
1 parent 64ff37e83f
commit c3eac2c02e
2 files changed
+12 -7

No files matched your search

+5 -2
View File
@@ -107,7 +107,7 @@ class UploadArchiveView(SuccessMessageMixin, FormView):
context = super().get_context_data(**kwargs)
context['title'] = _('Upload and restore a backup')
try:
disk_info = storage.get_disk_info('/')
mount_info = storage.get_mount_info('/')
except PlinthError as exception:
logger.exception(
'Error getting information about root partition: %s',
@@ -121,7 +121,7 @@ class UploadArchiveView(SuccessMessageMixin, FormView):
# - For restoring it's highly advisable to have at least as much
# free disk space as the file size.
context['max_filesize'] = storage.format_bytes(
disk_info['free_bytes'] / 2)
mount_info['free_bytes'] / 2)
return context
@@ -164,6 +164,7 @@ class BaseRestoreView(SuccessMessageMixin, FormView):
class RestoreFromUploadView(BaseRestoreView):
"""View to restore files from an (uploaded) exported archive."""
def get(self, *args, **kwargs):
path = self.request.session.get(SESSION_PATH_VARIABLE)
if not os.path.isfile(path):
@@ -193,6 +194,7 @@ class RestoreFromUploadView(BaseRestoreView):
class RestoreArchiveView(BaseRestoreView):
"""View to restore files from an archive."""
def _get_included_apps(self):
"""Save some data used to instantiate the form."""
name = unquote(self.kwargs['name'])
@@ -210,6 +212,7 @@ class RestoreArchiveView(BaseRestoreView):
class DownloadArchiveView(View):
"""View to export and download an archive as stream."""
def get(self, request, uuid, name):
repository = get_instance(uuid)
filename = f'{name}.tar.gz'
+7 -5
View File
@@ -156,10 +156,12 @@ def get_filesystem_type(mount_point='/'):
raise ValueError('No such mount point')
def get_disk_info(mount_point):
"""Get information about the free space of a drive"""
disks = get_disks()
list_root = [disk for disk in disks if mount_point in disk['mount_points']]
def get_mount_info(mount_point):
"""Get information about the free space of a mount point."""
mounts = get_mounts()
list_root = [
mount for mount in mounts if mount_point == mount['mount_point']
]
if not list_root:
raise PlinthError('Mount point {} not found.'.format(mount_point))
@@ -289,7 +291,7 @@ def warn_about_low_disk_space(request):
from plinth.notification import Notification
try:
root_info = get_disk_info('/')
root_info = get_mount_info('/')
except PlinthError:
return