@@ -16,7 +16,6 @@ class Converter
16
16
def initialize ( source , target , soffice_command = nil , convert_to = nil )
17
17
@source = source
18
18
@target = target
19
- @target_path = Dir . tmpdir
20
19
@soffice_command = soffice_command
21
20
@convert_to = convert_to || "pdf"
22
21
determine_soffice_command
@@ -30,11 +29,13 @@ def initialize(source, target, soffice_command = nil, convert_to = nil)
30
29
def convert
31
30
orig_stdout = $stdout. clone
32
31
$stdout. reopen File . new ( '/dev/null' , 'w' )
33
- pid = Spoon . spawnp ( @soffice_command , "--headless" , "--convert-to" , @convert_to , @source , "--outdir" , @target_path )
34
- Process . waitpid ( pid )
35
- $stdout. reopen orig_stdout
36
- target_tmp_file = "#{ @target_path } /#{ File . basename ( @source , ".*" ) } .#{ File . basename ( @convert_to , ":*" ) } "
37
- FileUtils . cp target_tmp_file , @target
32
+ Dir . mktmpdir { |target_path |
33
+ pid = Spoon . spawnp ( @soffice_command , "--headless" , "--convert-to" , @convert_to , @source , "--outdir" , target_path )
34
+ Process . waitpid ( pid )
35
+ $stdout. reopen orig_stdout
36
+ target_tmp_file = "#{ target_path } /#{ File . basename ( @source , ".*" ) } .#{ File . basename ( @convert_to , ":*" ) } "
37
+ FileUtils . cp target_tmp_file , @target
38
+ }
38
39
end
39
40
40
41
private
@@ -65,4 +66,4 @@ def check_source_type
65
66
raise IOError , "Source (#{ @source } ) is neither a file nor an URL."
66
67
end
67
68
end
68
- end
69
+ end
0 commit comments