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