From 800c9a7f87c1494db41c9503d0ca7f79dd9ae07f Mon Sep 17 00:00:00 2001 From: Carlos Fernandez Date: Sun, 21 Dec 2025 22:13:25 +0100 Subject: [PATCH] fix: Delete empty output files instead of leaving 0-byte files (#1282) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When using --output-field both (formerly -12), CCExtractor creates separate output files for each field. If one field has no captions, a 0-byte file was left behind, which is confusing for users. This fix checks the file size in dinit_write() before closing. If the file is empty (0 bytes), it deletes the file and prints an informational message. This is a simpler approach than deferred file creation - files are still created at initialization but cleaned up if they remain empty. Fixes #1282 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- src/lib_ccx/output.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/lib_ccx/output.c b/src/lib_ccx/output.c index 7cab09691..ac9be9257 100644 --- a/src/lib_ccx/output.c +++ b/src/lib_ccx/output.c @@ -14,7 +14,19 @@ void dinit_write(struct ccx_s_write *wb) return; } if (wb->fh > 0) + { + // Check if the file is empty before closing + off_t file_size = lseek(wb->fh, 0, SEEK_END); close(wb->fh); + + // Delete empty output files to avoid generating useless 0-byte files + // This commonly happens with -12 option when one field has no captions + if (file_size == 0 && wb->filename != NULL) + { + unlink(wb->filename); + mprint("Deleted empty output file: %s\n", wb->filename); + } + } freep(&wb->filename); freep(&wb->original_filename); if (wb->with_semaphore && wb->semaphore_filename)