mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Ensure get_container doesnt leak a tdir on error
This commit is contained in:
parent
202f537913
commit
a5516efe2b
@ -1551,9 +1551,18 @@ def get_container(path, log=None, tdir=None, tweak_mode=False):
|
|||||||
isdir = os.path.isdir(path)
|
isdir = os.path.isdir(path)
|
||||||
except Exception:
|
except Exception:
|
||||||
isdir = False
|
isdir = False
|
||||||
ebook = (AZW3Container if path.rpartition('.')[-1].lower() in {'azw3', 'mobi', 'original_azw3', 'original_mobi'} and not isdir
|
own_tdir = not tdir
|
||||||
else EpubContainer)(path, log, tdir=tdir)
|
ebook_cls = (AZW3Container if path.rpartition('.')[-1].lower() in {'azw3', 'mobi', 'original_azw3', 'original_mobi'} and not isdir
|
||||||
ebook.tweak_mode = tweak_mode
|
else EpubContainer)
|
||||||
|
if own_tdir:
|
||||||
|
tdir = PersistentTemporaryDirectory(f'_{ebook_cls.book_type}_container')
|
||||||
|
try:
|
||||||
|
ebook = ebook_cls(path, log, tdir=tdir)
|
||||||
|
ebook.tweak_mode = tweak_mode
|
||||||
|
except BaseException:
|
||||||
|
if own_tdir:
|
||||||
|
shutil.rmtree(tdir, ignore_errors=True)
|
||||||
|
raise
|
||||||
return ebook
|
return ebook
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user