Class: Depot::DebPackage
- Inherits:
-
Object
- Object
- Depot::DebPackage
- Defined in:
- lib/depot/packages/deb.rb
Defined Under Namespace
Classes: FormatError
Constant Summary collapse
- SCRIPT_NAMES =
%w[preinst postinst prerm postrm config].freeze
- DESKTOP_PATH =
%r{\A(?:\./)?usr/share/applications/[^/]+\.desktop\z}- ICON_PATH =
%r{/icons/hicolor/([^/]+)/apps/([^/]+)\.(png|svg|xpm)\z}i
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #ar_members ⇒ Object
- #control_archive_name ⇒ Object
- #control_fields ⇒ Object
- #control_members ⇒ Object
- #data_archive_name ⇒ Object
- #data_members ⇒ Object
- #debian_binary ⇒ Object
- #desktop_entries ⇒ Object
- #executable_entries ⇒ Object
- #extract_data_to(destination) ⇒ Object
- #icon_entries ⇒ Object
- #image_entries ⇒ Object
-
#initialize(path) ⇒ DebPackage
constructor
A new instance of DebPackage.
- #maintainer_scripts ⇒ Object
- #primary_desktop_entry ⇒ Object
- #read_data_entry(entry) ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(path) ⇒ DebPackage
Returns a new instance of DebPackage.
16 17 18 |
# File 'lib/depot/packages/deb.rb', line 16 def initialize(path) @path = path end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
14 15 16 |
# File 'lib/depot/packages/deb.rb', line 14 def path @path end |
Instance Method Details
#ar_members ⇒ Object
81 82 83 |
# File 'lib/depot/packages/deb.rb', line 81 def ar_members @ar_members ||= parse_ar.keys end |
#control_archive_name ⇒ Object
73 74 75 |
# File 'lib/depot/packages/deb.rb', line 73 def control_archive_name @control_archive_name ||= archive_name("control.tar") end |
#control_fields ⇒ Object
30 31 32 |
# File 'lib/depot/packages/deb.rb', line 30 def control_fields @control_fields ||= parse_control(read_control_file("control").to_s) end |
#control_members ⇒ Object
34 35 36 |
# File 'lib/depot/packages/deb.rb', line 34 def control_members @control_members ||= list_tar(control_archive_name) end |
#data_archive_name ⇒ Object
77 78 79 |
# File 'lib/depot/packages/deb.rb', line 77 def data_archive_name @data_archive_name ||= archive_name("data.tar") end |
#data_members ⇒ Object
38 39 40 |
# File 'lib/depot/packages/deb.rb', line 38 def data_members @data_members ||= list_tar(data_archive_name) end |
#debian_binary ⇒ Object
26 27 28 |
# File 'lib/depot/packages/deb.rb', line 26 def debian_binary member("debian-binary")&.strip end |
#desktop_entries ⇒ Object
48 49 50 51 |
# File 'lib/depot/packages/deb.rb', line 48 def desktop_entries data_members.map { |entry| clean_entry(entry) } .select { |entry| entry.end_with?(".desktop") } end |
#executable_entries ⇒ Object
67 68 69 70 71 |
# File 'lib/depot/packages/deb.rb', line 67 def executable_entries data_members.map { |entry| clean_entry(entry) } .select { |entry| entry.start_with?("usr/bin/", "usr/local/bin/", "opt/") } .reject { |entry| entry.end_with?("/") } end |
#extract_data_to(destination) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/depot/packages/deb.rb', line 89 def extract_data_to(destination) FileUtils.mkdir_p(destination) assert_safe_entries!(data_members) with_member_file(data_archive_name) do |archive| stdout, stderr, status = Open3.capture3( "tar", *(data_archive_name), "-xf", archive, "-C", destination ) raise FormatError, "Could not extract data archive: #{stderr.empty? ? stdout : stderr}" unless status.success? end end |
#icon_entries ⇒ Object
57 58 59 60 |
# File 'lib/depot/packages/deb.rb', line 57 def icon_entries data_members.map { |entry| clean_entry(entry) } .select { |entry| entry.match?(ICON_PATH) } end |
#image_entries ⇒ Object
62 63 64 65 |
# File 'lib/depot/packages/deb.rb', line 62 def image_entries data_members.map { |entry| clean_entry(entry) } .select { |entry| entry.match?(/\.(png|svg|xpm)\z/i) } end |
#maintainer_scripts ⇒ Object
42 43 44 45 46 |
# File 'lib/depot/packages/deb.rb', line 42 def maintainer_scripts control_members.map { |entry| clean_entry(entry) } .select { |entry| SCRIPT_NAMES.include?(File.basename(entry)) } .uniq end |
#primary_desktop_entry ⇒ Object
53 54 55 |
# File 'lib/depot/packages/deb.rb', line 53 def primary_desktop_entry desktop_entries.min_by { |entry| desktop_score(entry) } end |
#read_data_entry(entry) ⇒ Object
85 86 87 |
# File 'lib/depot/packages/deb.rb', line 85 def read_data_entry(entry) read_tar_entry(data_archive_name, entry) end |
#valid? ⇒ Boolean
20 21 22 23 24 |
# File 'lib/depot/packages/deb.rb', line 20 def valid? debian_binary && control_archive_name && data_archive_name rescue FormatError false end |