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



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

#headerHeader (readonly)

Returns Main header.

Returns:



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

def header
  @header
end

#leadLead (readonly)

Returns Parsed lead.

Returns:

  • (Lead)

    Parsed lead



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

def lead
  @lead
end

#pathString (readonly)

Returns File path.

Returns:

  • (String)

    File path



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

def path
  @path
end

#signatureHeader? (readonly)

Returns Signature header.

Returns:

  • (Header, nil)

    Signature header



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

def signature
  @signature
end

Instance Method Details

#architectureString

Get package architecture

Returns:

  • (String)


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

def architecture
  tags[:arch]
end

#build_timeTime

Get build time

Returns:

  • (Time)


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

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

#closeObject

Close file handle



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

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

#conflictsArray<Array>

Get conflicts

Returns:

  • (Array<Array>)

    [name, operator, version]



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

def conflicts
  build_relations(:conflict)
end

#descriptionString

Get package description

Returns:

  • (String)


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

def description
  tags[:description]
end

#entriesArray<Entry>

Get file entries with metadata

Returns:



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


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

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

#extract(output_dir) ⇒ Object

Extract to directory

Parameters:

  • output_dir (String)

    Output 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

#filesArray<String>

Get list of files

Returns:

  • (Array<String>)

    File paths



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

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)


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

def license
  tags[:license]
end

#nameString

Get package name

Returns:

  • (String)


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

def name
  tags[:name]
end

#openself

Open and parse RPM

Returns:

  • (self)


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

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

#payload_compressorString

Get payload compressor

Returns:

  • (String)

    Compressor name (gzip, bzip2, xz, zstd)



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

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

#providesArray<Array>

Get provides

Returns:

  • (Array<Array>)

    [name, operator, version]



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

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



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

#releaseString

Get package release

Returns:

  • (String)


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

def release
  tags[:release]
end

#requiresArray<Array>

Get requires

Returns:

  • (Array<Array>)

    [name, operator, version]



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

def requires
  build_relations(:require)
end

#summaryString

Get package summary

Returns:

  • (String)


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

def summary
  tags[:summary]
end

#tagsHash

Get all tags as hash

Returns:

  • (Hash)

    Tag names to values



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

def tags
  return @tags if @tags

  @tags = @header.to_h
end

#vendorString

Get package vendor

Returns:

  • (String)


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

def vendor
  tags[:vendor]
end

#versionString

Get package version

Returns:

  • (String)


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

def version
  tags[:version]
end