comparison MoinMoin/action/AttachFile.py @ 3705:ac48fad2e117

AttachFile action: catch runtime error raised by zipfile to not make attachments list unusable if someone attached a defective zip
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Thu, 12 Jun 2008 21:38:28 +0200
parents 9426f34f07b9
children f0532fa90c6d
comparison
equal deleted inserted replaced
3704:6b3274cd86c6 3705:ac48fad2e117
329 else: 329 else:
330 links.append(fmt.url(1, getAttachUrl(pagename, file, request, do='view')) + 330 links.append(fmt.url(1, getAttachUrl(pagename, file, request, do='view')) +
331 fmt.text(label_view) + 331 fmt.text(label_view) +
332 fmt.url(0)) 332 fmt.url(0))
333 333
334 is_zipfile = zipfile.is_zipfile(fullpath) 334 try:
335 if is_zipfile: 335 is_zipfile = zipfile.is_zipfile(fullpath)
336 is_package = packages.ZipPackage(request, fullpath).isPackage() 336 if is_zipfile:
337 if is_package and request.user.isSuperUser(): 337 is_package = packages.ZipPackage(request, fullpath).isPackage()
338 links.append(fmt.url(1, getAttachUrl(pagename, file, request, do='install')) + 338 if is_package and request.user.isSuperUser():
339 fmt.text(label_install) + 339 links.append(fmt.url(1, getAttachUrl(pagename, file, request, do='install')) +
340 fmt.url(0)) 340 fmt.text(label_install) +
341 elif (not is_package and mt.minor == 'zip' and 341 fmt.url(0))
342 may_delete and 342 elif (not is_package and mt.minor == 'zip' and
343 request.user.may.read(pagename) and 343 may_delete and
344 request.user.may.write(pagename)): 344 request.user.may.read(pagename) and
345 links.append(fmt.url(1, getAttachUrl(pagename, file, request, do='unzip')) + 345 request.user.may.write(pagename)):
346 fmt.text(label_unzip) + 346 links.append(fmt.url(1, getAttachUrl(pagename, file, request, do='unzip')) +
347 fmt.url(0)) 347 fmt.text(label_unzip) +
348 fmt.url(0))
349 except RuntimeError:
350 # We don't want to crash with a traceback here (an exception
351 # here could be caused by an uploaded defective zip file - and
352 # if we crash here, the user does not get a UI to remove the
353 # defective zip file again).
354 # RuntimeError is raised by zipfile stdlib module in case of
355 # problems (like inconsistent slash and backslash usage in the
356 # archive).
357 logging.exception("An exception within zip file attachment handling occurred:")
348 358
349 html.append(fmt.listitem(1)) 359 html.append(fmt.listitem(1))
350 html.append("[%s]" % "&nbsp;| ".join(links)) 360 html.append("[%s]" % "&nbsp;| ".join(links))
351 html.append(" (%(fmtime)s, %(fsize)s KB) [[attachment:%(file)s]]" % parmdict) 361 html.append(" (%(fmtime)s, %(fsize)s KB) [[attachment:%(file)s]]" % parmdict)
352 html.append(fmt.listitem(0)) 362 html.append(fmt.listitem(0))