Skip to content

Commit 18363f9

Browse files
committed
Ensuring that temp directories are cleaned up on gm or tesseract exception.
1 parent e85000a commit 18363f9

2 files changed

Lines changed: 2 additions & 0 deletions

File tree

lib/docsplit/image_extractor.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def convert(pdf, size, format, previous=nil)
4646
raise ExtractionFailed, result if $? != 0
4747
end
4848
end
49+
ensure
4950
FileUtils.remove_entry_secure tempdir if File.exists?(tempdir)
5051
end
5152

lib/docsplit/text_extractor.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def extract_from_ocr(pdf, pages)
7171
run "MAGICK_TMPDIR=#{tempdir} OMP_NUM_THREADS=2 gm convert #{MEMORY_ARGS} #{OCR_FLAGS} #{pdf} #{tiff} 2>&1"
7272
run "tesseract #{tiff} #{base_path} -l eng 2>&1"
7373
end
74+
ensure
7475
FileUtils.remove_entry_secure tempdir if File.exists?(tempdir)
7576
end
7677

0 commit comments

Comments
 (0)