From 0d8d44567bc5164c16345eabb87440837e719dbe Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 9 Mar 2012 22:07:18 +0530 Subject: [PATCH] EPUB Input: When extracting the contents of epub files on windows, do not error out if one or more of the components in the epub file have filepaths containing characters that are invalid for the windows filesystem, instead, just replace those characters, since those entries are likely to be bugs in the zip container anyway. Fixes #950081 (Private bug) --- src/calibre/utils/zipfile.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/calibre/utils/zipfile.py b/src/calibre/utils/zipfile.py index 1bf754288d..95e556418c 100644 --- a/src/calibre/utils/zipfile.py +++ b/src/calibre/utils/zipfile.py @@ -1097,18 +1097,26 @@ class ZipFile: and len(os.path.splitdrive(targetpath)[1]) > 1): targetpath = targetpath[:-1] - # don't include leading "/" from file name if present - if member.filename[0] == '/': - targetpath = os.path.join(targetpath, member.filename[1:]) - else: - targetpath = os.path.join(targetpath, member.filename) + base_target = targetpath # Added by Kovid - targetpath = os.path.normpath(targetpath) + # don't include leading "/" from file name if present + fname = member.filename + if fname.startswith('/'): + fname = fname[1:] + + targetpath = os.path.normpath(os.path.join(base_target, fname)) # Create all upper directories if necessary. upperdirs = os.path.dirname(targetpath) if upperdirs and not os.path.exists(upperdirs): - os.makedirs(upperdirs) + try: + os.makedirs(upperdirs) + except: # Added by Kovid + targetpath = os.path.join(base_target, + sanitize_file_name2(fname)) + upperdirs = os.path.dirname(targetpath) + if upperdirs and not os.path.exists(upperdirs): + os.makedirs(upperdirs) if member.filename[-1] == '/': if not os.path.isdir(targetpath):