Skip to content

Commit 80c5bfe

Browse files
committed
fix temp dir cleanup, fixes #284
1 parent 9b122ac commit 80c5bfe

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

ffmpeg_normalize/_media_file.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,10 @@ def _second_pass(self) -> Iterator[float]:
596596
yield 100
597597
return
598598

599+
# track temp_dir for cleanup
600+
temp_dir = None
601+
temp_file = None
602+
599603
# special case: if output is a null device, write directly to it
600604
if self.output_file == os.devnull:
601605
cmd.append(self.output_file)
@@ -617,6 +621,10 @@ def _second_pass(self) -> Iterator[float]:
617621
f"Moving temporary file from {temp_file} to {self.output_file}"
618622
)
619623
move(temp_file, self.output_file)
624+
finally:
625+
# clean up temp directory if it was created
626+
if temp_dir and os.path.exists(temp_dir):
627+
rmtree(temp_dir, ignore_errors=True)
620628

621629
output = cmd_runner.get_output()
622630
# in the second pass, we do not normalize stream-by-stream, so we set the stats based on the

0 commit comments

Comments
 (0)