[Groonga-commit] ranguba/chupa-text-decomposer-libreoffice at 42fa929 [master] general: set HOME to allow concurrent work

Back to archive index
Kouhei Sutou null+****@clear*****
Mon Mar 4 06:12:25 JST 2019


Kouhei Sutou	2019-03-04 06:12:25 +0900 (Mon, 04 Mar 2019)

  Revision: 42fa9299ce718cd7c13430cab999355a7d529273
  https://github.com/ranguba/chupa-text-decomposer-libreoffice/commit/42fa9299ce718cd7c13430cab999355a7d529273

  Message:
    general: set HOME to allow concurrent work

  Modified files:
    chupa-text-decomposer-libreoffice-general/lib/chupa-text/decomposers/libreoffice-general.rb

  Modified: chupa-text-decomposer-libreoffice-general/lib/chupa-text/decomposers/libreoffice-general.rb (+19 -12)
===================================================================
--- chupa-text-decomposer-libreoffice-general/lib/chupa-text/decomposers/libreoffice-general.rb    2019-03-03 06:09:16 +0900 (2e5b139)
+++ chupa-text-decomposer-libreoffice-general/lib/chupa-text/decomposers/libreoffice-general.rb    2019-03-04 06:12:25 +0900 (031530d)
@@ -73,19 +73,26 @@ module ChupaText
 
       def convert_to_pdf(data)
         Dir.mktmpdir do |temporary_directory|
-          output = Tempfile.new("chupa-text-decomposer-libreoffice-output")
-          error_output = Tempfile.new("chupa-text-decomposer-libreoffice-error")
-          succeeded =****@comma*****("--headless",
-                                   "--nologo",
+          home_directory = File.join(temporary_directory, "home")
+          FileUtils.mkdir_p(home_directory)
+          output_directory = File.join(temporary_directory, "output")
+          FileUtils.mkdir_p(output_directory)
+          stdout_path = File.join(temporary_directory, "stdout.log")
+          stderr_path = File.join(temporary_directory, "stderr.log")
+          succeeded =****@comma*****("--nologo",
                                    "--nolockcheck",
                                    "--norestore",
+                                   "--headless",
                                    "--convert-to", "pdf",
-                                   "--outdir", temporary_directory,
+                                   "--outdir", output_directory,
                                    data.path.to_s,
                                    {
+                                     :env => {
+                                       "HOME" => home_directory,
+                                     },
                                      :spawn_options => {
-                                       :out => output.path,
-                                       :err => error_output.path,
+                                       :out => stdout_path,
+                                       :err => stderr_path,
                                      },
                                    })
           unless succeeded
@@ -93,20 +100,20 @@ module ChupaText
               tag = "#{log_tag}[convert][exited][abnormally]"
               [
                 tag,
-                "output: <#{output.read}>",
-                "error: <#{error_output.read}>",
+                "output: <#{File.read(stdout_path)}>",
+                "error: <#{File.read(stderr_path)}>",
               ].join("\n")
             end
             return nil
           end
-          pdf_path, = Dir.glob("#{temporary_directory}/*.pdf")
+          pdf_path, = Dir.glob("#{output_directory}/*.pdf")
           if pdf_path.nil?
             error do
               tag = "#{log_tag}[convert][failed]"
               [
                 "#{tag}: LibreOffice may be running",
-                "output: <#{output.read}>",
-                "error: <#{error_output.read}>",
+                "output: <#{File.read(stdout_path)}>",
+                "error: <#{File.read(stderr_path)}>",
               ].join("\n")
             end
             return nil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20190304/78ba3f72/attachment-0001.html>


More information about the Groonga-commit mailing list
Back to archive index