Skip to content

Commit

Permalink
Add detection of %posttrans and %pretrans scriptlet from rpm header
Browse files Browse the repository at this point in the history
In specs files, user may use %posttrans and %pretrans scriptlet like this:
Requires(pretrans): test_pkg
Requires(posttrans): test_pkg
This commit add detection to the above special scriptlet

Signed-off-by: Shuo Wang <[email protected]>
  • Loading branch information
Shuo Wang authored and ppisar committed Mar 18, 2024
1 parent 4a8f87d commit f02f17a
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 33 deletions.
2 changes: 2 additions & 0 deletions src/parsehdr.c
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,8 @@ cr_package_from_header(Header hdr,
// Calculate pre value
if (num_flags & (RPMSENSE_PREREQ |
RPMSENSE_SCRIPT_PRE |
RPMSENSE_POSTTRANS |
RPMSENSE_PRETRANS |
RPMSENSE_SCRIPT_POST))
{
pre = 1;
Expand Down
6 changes: 3 additions & 3 deletions tests/python/tests/test_contentstat.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ def test_contentstat(self):

self.assertTrue(os.path.isfile(path))

self.assertEqual(cs.size, 2668)
self.assertEqual(cs.size, 2805)
self.assertEqual(cs.checksum_type, cr.SHA256)
self.assertEqual(cs.checksum, "67bc6282915fad80dc11f3d7c3210977a0bde"\
"05a762256d86083c2447d425776")
self.assertEqual(cs.checksum, "d447983b39363a6519067ce477a7fc64409b4"\
"900e0160da68d66b25207a0408d")

def test_contentstat_ref_in_xmlfile(self):
"""Test if reference is saved properly"""
Expand Down
20 changes: 11 additions & 9 deletions tests/python/tests/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def test_package_empty(self):
def test_package_archer(self):
pkg = cr.package_from_rpm(PKG_ARCHER_PATH)
self.assertTrue(pkg)
self.assertEqual(pkg.pkgId, "4e0b775220c67f0f2c1fd2177e626b9c863a098130224ff09778ede25cea9a9e")
self.assertEqual(pkg.pkgId, "65dd4d39b7539cb0b6b150db20a314402845e006cc0456d910bce87741f81b82")
self.assertEqual(pkg.name, "Archer")
self.assertEqual(pkg.arch, "x86_64")
self.assertEqual(pkg.version, "3.4.5")
Expand All @@ -63,16 +63,16 @@ def test_package_archer(self):
self.assertEqual(pkg.description, "Archer package")
self.assertEqual(pkg.url, "http://soo_complex_package.eu/")
#self.assertEqual(pkg.time_file, 1365416502)
self.assertEqual(pkg.time_build, 1365416480)
self.assertEqual(pkg.time_build, 1710742930)
self.assertEqual(pkg.rpm_license, "GPL")
self.assertEqual(pkg.rpm_vendor, "ISIS")
self.assertEqual(pkg.rpm_group, "Development/Tools")
self.assertEqual(pkg.rpm_buildhost, "localhost.localdomain")
self.assertEqual(pkg.rpm_sourcerpm, "Archer-3.4.5-6.src.rpm")
self.assertEqual(pkg.rpm_header_start, 280)
self.assertEqual(pkg.rpm_header_end, 2865)
self.assertEqual(pkg.rpm_header_start, 4504)
self.assertEqual(pkg.rpm_header_end, 7517)
self.assertEqual(pkg.rpm_packager, "Sterling Archer")
self.assertEqual(pkg.size_package, 3101)
self.assertEqual(pkg.size_package, 7737)
self.assertEqual(pkg.size_installed, 0)
self.assertEqual(pkg.size_archive, 544)
self.assertEqual(pkg.location_href, None)
Expand All @@ -85,16 +85,18 @@ def test_package_archer(self):
('fooc', 'EQ', '0', '3', None, False),
('food', 'LT', '0', '4', None, False),
('fooe', 'GT', '0', '5', None, False),
('foof', 'EQ', '0', '6', None, True)
('foof', 'EQ', '0', '6', None, True),
('foog', 'EQ', '0', '7', None, True),
('fooh', 'EQ', '0', '8', None, True)
])
self.assertEqual(pkg.provides, [
('Archer', 'EQ', '2', '3.4.5', '6', False),
('Archer(x86-64)', 'EQ', '2', '3.4.5', '6', False),
('bara', 'LE', '0', '22', None, False),
('barb', 'GE', '0', '11.22.33', '44', False),
('barc', 'EQ', '0', '33', None, False),
('bard', 'LT', '0', '44', None, False),
('bare', 'GT', '0', '55', None, False),
('Archer', 'EQ', '2', '3.4.5', '6', False),
('Archer(x86-64)', 'EQ', '2', '3.4.5', '6', False)
('bare', 'GT', '0', '55', None, False)
])
self.assertEqual(pkg.conflicts, [
('bba', 'LE', '0', '2222', None, False),
Expand Down
4 changes: 2 additions & 2 deletions tests/python/tests/test_parsepkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ def test_xml_from_rpm(self):
self.assertTrue(xml)
self.assertTrue(len(xml) == 3)
self.assertTrue("<name>Archer</name>" in xml[0])
self.assertTrue('<package pkgid="4e0b775220c67f0f2c1fd2177e626b9c863a098130224ff09778ede25cea9a9e" name="Archer" arch="x86_64">' in xml[1])
self.assertTrue('<package pkgid="4e0b775220c67f0f2c1fd2177e626b9c863a098130224ff09778ede25cea9a9e" name="Archer" arch="x86_64">' in xml[2])
self.assertTrue('<package pkgid="65dd4d39b7539cb0b6b150db20a314402845e006cc0456d910bce87741f81b82" name="Archer" arch="x86_64">' in xml[1])
self.assertTrue('<package pkgid="65dd4d39b7539cb0b6b150db20a314402845e006cc0456d910bce87741f81b82" name="Archer" arch="x86_64">' in xml[2])

# Test error cases

Expand Down
25 changes: 14 additions & 11 deletions tests/python/tests/test_sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,22 +155,23 @@ def test_sqlite_primary(self):
# Check packages table
res = con.execute("select * from packages").fetchall()
self.assertEqual(res,
[(1, u'4e0b775220c67f0f2c1fd2177e626b9c863a098130224ff09778ede25cea9a9e',
[(1, u'65dd4d39b7539cb0b6b150db20a314402845e006cc0456d910bce87741f81b82',
u'Archer', u'x86_64', u'3.4.5', u'2', u'6', u'Complex package.',
u'Archer package', u'http://soo_complex_package.eu/',
res[0][10], 1365416480, u'GPL', u'ISIS', u'Development/Tools',
u'localhost.localdomain', u'Archer-3.4.5-6.src.rpm', 280, 2865,
u'Sterling Archer', 3101, 0, 544, None, None, u'sha256')])
res[0][10], 1710742930, u'GPL', u'ISIS', u'Development/Tools',
u'localhost.localdomain', u'Archer-3.4.5-6.src.rpm', 4504, 7517,
u'Sterling Archer', 7737, 0, 544, None, None, u'sha256')])

# Check provides table
self.assertEqual(con.execute("select * from provides").fetchall(),
[(u'bara', u'LE', u'0', u'22', None, 1),
[(u'Archer', u'EQ', u'2', u'3.4.5', u'6', 1),
(u'Archer(x86-64)', u'EQ', u'2', u'3.4.5', u'6', 1),
(u'bara', u'LE', u'0', u'22', None, 1),
(u'barb', u'GE', u'0', u'11.22.33', u'44', 1),
(u'barc', u'EQ', u'0', u'33', None, 1),
(u'bard', u'LT', u'0', u'44', None, 1),
(u'bare', u'GT', u'0', u'55', None, 1),
(u'Archer', u'EQ', u'2', u'3.4.5', u'6', 1),
(u'Archer(x86-64)', u'EQ', u'2', u'3.4.5', u'6', 1)])
(u'bare', u'GT', u'0', u'55', None, 1)])


