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
123 124 125 126 127 128 129 130 |
# File 'lib/omnizip/formats/rpm.rb', line 123 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.
118 119 120 |
# File 'lib/omnizip/formats/rpm.rb', line 118 def header @header end |
#lead ⇒ Lead (readonly)
Returns Parsed lead.
112 113 114 |
# File 'lib/omnizip/formats/rpm.rb', line 112 def lead @lead end |
#path ⇒ String (readonly)
Returns File path.
109 110 111 |
# File 'lib/omnizip/formats/rpm.rb', line 109 def path @path end |
#signature ⇒ Header? (readonly)
Returns Signature header.
115 116 117 |
# File 'lib/omnizip/formats/rpm.rb', line 115 def signature @signature end |
Instance Method Details
#architecture ⇒ String
Get package architecture
187 188 189 |
# File 'lib/omnizip/formats/rpm.rb', line 187 def architecture [:arch] end |
#build_time ⇒ Time
Get build time
222 223 224 |
# File 'lib/omnizip/formats/rpm.rb', line 222 def build_time Time.at([:buildtime]&.first || 0) end |
#close ⇒ Object
Close file handle
142 143 144 145 |
# File 'lib/omnizip/formats/rpm.rb', line 142 def close @file&.close @file = nil end |
#conflicts ⇒ Array<Array>
Get conflicts
296 297 298 |
# File 'lib/omnizip/formats/rpm.rb', line 296 def conflicts build_relations(:conflict) end |
#description ⇒ String
Get package description
201 202 203 |
# File 'lib/omnizip/formats/rpm.rb', line 201 def description [:description] end |
#entries ⇒ Array<Entry>
Get file entries with metadata
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 277 |
# File 'lib/omnizip/formats/rpm.rb', line 249 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
180 181 182 |
# File 'lib/omnizip/formats/rpm.rb', line 180 def epoch [:epochnum] || [:epoch]&.first end |
#extract(output_dir) ⇒ Object
Extract to directory
303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
# File 'lib/omnizip/formats/rpm.rb', line 303 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
236 237 238 239 240 241 242 243 244 |
# File 'lib/omnizip/formats/rpm.rb', line 236 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
208 209 210 |
# File 'lib/omnizip/formats/rpm.rb', line 208 def license [:license] end |
#name ⇒ String
Get package name
159 160 161 |
# File 'lib/omnizip/formats/rpm.rb', line 159 def name [:name] end |
#open ⇒ self
Open and parse RPM
135 136 137 138 139 |
# File 'lib/omnizip/formats/rpm.rb', line 135 def open @file = File.open(@path, "rb") parse! self end |
#payload_compressor ⇒ String
Get payload compressor
229 230 231 |
# File 'lib/omnizip/formats/rpm.rb', line 229 def payload_compressor [:payloadcompressor] || "gzip" end |
#provides ⇒ Array<Array>
Get provides
289 290 291 |
# File 'lib/omnizip/formats/rpm.rb', line 289 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).
324 325 326 327 328 329 |
# File 'lib/omnizip/formats/rpm.rb', line 324 def raw_payload raise "RPM not opened" unless @file payload_io = payload payload_io.read end |
#release ⇒ String
Get package release
173 174 175 |
# File 'lib/omnizip/formats/rpm.rb', line 173 def release [:release] end |
#requires ⇒ Array<Array>
Get requires
282 283 284 |
# File 'lib/omnizip/formats/rpm.rb', line 282 def requires build_relations(:require) end |
#summary ⇒ String
Get package summary
194 195 196 |
# File 'lib/omnizip/formats/rpm.rb', line 194 def summary [:summary] end |
#tags ⇒ Hash
Get all tags as hash
150 151 152 153 154 |
# File 'lib/omnizip/formats/rpm.rb', line 150 def return @tags if @tags @tags = @header.to_h end |
#vendor ⇒ String
Get package vendor
215 216 217 |
# File 'lib/omnizip/formats/rpm.rb', line 215 def vendor [:vendor] end |
#version ⇒ String
Get package version
166 167 168 |
# File 'lib/omnizip/formats/rpm.rb', line 166 def version [:version] end |