[Groonga-commit] groonga/groonga at f18bced [master] Extract tar.gz without external tool

Back to archive index

Kouhei Sutou null+****@clear*****
Mon Oct 19 10:54:50 JST 2015


Kouhei Sutou	2015-10-19 10:54:50 +0900 (Mon, 19 Oct 2015)

  New Revision: f18bced32d15049541f98d1c43f4254837c59d0e
  https://github.com/groonga/groonga/commit/f18bced32d15049541f98d1c43f4254837c59d0e

  Message:
    Extract tar.gz without external tool

  Modified files:
    vendor/download_mecab.rb

  Modified: vendor/download_mecab.rb (+19 -3)
===================================================================
--- vendor/download_mecab.rb    2015-10-18 17:26:42 +0900 (0f8c2a8)
+++ vendor/download_mecab.rb    2015-10-19 10:54:50 +0900 (fdab614)
@@ -3,6 +3,8 @@
 require "pathname"
 require "fileutils"
 require "open-uri"
+require "rubygems/package"
+require "zlib"
 
 base_dir = Pathname.new(__FILE__).expand_path.dirname.parent
 
@@ -12,6 +14,22 @@ mecab_naist_jdic_version = (base_dir + "bundled_mecab_naist_jdic_version").read.
 mecab_base = "mecab-#{mecab_version}"
 mecab_naist_jdic_base = "mecab-naist-jdic-#{mecab_naist_jdic_version}"
 
+def extract_tar_gz(tar_gz_path)
+  Zlib::GzipReader.open(tar_gz_path) do |tar_io|
+    Gem::Package::TarReader.new(tar_io) do |tar|
+      tar.each do |entry|
+        if entry.directory?
+          FileUtils.mkdir_p(entry.full_name)
+        elsif entry.file?
+          File.open(entry.full_name, "wb") do |file|
+            file.print(entry.read)
+          end
+        end
+      end
+    end
+  end
+end
+
 def download(url, base)
   tar = "#{base}.tar"
   tar_gz = "#{tar}.gz"
@@ -21,9 +39,7 @@ def download(url, base)
     end
   end
   FileUtils.rm_rf(base)
-  system("7z", "x", tar_gz)
-  system("7z", "x", tar)
-  FileUtils.rm_rf(tar)
+  extract_tar_gz(tar_gz)
   FileUtils.rm_rf(tar_gz)
 end
 
-------------- next part --------------
HTML����������������������������...
下载 



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