Skip to content

Commit 017082c

Browse files
committed
Merge pull request #14 from zkgan/use-mktmpdir
Use mktmpdir instead of tmpdir for temporary files created
2 parents e020cd9 + e120095 commit 017082c

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

lib/libreconv.rb

+8-7
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ class Converter
1616
def initialize(source, target, soffice_command = nil, convert_to = nil)
1717
@source = source
1818
@target = target
19-
@target_path = Dir.tmpdir
2019
@soffice_command = soffice_command
2120
@convert_to = convert_to || "pdf"
2221
determine_soffice_command
@@ -30,11 +29,13 @@ def initialize(source, target, soffice_command = nil, convert_to = nil)
3029
def convert
3130
orig_stdout = $stdout.clone
3231
$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+
}
3839
end
3940

4041
private
@@ -65,4 +66,4 @@ def check_source_type
6566
raise IOError, "Source (#{@source}) is neither a file nor an URL."
6667
end
6768
end
68-
end
69+
end

0 commit comments

Comments
 (0)