package rpmfile-eio
Install
Dune Dependency
Authors
Maintainers
Sources
md5=3395b5a612e6a4b05172f048a22a8620
sha512=91bf570efd1a410e6e0e4a5a3d47f5fab401711ddc3bb451e54f729c074e0ce414bcaf29034c08b1e9fcc46ca54ecfd12acc756916b61752f454999d89c4302a
README.md.html
rpmfile
A library for reading metadata from RPM packages (supports version 3.0 and partially 4.0).
Installation
You can install the library using OPAM package manager:
$ opam install rpmfile
$ opam install # rpmfile-unix / rpmfile-eio
Extra:
$ opam install rpmfile-cli # depends by rpmfile-eio
Usage
The Rpmfile
module only provides types and functions for easy field access. To read packages you need to use readers.
Package | Description | Require OCaml |
---|---|---|
rpmfile-unix |
Original reader (since the first version) powered by Angstrom | >= 4.14 |
rpmfile-eio |
New Eio-based reader for more modern age | > 5.1 |
Theoretical minimum
Each RPM package consists of four sections: lead, signature, header, and payload. The first three are meta information about the package. It contains a description, a dependency list, and so on.
The information in the signature and header is stored on a key-value basis, where the key is called a tag. The value can be a number, a string or an array.
Often you don't need all information about a package, but only some tags. For this task, a selector (like predicate function) is used to determine which tags should be parsed and which should not. This greatly increases parsing speed and saves memory.
Read package
For an example, let's use the Rpmfile_unix
reader.
(* Create a reader to read all tags. *)
module Rpm_pkg_reader = Rpmfile_unix.Reader.Make (Rpmfile.Selector.All)
let () =
let metadata =
Rpm_pkg_reader.of_file "hello-2.12.1-1.7.x86_64.rpm"
|> Result.get_ok
in
(* Get the package name by field access function. *)
Printf.printf "Package Name: %s\n" @@ Rpmfile.name metadata
Custom selector
You may write your own selector.
module My_custom_selector : Rpmfile.Selector.S = struct
(* ... *)
end
Or just use built-in selectors
Selector | For |
---|---|
Selector.All |
read all tags |
Selector.Base |
read basic tags (see docs or implementation) |
Manual decode
You can write your own decoder if there is no convenient field access function for the tag you need.
let get_signature_size_field =
Rpmfile.get_from_signature
~msg:"signature.size" (* Failwith message. *)
D.int Tag.Signature.size
Limitations
The implementation uses native OCaml int (32/64 bit depending on your machine) for some internal service values (e.g. as an offset), which may have limitations.
Also, decoding values with field access functions converts any int to native OCaml int, which may break on 32-bit systems.
CLI
You can use the rpmfile-cli
package as a command line utility to get basic information about the package, similar to rpm -qi
.
Example
$ rpmfile-cli test_misc/hello-2.12.1-1.7.x86_64.rpm
Name : hello
Version : 2.12.1
Release : 1.7
Architecture: x86_64
Group : Development/Tools/Other
Size : 185847
License : GPL-3.0-or-later
Source RPM : hello-2.12.1-1.7.src.rpm
Build Date : 2022-05-30
Build Host : reproducible
Packager : https://bugs.opensuse.org
Vendor : openSUSE
URL : https://www.gnu.org/software/hello
Summary : A Friendly Greeting Program
Description :
The GNU hello program produces a familiar, friendly greeting. It
allows nonprogrammers to use a classic computer science tool that would
otherwise be unavailable to them. Because it is protected by the GNU
General Public License, users are free to share and change it.
GNU hello supports many native languages.
Distribution: openSUSE Tumbleweed
Documentation
See the API references.
Contribution
The project is stable, but the library could be more complete. I look forward to your pull requests! If you encounter a bug, then please create an issue.
See HACKING.md if you are interested in developing the project.