File removal and error handling

This commit is contained in:
John Whitington 2024-01-12 14:16:11 +00:00
parent edb36171be
commit b57e221879
1 changed files with 8 additions and 1 deletions

View File

@ -5,7 +5,7 @@ open Cpdferror
let debug_image_processing = ref false let debug_image_processing = ref false
let remove x = let remove x =
try Sys.remove x with _ -> () try (*Printf.printf "%s\n" x;*) Sys.remove x with _ -> ()
let pnm_white ch = output_char ch ' ' let pnm_white ch = output_char ch ' '
let pnm_newline ch = output_char ch '\n' let pnm_newline ch = output_char ch '\n'
@ -762,6 +762,7 @@ let preprocess_jbig2_lossy ~path_to_jbig2enc ~length_threshold ~pixel_threshold
in in
(*Printf.printf "%S\n" command;*) Sys.command command (*Printf.printf "%S\n" command;*) Sys.command command
in in
iter remove (map snd !objnum_name_pairs);
if retcode = 0 then if retcode = 0 then
begin begin
let globals = bytes_of_string (contents_of_file (jbig2out ^ ".sym")) in let globals = bytes_of_string (contents_of_file (jbig2out ^ ".sym")) in
@ -790,6 +791,12 @@ let preprocess_jbig2_lossy ~path_to_jbig2enc ~length_threshold ~pixel_threshold
!objnum_name_pairs !objnum_name_pairs
(indx0 !objnum_name_pairs) (indx0 !objnum_name_pairs)
end end
else
begin
Pdfe.log "Call to jbig2enc failed"
end;
iter (fun i -> remove (jbig2out ^ Printf.sprintf ".%04i" i)) (indx0 !objnum_name_pairs);
remove (jbig2out ^ ".sym")
let process let process
?q ?qlossless ?onebppmethod ~length_threshold ~percentage_threshold ~pixel_threshold ~dpi_threshold ?q ?qlossless ?onebppmethod ~length_threshold ~percentage_threshold ~pixel_threshold ~dpi_threshold