Permalink
Browse files

Ensuring that temp directories are cleaned up on gm or tesseract exce…

…ption.
  • Loading branch information...
1 parent e85000a commit 18363f9577497e5526d14e1103a21057ab7649df @jashkenas jashkenas committed Aug 23, 2010
Showing with 2 additions and 0 deletions.
  1. +1 −0 lib/docsplit/image_extractor.rb
  2. +1 −0 lib/docsplit/text_extractor.rb
View
1 lib/docsplit/image_extractor.rb
@@ -46,6 +46,7 @@ def convert(pdf, size, format, previous=nil)
raise ExtractionFailed, result if $? != 0
end
end
+ ensure
FileUtils.remove_entry_secure tempdir if File.exists?(tempdir)
end
View
1 lib/docsplit/text_extractor.rb
@@ -71,6 +71,7 @@ def extract_from_ocr(pdf, pages)
run "MAGICK_TMPDIR=#{tempdir} OMP_NUM_THREADS=2 gm convert #{MEMORY_ARGS} #{OCR_FLAGS} #{pdf} #{tiff} 2>&1"
run "tesseract #{tiff} #{base_path} -l eng 2>&1"
end
+ ensure
FileUtils.remove_entry_secure tempdir if File.exists?(tempdir)
end

0 comments on commit 18363f9

Please sign in to comment.