1
0
mirror of https://github.com/ciromattia/kcc synced 2025-12-15 18:56:28 +00:00

Added some safeguards against path length limit

This commit is contained in:
Paweł Jastrzębski
2013-10-17 09:25:56 +02:00
parent edfc2467a3
commit 910e8a6cf9

View File

@@ -547,12 +547,16 @@ def genEpubStruct(path):
def getWorkFolder(afile): def getWorkFolder(afile):
if len(afile) > 240:
raise UserWarning("Path is too long.")
if os.path.isdir(afile): if os.path.isdir(afile):
workdir = tempfile.mkdtemp('', 'KCC-TMP-') workdir = tempfile.mkdtemp('', 'KCC-TMP-')
#workdir = tempfile.mkdtemp('', 'KCC-TMP-', os.path.join(os.path.splitext(afile)[0], '..')) #workdir = tempfile.mkdtemp('', 'KCC-TMP-', os.path.join(os.path.splitext(afile)[0], '..'))
try: try:
os.rmdir(workdir) # needed for copytree() fails if dst already exists os.rmdir(workdir) # needed for copytree() fails if dst already exists
fullPath = os.path.join(workdir, 'OEBPS', 'Images') fullPath = os.path.join(workdir, 'OEBPS', 'Images')
if len(fullPath) > 240:
raise UserWarning("Path is too long.")
copytree(afile, fullPath) copytree(afile, fullPath)
sanitizeTreeBeforeConversion(fullPath) sanitizeTreeBeforeConversion(fullPath)
return workdir return workdir
@@ -579,6 +583,8 @@ def getWorkFolder(afile):
else: else:
rmtree(workdir, True) rmtree(workdir, True)
raise TypeError raise TypeError
if len(os.path.join(path, 'OEBPS', 'Images')) > 240:
raise UserWarning("Path is too long.")
move(path, path + "_temp") move(path, path + "_temp")
move(path + "_temp", os.path.join(path, 'OEBPS', 'Images')) move(path + "_temp", os.path.join(path, 'OEBPS', 'Images'))
return path return path