Skip to content

Commit f2339f8

Browse files
author
qount25
committed
Refactor: use @spec.sources to download and extract sources when building deb
This is instead of copying repository into the container.
1 parent 0e9ce56 commit f2339f8

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

lib/pgpm/deb/builder.rb

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# frozen_string_literal: true
22

3+
require "debug"
4+
35
module Pgpm
46
module Deb
57
class Builder
@@ -31,8 +33,32 @@ def prepare
3133
@pgpm_dir = Dir.mktmpdir
3234
Dir.mkdir "#{@pgpm_dir}/source"
3335
Dir.mkdir "#{@pgpm_dir}/out"
34-
puts " Copying #{@spec.package.source.to_s} to #{@pgpm_dir}/source/"
35-
FileUtils.copy_entry @spec.package.source.to_s, "#{@pgpm_dir}/source/"
36+
37+
puts " Downloading and unpacking sources to #{@pgpm_dir}"
38+
39+
fn = nil
40+
@spec.sources.map do |src|
41+
srcfile = File.join("#{@pgpm_dir}", src.name)
42+
File.write(srcfile, src.read)
43+
fn = src.name
44+
end
45+
46+
system("tar -xf #{@pgpm_dir}/#{fn} -C #{@pgpm_dir}/source/")
47+
FileUtils.remove("#{@pgpm_dir}/#{fn}")
48+
49+
untar_dir_entries = Dir.entries("#{@pgpm_dir}/source/").select do |entry|
50+
!([".", ".."].include?(entry))
51+
end
52+
53+
if untar_dir_entries.size == 1
54+
entry = untar_dir_entries[0]
55+
if File.directory?("#{@pgpm_dir}/source/#{entry}")
56+
FileUtils.mv "#{@pgpm_dir}/source/#{entry}", "#{@pgpm_dir}/"
57+
FileUtils.remove_dir "#{@pgpm_dir}/source/"
58+
FileUtils.mv "#{@pgpm_dir}/#{entry}", "#{@pgpm_dir}/source"
59+
end
60+
end
61+
3662
end
3763

3864
def pull_image

0 commit comments

Comments
 (0)