Skip to content

Commit

Permalink
rename extracted Folder by removing suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
jrief committed Oct 12, 2024
1 parent cf30b1c commit 73f06bf
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions finder/contrib/archive/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 73f06bf

Please sign in to comment.