Class: Omnizip::Formats::Rpm::Reader
- Inherits:
-
Object
- Object
- Omnizip::Formats::Rpm::Reader
- Includes:
- Constants
- Defined in:
- lib/omnizip/formats/rpm.rb
Overview
RPM package reader
Handles parsing and extraction of RPM packages.
Constant Summary
Constants included from Constants
Constants::FILE_CONFIG, Constants::FILE_DOC, Constants::FILE_LICENSE, Constants::FILE_README, Constants::FLAG_EQUAL, Constants::FLAG_GREATER, Constants::FLAG_LESS, Constants::HEADER_HEADER_SIZE, Constants::HEADER_MAGIC, Constants::HEADER_SIGNED_TYPE, Constants::LEAD_MAGIC, Constants::LEAD_SIZE, Constants::PACKAGE_BINARY, Constants::PACKAGE_SOURCE, Constants::TAG_ENTRY_SIZE, Constants::TYPE_BINARY, Constants::TYPE_CHAR, Constants::TYPE_I18NSTRING, Constants::TYPE_INT16, Constants::TYPE_INT32, Constants::TYPE_INT64, Constants::TYPE_INT8, Constants::TYPE_NULL, Constants::TYPE_STRING, Constants::TYPE_STRING_ARRAY
Instance Attribute Summary collapse
-
#header ⇒ Header
readonly
Main header.
-
#lead ⇒ Lead
readonly
Parsed lead.
-
#path ⇒ String
readonly
File path.
-
#signature ⇒ Header?
readonly
Signature header.
Instance Method Summary collapse
-
#architecture ⇒ String
Get package architecture.
-
#build_time ⇒ Time
Get build time.
-
#close ⇒ Object
Close file handle.
-
#conflicts ⇒ Array<Array>
Get conflicts.
-
#description ⇒ String
Get package description.
-
#entries ⇒ Array<Entry>
Get file entries with metadata.
-
#epoch ⇒ Integer?
Get package epoch.
-
#extract(output_dir) ⇒ Object
Extract to directory.
-
#files ⇒ Array<String>
Get list of files.
-
#initialize(path) ⇒ Reader
constructor
Initialize reader.
-
#license ⇒ String
Get package license.
-
#name ⇒ String
Get package name.
-
#open ⇒ self
Open and parse RPM.
-
#payload_compressor ⇒ String
Get payload compressor.
-
#provides ⇒ Array<Array>
Get provides.
-
#raw_payload ⇒ String
Get raw payload data.
-
#release ⇒ String
Get package release.
-
#requires ⇒ Array<Array>
Get requires.
-
#summary ⇒ String
Get package summary.
-
#tags ⇒ Hash
Get all tags as hash.
-
#vendor ⇒ String
Get package vendor.
-
#version ⇒ String
Get package version.
Constructor Details
#initialize(path) ⇒ Reader
Initialize reader
122 123 124 125 126 127 128 129 |
# File 'lib/omnizip/formats/rpm.rb', line 122 def initialize(path) @path = path @file = nil @lead = nil @signature = nil @header = nil @tags = nil end |
Instance Attribute Details
#header ⇒ Header (readonly)
Returns Main header.
117 118 119 |
# File 'lib/omnizip/formats/rpm.rb', line 117 def header @header end |
#lead ⇒ Lead (readonly)
Returns Parsed lead.
111 112 113 |
# File 'lib/omnizip/formats/rpm.rb', line 111 def lead @lead end |
#path ⇒ String (readonly)
Returns File path.
108 109 110 |
# File 'lib/omnizip/formats/rpm.rb', line 108 def path @path end |
#signature ⇒ Header? (readonly)
Returns Signature header.
114 115 116 |
# File 'lib/omnizip/formats/rpm.rb', line 114 def signature @signature end |
Instance Method Details
#architecture ⇒ String
Get package architecture
186 187 188 |
# File 'lib/omnizip/formats/rpm.rb', line 186 def architecture [:arch] end |
#build_time ⇒ Time
Get build time
221 222 223 |
# File 'lib/omnizip/formats/rpm.rb', line 221 def build_time Time.at([:buildtime]&.first || 0) end |
#close ⇒ Object
Close file handle
141 142 143 144 |
# File 'lib/omnizip/formats/rpm.rb', line 141 def close @file&.close @file = nil end |
#conflicts ⇒ Array<Array>
Get conflicts
295 296 297 |
# File 'lib/omnizip/formats/rpm.rb', line 295 def conflicts build_relations(:conflict) end |
#description ⇒ String
Get package description
200 201 202 |
# File 'lib/omnizip/formats/rpm.rb', line 200 def description [:description] end |
#entries ⇒ Array<Entry>
Get file entries with metadata
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'lib/omnizip/formats/rpm.rb', line 248 def entries paths = files sizes = [:filesizes] || [] modes = [:filemodes] || [] uids = [:fileuids] || [] gids = [:filegids] || [] mtimes = [:filemtimes] || [] flags = [:fileflags] || [] users = [:fileusername] || [] groups = [:filegroupname] || [] digests = [:filedigests] || [] linktos = [:filelinktos] || [] paths.each_with_index.map do |path, i| Entry.new.tap do |entry| entry.path = path entry.size = sizes[i] || 0 entry.mode = modes[i] || 0o100_644 entry.uid = uids[i] || 0 entry.gid = gids[i] || 0 entry.mtime = Time.at(mtimes[i] || 0) entry.flags = flags[i] || 0 entry.user = users[i] || "" entry.group = groups[i] || "" entry.digest = digests[i] || "" entry.link_to = linktos[i] || "" end end end |
#epoch ⇒ Integer?
Get package epoch
179 180 181 |
# File 'lib/omnizip/formats/rpm.rb', line 179 def epoch [:epochnum] || [:epoch]&.first end |
#extract(output_dir) ⇒ Object
Extract to directory
302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
# File 'lib/omnizip/formats/rpm.rb', line 302 def extract(output_dir) raise "RPM not opened" unless @file FileUtils.mkdir_p(output_dir) # Get payload IO payload_io = payload # Decompress payload using appropriate decompressor decompressor = create_decompressor(payload_io) # Parse CPIO from decompressed stream extract_cpio(decompressor, output_dir) end |
#files ⇒ Array<String>
Get list of files
235 236 237 238 239 240 241 242 243 |
# File 'lib/omnizip/formats/rpm.rb', line 235 def files basenames = [:basenames] || [] dirindexes = [:dirindexes] || [] dirnames = [:dirnames] || [] basenames.zip(dirindexes).map do |name, idx| File.join(dirnames[idx] || "", name || "") end end |
#license ⇒ String
Get package license
207 208 209 |
# File 'lib/omnizip/formats/rpm.rb', line 207 def license [:license] end |
#name ⇒ String
Get package name
158 159 160 |
# File 'lib/omnizip/formats/rpm.rb', line 158 def name [:name] end |
#open ⇒ self
Open and parse RPM
134 135 136 137 138 |
# File 'lib/omnizip/formats/rpm.rb', line 134 def open @file = File.open(@path, "rb") parse! self end |
#payload_compressor ⇒ String
Get payload compressor
228 229 230 |
# File 'lib/omnizip/formats/rpm.rb', line 228 def payload_compressor [:payloadcompressor] || "gzip" end |
#provides ⇒ Array<Array>
Get provides
288 289 290 |
# File 'lib/omnizip/formats/rpm.rb', line 288 def provides build_relations(:provide) end |
#raw_payload ⇒ String
Get raw payload data
Returns the compressed payload as-is (without decompression). Useful for saving the payload as a file (e.g., fonts.src.cpio.gz).
323 324 325 326 327 328 |
# File 'lib/omnizip/formats/rpm.rb', line 323 def raw_payload raise "RPM not opened" unless @file payload_io = payload payload_io.read end |
#release ⇒ String
Get package release
172 173 174 |
# File 'lib/omnizip/formats/rpm.rb', line 172 def release [:release] end |
#requires ⇒ Array<Array>
Get requires
281 282 283 |
# File 'lib/omnizip/formats/rpm.rb', line 281 def requires build_relations(:require) end |
#summary ⇒ String
Get package summary
193 194 195 |
# File 'lib/omnizip/formats/rpm.rb', line 193 def summary [:summary] end |
#tags ⇒ Hash
Get all tags as hash
149 150 151 152 153 |
# File 'lib/omnizip/formats/rpm.rb', line 149 def return @tags if @tags @tags = @header.to_h end |
#vendor ⇒ String
Get package vendor
214 215 216 |
# File 'lib/omnizip/formats/rpm.rb', line 214 def vendor [:vendor] end |
#version ⇒ String
Get package version
165 166 167 |
# File 'lib/omnizip/formats/rpm.rb', line 165 def version [:version] end |