Joseph Nuthalapati 56a055639d
backups: Use new utility for handling file uploads
- Use dedicated directory for uploads

- Uploaded backup archives are owned by root and read-only (0o600)

Signed-off-by: Joseph Nuthalapati <njoseph@riseup.net>
[sunil: Fix checking the relativeness of file path before removing]
[sunil: Create backups upload path recursively]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2024-10-14 12:52:45 -07:00

27 lines
645 B
Python

# SPDX-License-Identifier: AGPL-3.0-or-later
"""
Decorators for the backup views.
"""
import functools
from . import privileged, SESSION_PATH_VARIABLE
def delete_tmp_backup_file(function):
"""Decorator to delete uploaded backup files.
XXX: Implement a better way to delete uploaded files.
"""
@functools.wraps(function)
def wrapper(request, *args, **kwargs):
path = request.session.get(SESSION_PATH_VARIABLE, None)
if path:
privileged.remove_uploaded_archive(path)
del request.session[SESSION_PATH_VARIABLE]
return function(request, *args, **kwargs)
return wrapper