From 73f06bfed533e0bc29b72d598baa2e508b0b4756 Mon Sep 17 00:00:00 2001 From: Jacob Rief Date: Sat, 12 Oct 2024 12:25:02 +0200 Subject: [PATCH] rename extracted Folder by removing suffix --- finder/contrib/archive/admin.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/finder/contrib/archive/admin.py b/finder/contrib/archive/admin.py index a2e6c99fa..4ecead6cb 100644 --- a/finder/contrib/archive/admin.py +++ b/finder/contrib/archive/admin.py @@ -101,16 +101,21 @@ def unarchive_file(self, request, file_id): if not (zip_file_obj := self.get_object(request, file_id)): return HttpResponseNotFound(f"File {file_id} not found.") realm = self.get_realm(request) + archive_name = pathlib.Path(zip_file_obj.name) + if archive_name.suffix in ['.zip', '.tar', '.tar.gz', '.gz']: + archive_name = archive_name.stem + else: + archive_name = str(archive_name) if FolderModel.objects.filter( - name=zip_file_obj.name, + name=archive_name, parent=zip_file_obj.folder, realm=realm, ).exists(): msg = gettext("Can not extract archive. A folder named “{name}” already exists.") - return HttpResponseBadRequest(msg.format(name=zip_file_obj.name), status=409) + return HttpResponseBadRequest(msg.format(name=archive_name), status=409) try: folder_obj = FolderModel.objects.create( - name=zip_file_obj.name, + name=archive_name, parent=zip_file_obj.folder, realm=realm, owner=request.user,