Class: Omnizip::Formats::Rpm::Reader

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Reader

Initialize reader

Parameters:

  • path (String)

    Path to RPM file



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

#headerHeader (readonly)

Returns Main header.

Returns:



117
118
119
# File 'lib/omnizip/formats/rpm.rb', line 117

def header
  @header
end

#leadLead (readonly)

Returns Parsed lead.

Returns:

  • (Lead)

    Parsed lead



111
112
113
# File 'lib/omnizip/formats/rpm.rb', line 111

def lead
  @lead
end

#pathString (readonly)

Returns File path.

Returns:

  • (String)

    File path



108
109
110
# File 'lib/omnizip/formats/rpm.rb', line 108

def path
  @path
end

#signatureHeader? (readonly)

Returns Signature header.

Returns:

  • (Header, nil)

    Signature header



114
115
116
# File 'lib/omnizip/formats/rpm.rb', line 114

def signature
  @signature
end

Instance Method Details

#architectureString

Get package architecture

Returns:

  • (String)


186
187
188
# File 'lib/omnizip/formats/rpm.rb', line 186

def architecture
  tags[:arch]
end

#build_timeTime

Get build time

Returns:

  • (Time)


221
222
223
# File 'lib/omnizip/formats/rpm.rb', line 221

def build_time
  Time.at(tags[:buildtime]&.first || 0)
end

#closeObject

Close file handle



141
142
143
144
# File 'lib/omnizip/formats/rpm.rb', line 141

def close
  @file&.close
  @file = nil
end

#conflictsArray<Array>

Get conflicts

Returns:

  • (Array<Array>)

    [name, operator, version]



295
296
297
# File 'lib/omnizip/formats/rpm.rb', line 295

def conflicts
  build_relations(:conflict)
end

#descriptionString

Get package description

Returns:

  • (String)


200
201
202
# File 'lib/omnizip/formats/rpm.rb', line 200

def description
  tags[:description]
end

#entriesArray<Entry>

Get file entries with metadata

Returns:



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 = tags[:filesizes] || []
  modes = tags[:filemodes] || []
  uids = tags[:fileuids] || []
  gids = tags[:filegids] || []
  mtimes = tags[:filemtimes] || []
  flags = tags[:fileflags] || []
  users = tags[:fileusername] || []
  groups = tags[:filegroupname] || []
  digests = tags[:filedigests] || []
  linktos = tags[: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

#epochInteger?

Get package epoch

Returns:

  • (Integer, nil)


179
180
181
# File 'lib/omnizip/formats/rpm.rb', line 179

def epoch
  tags[:epochnum] || tags[:epoch]&.first
end

#extract(output_dir) ⇒ Object

Extract to directory

Parameters:

  • output_dir (String)

    Output 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

#filesArray<String>

Get list of files

Returns:

  • (Array<String>)

    File paths



235
236
237
238
239
240
241
242
243
# File 'lib/omnizip/formats/rpm.rb', line 235

def files
  basenames = tags[:basenames] || []
  dirindexes = tags[:dirindexes] || []
  dirnames = tags[:dirnames] || []

  basenames.zip(dirindexes).map do |name, idx|
    File.join(dirnames[idx] || "", name || "")
  end
end

#licenseString

Get package license

Returns:

  • (String)


207
208
209
# File 'lib/omnizip/formats/rpm.rb', line 207

def license
  tags[:license]
end

#nameString

Get package name

Returns:

  • (String)


158
159
160
# File 'lib/omnizip/formats/rpm.rb', line 158

def name
  tags[:name]
end

#openself

Open and parse RPM

Returns:

  • (self)


134
135
136
137
138
# File 'lib/omnizip/formats/rpm.rb', line 134

def open
  @file = File.open(@path, "rb")
  parse!
  self
end

#payload_compressorString

Get payload compressor

Returns:

  • (String)

    Compressor name (gzip, bzip2, xz, zstd)



228
229
230
# File 'lib/omnizip/formats/rpm.rb', line 228

def payload_compressor
  tags[:payloadcompressor] || "gzip"
end

#providesArray<Array>

Get provides

Returns:

  • (Array<Array>)

    [name, operator, version]



288
289
290
# File 'lib/omnizip/formats/rpm.rb', line 288

def provides
  build_relations(:provide)
end

#raw_payloadString

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).

Returns:

  • (String)

    Raw compressed payload data



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

#releaseString

Get package release

Returns:

  • (String)


172
173
174
# File 'lib/omnizip/formats/rpm.rb', line 172

def release
  tags[:release]
end

#requiresArray<Array>

Get requires

Returns:

  • (Array<Array>)

    [name, operator, version]



281
282
283
# File 'lib/omnizip/formats/rpm.rb', line 281

def requires
  build_relations(:require)
end

#summaryString

Get package summary

Returns:

  • (String)


193
194
195
# File 'lib/omnizip/formats/rpm.rb', line 193

def summary
  tags[:summary]
end

#tagsHash

Get all tags as hash

Returns:

  • (Hash)

    Tag names to values



149
150
151
152
153
# File 'lib/omnizip/formats/rpm.rb', line 149

def tags
  return @tags if @tags

  @tags = @header.to_h
end

#vendorString

Get package vendor

Returns:

  • (String)


214
215
216
# File 'lib/omnizip/formats/rpm.rb', line 214

def vendor
  tags[:vendor]
end

#versionString

Get package version

Returns:

  • (String)


165
166
167
# File 'lib/omnizip/formats/rpm.rb', line 165

def version
  tags[:version]
end