CHM Input: Skip files whoose names are too long for windows

This commit is contained in:
Kovid Goyal 2010-06-17 12:51:37 -06:00
parent 38851d6ddb
commit 4758fcfffc

View File

@ -8,7 +8,7 @@ import os, re
from mimetypes import guess_type as guess_mimetype from mimetypes import guess_type as guess_mimetype
from calibre.ebooks.BeautifulSoup import BeautifulSoup, NavigableString from calibre.ebooks.BeautifulSoup import BeautifulSoup, NavigableString
from calibre.constants import iswindows
from calibre.utils.chm.chm import CHMFile from calibre.utils.chm.chm import CHMFile
from calibre.utils.chm.chmlib import ( from calibre.utils.chm.chmlib import (
CHM_RESOLVE_SUCCESS, CHM_ENUMERATE_NORMAL, CHM_RESOLVE_SUCCESS, CHM_ENUMERATE_NORMAL,
@ -135,10 +135,16 @@ class CHMReader(CHMFile):
if lpath.find(';') != -1: if lpath.find(';') != -1:
# fix file names with ";<junk>" at the end, see _reformat() # fix file names with ";<junk>" at the end, see _reformat()
lpath = lpath.split(';')[0] lpath = lpath.split(';')[0]
try:
with open(lpath, 'wb') as f: with open(lpath, 'wb') as f:
if guess_mimetype(path)[0] == ('text/html'): if guess_mimetype(path)[0] == ('text/html'):
data = self._reformat(data) data = self._reformat(data)
f.write(data) f.write(data)
except:
if iswindows and len(lpath) > 250:
self.log.warn('%r filename too long, skipping'%path)
continue
raise
self._extracted = True self._extracted = True
files = os.listdir(output_dir) files = os.listdir(output_dir)
if self.hhc_path not in files: if self.hhc_path not in files: