[SCM] ci-tooling packaging branch, master, updated. f55197dd85b4dc43611ba69d97b19acf06ad922c

Harald Sitter apachelogger-guest at moszumanska.debian.org
Fri Oct 16 08:40:07 UTC 2015


Gitweb-URL: http://git.debian.org/?p=pkg-kde/ci-tooling.git;a=commitdiff;h=1b5243d

The following commit has been merged in the master branch:
commit 1b5243de983be27f913594d7302b13f1c8f18aeb
Author: Harald Sitter <sitter at kde.org>
Date:   Fri Oct 16 10:07:57 2015 +0200

    implement tarball extraction
---
 lib/ci/tarball.rb                                  |  21 +++++++++++++++++++++
 test/data/test_ci_tarball/test_extract/test-1.tar  | Bin 0 -> 10240 bytes
 .../test_ci_tarball/test_extract/test-flat.tar     | Bin 0 -> 10240 bytes
 test/test_ci_tarball.rb                            |  13 +++++++++++++
 4 files changed, 34 insertions(+)

diff --git a/lib/ci/tarball.rb b/lib/ci/tarball.rb
index ca48b9f..c6e99db 100644
--- a/lib/ci/tarball.rb
+++ b/lib/ci/tarball.rb
@@ -1,3 +1,5 @@
+require 'tmpdir'
+
 module CI
   class Tarball
     attr_reader :path
@@ -29,6 +31,25 @@ module CI
       self
     end
 
+    # @param dest path to extract to. This must be the actual target
+    #             for the directory content. If the tarball contains
+    #             a single top-level directory it will be renamed to
+    #             the basename of to_dir. If it contains more than one
+    #             top-level directory or no directory all content is
+    #             moved *into* dest.
+    def extract(dest)
+      Dir.mktmpdir do |tmpdir|
+        system('tar', '-xf', path, '-C', tmpdir)
+        content = Dir.glob("#{tmpdir}/*")
+        if content.size > 1 || !File.directory?(content[0])
+          FileUtils.mkpath(dest) unless Dir.exist?(dest)
+          FileUtils.cp_r(content, dest)
+        else
+          FileUtils.cp_r(content[0], dest)
+        end
+      end
+    end
+
     def self.orig?(path)
       !File.basename(path).match(/(.+)_([\d.]+)\.orig\.tar(.*)/).nil?
     end
diff --git a/test/data/test_ci_tarball/test_extract/test-1.tar b/test/data/test_ci_tarball/test_extract/test-1.tar
new file mode 100644
index 0000000..9df40ba
Binary files /dev/null and b/test/data/test_ci_tarball/test_extract/test-1.tar differ
diff --git a/test/data/test_ci_tarball/test_extract/test-flat.tar b/test/data/test_ci_tarball/test_extract/test-flat.tar
new file mode 100644
index 0000000..57e752c
Binary files /dev/null and b/test/data/test_ci_tarball/test_extract/test-flat.tar differ
diff --git a/test/test_ci_tarball.rb b/test/test_ci_tarball.rb
index ef834a5..6406fc2 100644
--- a/test/test_ci_tarball.rb
+++ b/test/test_ci_tarball.rb
@@ -25,5 +25,18 @@ module CI
       t = Tarball.new('a-1.0.tar').origify
       assert_equal('a_1.0.orig.tar', File.basename(t.path))
     end
+
+    def test_extract
+      t = Tarball.new(data('test-1.tar'))
+      t.extract("#{Dir.pwd}/test-2")
+      assert_path_exist('test-2')
+      assert_path_exist('test-2/a')
+      assert_path_not_exist('test-1')
+
+      t = Tarball.new(data('test-flat.tar'))
+      t.extract("#{Dir.pwd}/test-1")
+      assert_path_exist('test-1')
+      assert_path_exist('test-1/test-flat')
+    end
   end
 end

-- 
ci-tooling packaging



More information about the pkg-kde-commits mailing list