summaryrefslogtreecommitdiffstats
path: root/README.md
blob: a53d7e40a82cb6cfd0a59237bef40b4e3417bcfa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# RPM information extension for PHP

Retrieve RPM information from PHP code using librpm.

**Notice**: this is a experimental extension, a work in progress, so don't expect a stable API yet.

----

# Sources

* Official git repository: https://git.remirepo.net/cgit/tools/php-rpminfo.git/
* Mirror on github for contributors: https://github.com/remicollet/rpminfo

# Build

You need the rpm development files (rpm-devel) version >= 4.11.3.

From the sources tree

    $ phpize
    $ ./configure --enable-rpminfo
    $ make
    $ make test

----

# Usage

## rpmvercmp

	int rpmvercmp(string evr1, string evr2);

Allow to compare 2 EVR (epoch:version-release) strings. The return value is < 0 if evr1 < evr2, > 0 if evr1 > evr2, 0 if equal.

    $ php -a
    php > var_dump(rpmvercmp("1.0", "1.1"));
    int(-1)
    php > var_dump(rpmvercmp("1:1.0", "1.1"));
    int(1)


## rpminfo

	array rpminfo(string path [, bool full ]);

Retrieve information from a rpm file, reading its metadata.
The return value is a hash table, or false if it fails.

    $ php -a
    php > print_r(rpminfo("tests/bidon.rpm"));
    Array
    (
        [Name] => bidon
        [Version] => 1
        [Release] => 1.fc25.remi
        [Arch] => x86_64
    )
    
    php > print_r(rpminfo("tests/bidon.rpm", true));
    Array
    (
        [Headeri18ntable] => C
        [Sigsize] => 2304
        [Sigmd5] => 644819c3566819b1e10a5c97943de094
        [Sha1header] => 0a86742fe53973ac9ab4611187a83ffb44f1de5a
        [Sha256header] => 9aab7242a80212ad1fe4fdd3b250c0c4f176c0b3fb1355c0d62ff094fc3f7da0
        [Name] => bidon
        [Version] => 1
        [Release] => 1.fc25.remi
        [Summary] => Bidon
        [Description] => A dummy package
        ...
        [IsSource] => 
    )
    
    php > var_dump(rpminfo("missing.rpm"));
    Warning: rpminfo(): Can't open 'missing.rpm': No such file or directory in php shell code on line 1
    bool(false)
    
    php > var_dump(rpminfo("missing.rpm", false, $error));
    bool(false)
    php > echo $error;
    Can't open 'missing.rpm': No such file or directory


----

# LICENSE

Author: Remi Collet

This extension is licensed under [The PHP License, version 3.01](http://www.php.net/license/3_01.txt)

-----

# History

Created as a PoC, for fun, see history on
https://blog.remirepo.net/post/2018/01/26/About-repomanage-performance-regression