# Check conflicts table
self.assertEqual(con.execute("select * from conflicts").fetchall(),
Expand All @@ -195,7 +196,9 @@ def test_sqlite_primary(self):
(u'fooc', u'EQ', u'0', u'3', None, 1, u'FALSE'),
(u'food', u'LT', u'0', u'4', None, 1, u'FALSE'),
(u'fooe', u'GT', u'0', u'5', None, 1, u'FALSE'),
(u'foof', u'EQ', u'0', u'6', None, 1, u'TRUE')])
(u'foof', u'EQ', u'0', u'6', None, 1, u'TRUE'),
(u'foog', u'EQ', u'0', u'7', None, 1, u'TRUE'),
(u'fooh', u'EQ', u'0', u'8', None, 1, u'TRUE')])

# Check files table
self.assertEqual(con.execute("select * from files").fetchall(),
Expand All @@ -219,7 +222,7 @@ def test_sqlite_filelists(self):

# Check packages table
self.assertEqual(con.execute("select * from packages").fetchall(),
[(1, u'4e0b775220c67f0f2c1fd2177e626b9c863a098130224ff09778ede25cea9a9e')])
[(1, u'65dd4d39b7539cb0b6b150db20a314402845e006cc0456d910bce87741f81b82')])

# Check files table
self.assertEqual(set(con.execute("select * from filelist").fetchall()),
Expand All @@ -245,7 +248,7 @@ def test_sqlite_other(self):

# Check packages table
self.assertEqual(con.execute("select * from packages").fetchall(),
[(1, u'4e0b775220c67f0f2c1fd2177e626b9c863a098130224ff09778ede25cea9a9e')])
[(1, u'65dd4d39b7539cb0b6b150db20a314402845e006cc0456d910bce87741f81b82')])

