Fix #4426 (Error opening epub for view)

This commit is contained in:
Kovid Goyal 2010-01-05 17:16:46 -07:00
parent 536e629356
commit 8bfffc74e2

View File

@ -4,6 +4,7 @@ a zip archive.
""" """
from __future__ import with_statement from __future__ import with_statement
from calibre.ptempfile import TemporaryDirectory from calibre.ptempfile import TemporaryDirectory
from calibre import sanitize_file_name
import struct, os, time, sys, shutil import struct, os, time, sys, shutil
import binascii, cStringIO import binascii, cStringIO
@ -1038,6 +1039,10 @@ class ZipFile:
source = self.open(member, pwd=pwd) source = self.open(member, pwd=pwd)
if not os.path.exists(targetpath): # Could be a previously automatically created directory if not os.path.exists(targetpath): # Could be a previously automatically created directory
try:
target = open(targetpath, "wb")
except IOError:
targetpath = sanitize_file_name(targetpath)
target = open(targetpath, "wb") target = open(targetpath, "wb")
shutil.copyfileobj(source, target) shutil.copyfileobj(source, target)
source.close() source.close()