From 4a6e4622edc7346ca379718e3e99d7c5e3b129fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=95=E3=82=A3=E3=83=AB=E3=82=BF=E3=83=BC=E3=83=9A?= =?UTF-8?q?=E3=83=BC=E3=83=91=E3=83=BC?= <76888457+filterpaper@users.noreply.github.com> Date: Tue, 21 Apr 2026 14:20:46 +0800 Subject: [PATCH 1/3] Use tempdir option for fusion path * Update makeFusion to use the same temporary directory location * Avoid creating an orphan "KCC-" in TMPDIR when --tempdir is set --- kindlecomicconverter/comic2ebook.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/kindlecomicconverter/comic2ebook.py b/kindlecomicconverter/comic2ebook.py index 8cd316c..7491c8a 100755 --- a/kindlecomicconverter/comic2ebook.py +++ b/kindlecomicconverter/comic2ebook.py @@ -1632,10 +1632,13 @@ def makeFusion(sources: List[str]): raise UserWarning('Fusion requires at least 2 sources. Did you forget to uncheck fusion?') start = perf_counter() first_path = Path(sources[0]) + fusion_parent = Path(gettempdir()) + if options.tempdir: + fusion_parent = first_path.parent if first_path.is_file(): - fusion_path = first_path.parent.joinpath(first_path.stem + ' [fused]') + fusion_path = fusion_parent.joinpath(first_path.stem + ' [fused]') else: - fusion_path = first_path.parent.joinpath(first_path.name + ' [fused]') + fusion_path = fusion_parent.joinpath(first_path.name + ' [fused]') print("Running Fusion") # Check if prefix is needed when user-specified ordering differs from OS natural sorting From b95bb12393b6c1a46a1095bda4c275a11e7bd585 Mon Sep 17 00:00:00 2001 From: Alex Xu Date: Mon, 11 May 2026 11:53:20 -0700 Subject: [PATCH 2/3] honor temp directory option in all locations --- kindlecomicconverter/comic2ebook.py | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/kindlecomicconverter/comic2ebook.py b/kindlecomicconverter/comic2ebook.py index 7491c8a..a232471 100755 --- a/kindlecomicconverter/comic2ebook.py +++ b/kindlecomicconverter/comic2ebook.py @@ -30,8 +30,8 @@ from glob import glob, escape from re import sub from stat import S_IWRITE, S_IREAD, S_IEXEC from typing import List -from zipfile import ZipFile, ZIP_STORED, ZIP_DEFLATED -from tempfile import mkdtemp, gettempdir, TemporaryFile +from zipfile import ZipFile, ZIP_STORED +from tempfile import mkdtemp, gettempdir from shutil import move, copytree, rmtree, copyfile from multiprocessing import Pool, cpu_count from uuid import uuid4 @@ -892,9 +892,12 @@ def getWorkFolder(afile, workdir=None): fullPath = os.path.join(workdir, 'OEBPS', 'Images') else: fullPath = workdir - check_path = gettempdir() + if options.tempdir: check_path = os.path.dirname(afile) + else: + check_path = gettempdir() + if os.path.isdir(afile): if disk_usage(check_path)[2] < getDirectorySize(afile) * 2.5: raise UserWarning("Not enough disk space to perform conversion.") @@ -1615,26 +1618,18 @@ def checkPre(source): for tempdir in dirs: if tempdir.startswith('KCC-'): 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]): if len(sources) < 2: raise UserWarning('Fusion requires at least 2 sources. Did you forget to uncheck fusion?') start = perf_counter() first_path = Path(sources[0]) - fusion_parent = Path(gettempdir()) + if options.tempdir: fusion_parent = first_path.parent + else: + fusion_parent = Path(gettempdir()) + if first_path.is_file(): fusion_path = fusion_parent.joinpath(first_path.stem + ' [fused]') else: From ffeaaeca190d1f080bde03135bc4966e06555210 Mon Sep 17 00:00:00 2001 From: Alex Xu Date: Mon, 11 May 2026 16:34:11 -0700 Subject: [PATCH 3/3] clean up temp files better --- kindlecomicconverter/KCC_gui.py | 1 + kindlecomicconverter/comic2ebook.py | 14 +++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/kindlecomicconverter/KCC_gui.py b/kindlecomicconverter/KCC_gui.py index 9d9fb5b..566bc3b 100644 --- a/kindlecomicconverter/KCC_gui.py +++ b/kindlecomicconverter/KCC_gui.py @@ -564,6 +564,7 @@ class WorkerThread(QThread): os.remove(path) elif os.path.isdir(path): rmtree(path, True) + comic2ebook.checkPre('LLL-') GUI.progress.content = '' GUI.progress.stop() MW.hideProgressBar.emit() diff --git a/kindlecomicconverter/comic2ebook.py b/kindlecomicconverter/comic2ebook.py index a232471..6a92f1a 100755 --- a/kindlecomicconverter/comic2ebook.py +++ b/kindlecomicconverter/comic2ebook.py @@ -90,6 +90,7 @@ def main(argv=None): os.remove(path) elif os.path.isdir(path): rmtree(path, True) + checkPre('LLL-') return 0 @@ -1612,11 +1613,11 @@ def checkTools(source): sys.exit(1) -def checkPre(source): +def checkPre(source='KCC-'): # Make sure that all temporary files are gone for root, dirs, _ in walkLevel(gettempdir(), 0): for tempdir in dirs: - if tempdir.startswith('KCC-'): + if tempdir.startswith(source): rmtree(os.path.join(root, tempdir), True) def makeFusion(sources: List[str]): @@ -1628,7 +1629,9 @@ def makeFusion(sources: List[str]): if options.tempdir: fusion_parent = first_path.parent else: - fusion_parent = Path(gettempdir()) + # LLL is after KCC + checkPre('LLL-') + fusion_parent = Path(mkdtemp('', 'LLL-')) if first_path.is_file(): fusion_path = fusion_parent.joinpath(first_path.stem + ' [fused]') @@ -1642,7 +1645,6 @@ def makeFusion(sources: List[str]): for index, source in enumerate(sources, start=1): print(f"Processing {source}...") - checkPre(source) print("Checking images...") source_path = Path(source) # Add the fusion_0001_ prefix to maintain user-specified order if needed @@ -1674,7 +1676,9 @@ def makeBook(source, qtgui=None, job_progress=''): GUI.progressBarTick.emit('1') else: checkTools(source) - checkPre(source) + checkPre() + if not options.filefusion: + checkPre('LLL-') print(f"{job_progress}Preparing source images...") path = getWorkFolder(source) print(f"{job_progress}Checking images...")