# Check filelist table
self.assertEqual(set(con.execute("select * from filelist").fetchall()),
Expand Down
18 changes: 10 additions & 8 deletions tests/python/tests/test_xml_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,29 +196,29 @@ def test_xmlfile_add_pkg(self):
<name>Archer</name>
<arch>x86_64</arch>
<version epoch="2" ver="3.4.5" rel="6"/>
<checksum type="sha256" pkgid="YES">4e0b775220c67f0f2c1fd2177e626b9c863a098130224ff09778ede25cea9a9e</checksum>
<checksum type="sha256" pkgid="YES">65dd4d39b7539cb0b6b150db20a314402845e006cc0456d910bce87741f81b82</checksum>
<summary>Complex package.</summary>
<description>Archer package</description>
<packager>Sterling Archer</packager>
<url>http://soo_complex_package.eu/</url>
<time file="111" build="1365416480"/>
<size package="3101" installed="0" archive="544"/>
<time file="111" build="1710742930"/>
<size package="7737" installed="0" archive="544"/>
<location href=""/>
<format>
<rpm:license>GPL</rpm:license>
<rpm:vendor>ISIS</rpm:vendor>
<rpm:group>Development/Tools</rpm:group>
<rpm:buildhost>localhost.localdomain</rpm:buildhost>
<rpm:sourcerpm>Archer-3.4.5-6.src.rpm</rpm:sourcerpm>
<rpm:header-range start="280" end="2865"/>
<rpm:header-range start="4504" end="7517"/>
<rpm:provides>
<rpm:entry name="Archer" flags="EQ" epoch="2" ver="3.4.5" rel="6"/>
<rpm:entry name="Archer(x86-64)" flags="EQ" epoch="2" ver="3.4.5" rel="6"/>
<rpm:entry name="bara" flags="LE" epoch="0" ver="22"/>
<rpm:entry name="barb" flags="GE" epoch="0" ver="11.22.33" rel="44"/>
<rpm:entry name="barc" flags="EQ" epoch="0" ver="33"/>
<rpm:entry name="bard" flags="LT" epoch="0" ver="44"/>
<rpm:entry name="bare" flags="GT" epoch="0" ver="55"/>
<rpm:entry name="Archer" flags="EQ" epoch="2" ver="3.4.5" rel="6"/>
<rpm:entry name="Archer(x86-64)" flags="EQ" epoch="2" ver="3.4.5" rel="6"/>
</rpm:provides>
<rpm:requires>
<rpm:entry name="fooa" flags="LE" epoch="0" ver="2"/>
Expand All @@ -227,6 +227,8 @@ def test_xmlfile_add_pkg(self):
<rpm:entry name="food" flags="LT" epoch="0" ver="4"/>
<rpm:entry name="fooe" flags="GT" epoch="0" ver="5"/>
<rpm:entry name="foof" flags="EQ" epoch="0" ver="6" pre="1"/>
<rpm:entry name="foog" flags="EQ" epoch="0" ver="7" pre="1"/>
<rpm:entry name="fooh" flags="EQ" epoch="0" ver="8" pre="1"/>
</rpm:requires>
<rpm:conflicts>
<rpm:entry name="bba" flags="LE" epoch="0" ver="2222"/>
Expand Down Expand Up @@ -264,7 +266,7 @@ def test_xmlfile_add_pkg(self):
self.assertEqual(filelists.read(),
"""<?xml version="1.0" encoding="UTF-8"?>
<filelists xmlns="http://linux.duke.edu/metadata/filelists" packages="0">
<package pkgid="4e0b775220c67f0f2c1fd2177e626b9c863a098130224ff09778ede25cea9a9e" name="Archer" arch="x86_64">
<package pkgid="65dd4d39b7539cb0b6b150db20a314402845e006cc0456d910bce87741f81b82" name="Archer" arch="x86_64">
<version epoch="2" ver="3.4.5" rel="6"/>
<file>/usr/bin/complex_a</file>
<file type="dir">/usr/share/doc/Archer-3.4.5</file>
Expand All @@ -289,7 +291,7 @@ def test_xmlfile_add_pkg(self):
self.assertEqual(other.read(),
"""<?xml version="1.0" encoding="UTF-8"?>
<otherdata xmlns="http://linux.duke.edu/metadata/other" packages="0">
<package pkgid="4e0b775220c67f0f2c1fd2177e626b9c863a098130224ff09778ede25cea9a9e" name="Archer" arch="x86_64">
<package pkgid="65dd4d39b7539cb0b6b150db20a314402845e006cc0456d910bce87741f81b82" name="Archer" arch="x86_64">
<version epoch="2" ver="3.4.5" rel="6"/>
<changelog author="Tomas Mlcoch &lt;[email protected]&gt; - 1.1.1-1" date="1334664000">- First changelog.</changelog>
<changelog author="Tomas Mlcoch &lt;[email protected]&gt; - 2.2.2-2" date="1334750400">- That was totally ninja!</changelog>
Expand Down
Binary file modified tests/testdata/packages/Archer-3.4.5-6.x86_64.rpm
Binary file not shown.
2 changes: 2 additions & 0 deletions tests/testdata/specs/fake-Archer.spec
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Requires: fooc = 3
Requires: food < 4
Requires: fooe > 5
Requires(pre): foof = 6
Requires(pretrans): foog = 7
Requires(posttrans): fooh = 8

Provides: bara <= 22
Provides: barb >= 11.22.33-44
Expand Down

0 comments on commit f02f17a

Please sign in to comment.