honor temp directory option in all locations

This commit is contained in:
Alex Xu
2026-05-11 11:53:20 -07:00
parent 4a6e4622ed
commit b95bb12393
+10 -15
View File
@@ -30,8 +30,8 @@ from glob import glob, escape
from re import sub from re import sub
from stat import S_IWRITE, S_IREAD, S_IEXEC from stat import S_IWRITE, S_IREAD, S_IEXEC
from typing import List from typing import List
from zipfile import ZipFile, ZIP_STORED, ZIP_DEFLATED from zipfile import ZipFile, ZIP_STORED
from tempfile import mkdtemp, gettempdir, TemporaryFile from tempfile import mkdtemp, gettempdir
from shutil import move, copytree, rmtree, copyfile from shutil import move, copytree, rmtree, copyfile
from multiprocessing import Pool, cpu_count from multiprocessing import Pool, cpu_count
from uuid import uuid4 from uuid import uuid4
@@ -892,9 +892,12 @@ def getWorkFolder(afile, workdir=None):
fullPath = os.path.join(workdir, 'OEBPS', 'Images') fullPath = os.path.join(workdir, 'OEBPS', 'Images')
else: else:
fullPath = workdir fullPath = workdir
check_path = gettempdir()
if options.tempdir: if options.tempdir:
check_path = os.path.dirname(afile) check_path = os.path.dirname(afile)
else:
check_path = gettempdir()
if os.path.isdir(afile): if os.path.isdir(afile):
if disk_usage(check_path)[2] < getDirectorySize(afile) * 2.5: if disk_usage(check_path)[2] < getDirectorySize(afile) * 2.5:
raise UserWarning("Not enough disk space to perform conversion.") raise UserWarning("Not enough disk space to perform conversion.")
@@ -1615,26 +1618,18 @@ def checkPre(source):
for tempdir in dirs: for tempdir in dirs:
if tempdir.startswith('KCC-'): if tempdir.startswith('KCC-'):
rmtree(os.path.join(root, tempdir), True) rmtree(os.path.join(root, tempdir), True)
# Make sure that target directory is writable
if os.path.isdir(source):
src = os.path.abspath(os.path.join(source, '..'))
else:
src = os.path.dirname(source)
try:
with TemporaryFile(prefix='KCC-', dir=src):
pass
except Exception:
raise UserWarning("Target directory is not writable.")
def makeFusion(sources: List[str]): def makeFusion(sources: List[str]):
if len(sources) < 2: if len(sources) < 2:
raise UserWarning('Fusion requires at least 2 sources. Did you forget to uncheck fusion?') raise UserWarning('Fusion requires at least 2 sources. Did you forget to uncheck fusion?')
start = perf_counter() start = perf_counter()
first_path = Path(sources[0]) first_path = Path(sources[0])
fusion_parent = Path(gettempdir())
if options.tempdir: if options.tempdir:
fusion_parent = first_path.parent fusion_parent = first_path.parent
else:
fusion_parent = Path(gettempdir())
if first_path.is_file(): if first_path.is_file():
fusion_path = fusion_parent.joinpath(first_path.stem + ' [fused]') fusion_path = fusion_parent.joinpath(first_path.stem + ' [fused]')
else: else: