[PR #1877] [FIX] Delete empty output files instead of leaving 0-byte files (#1282) #2660

Closed
opened 2026-01-29 17:23:18 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/CCExtractor/ccextractor/pull/1877

State: closed
Merged: Yes


Summary

  • When using --output-field both, CCExtractor creates separate output files for each field
  • If one field has no captions (e.g., CC3 when only CC1 has data), a 0-byte file was left behind
  • This fix checks file size in dinit_write() before closing - if empty, deletes the file

Approach

This is a simpler approach than PR #1793 (deferred file creation):

  • Files are still created at initialization (no changes to init path)
  • At cleanup, if a file is empty (0 bytes), it's deleted with an informational message
  • Minimal code change (1 file, ~12 lines)

Test Results

$ ccextractor sample.ts --output-field both -o /tmp/test.srt
...
Deleted empty output file: /tmp/test_2.srt

Only the file with actual captions remains.

Fixes #1282

🤖 Generated with Claude Code

**Original Pull Request:** https://github.com/CCExtractor/ccextractor/pull/1877 **State:** closed **Merged:** Yes --- ## Summary - When using `--output-field both`, CCExtractor creates separate output files for each field - If one field has no captions (e.g., CC3 when only CC1 has data), a 0-byte file was left behind - This fix checks file size in `dinit_write()` before closing - if empty, deletes the file ## Approach This is a simpler approach than PR #1793 (deferred file creation): - Files are still created at initialization (no changes to init path) - At cleanup, if a file is empty (0 bytes), it's deleted with an informational message - Minimal code change (1 file, ~12 lines) ## Test Results ``` $ ccextractor sample.ts --output-field both -o /tmp/test.srt ... Deleted empty output file: /tmp/test_2.srt ``` Only the file with actual captions remains. Fixes #1282 🤖 Generated with [Claude Code](https://claude.com/claude-code)
claunia added the pull-request label 2026-01-29 17:23:18 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/ccextractor#2660