Skip to content

Commit b92f3c8

Browse files
authored
use rpmExpandMacros on 4.14+
2 parents 712e07a + b32fd2c commit b92f3c8

File tree

4 files changed

+32
-26
lines changed

4 files changed

+32
-26
lines changed

lib/rpm.rb

+16-5
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,22 @@ def self.transaction(root = '/')
4141
# @param [String] name Name of the macro
4242
# @return [String] value of macro +name+
4343
def self.[](name)
44-
val = ''
45-
buffer = ::FFI::MemoryPointer.new(:pointer, 1024)
46-
buffer.write_string("%{#{name}}")
47-
ret = RPM::C.expandMacros(nil, nil, buffer, 1024)
48-
buffer.read_string
44+
if C::rpm_version_code >= ((4 << 16) + (14 << 8) + (0 << 0))
45+
obuf = ::FFI::MemoryPointer.new(:pointer, 1)
46+
sbuf = FFI::MemoryPointer.from_string("%{#{name}}")
47+
ret = RPM::C.rpmExpandMacros(nil, sbuf, obuf, 0)
48+
raise if ret < 0
49+
50+
val = obuf.read_pointer
51+
val.nil? ? nil : val.read_string
52+
else
53+
buffer = ::FFI::MemoryPointer.new(:pointer, 1024)
54+
buffer.write_string("%{#{name}}")
55+
ret = RPM::C.expandMacros(nil, nil, buffer, 1024)
56+
raise if ret < 0
57+
58+
buffer.read_string
59+
end
4960
end
5061

5162
# Setup a macro

lib/rpm/c/rpmmacro.rb

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ module C
1919
if rpm_version_code >= ((4 << 16) + (14 << 8) + (0 << 0))
2020
attach_function 'rpmPushMacro', [:pointer, :string, :string, :string, :int], :void
2121
attach_function 'rpmPopMacro', [:pointer, :string], :void
22+
attach_function 'rpmExpandMacros', [:pointer, :pointer, :pointer, :int], :int
2223
else
2324
attach_function 'addMacro', [:pointer, :string, :string, :string, :int], :void
2425
attach_function 'delMacro', [:pointer, :string], :void

test/test_rpm.rb

-2
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,10 @@ def test_iterator
2525
end
2626

2727
def test_macro_read
28-
skip("NoMethodError: undefined method `expandMacros' for module RPM::C")
2928
assert_equal '/usr', RPM['_usr']
3029
end
3130

3231
def test_macro_write
33-
skip("NoMethodError: undefined method `expandMacros' for module RPM::C")
3432
RPM['hoge'] = 'hoge'
3533
assert_equal(RPM['hoge'], 'hoge')
3634
end

test/test_transaction.rb

+15-19
Original file line numberDiff line numberDiff line change
@@ -57,64 +57,60 @@ def test_basic_transaction_setters
5757
end
5858

5959
def test_test_flag_install
60-
skip("NoMethodError: undefined method `expandMacros' for RPM::C:Module")
61-
62-
filename = 'simple-1.0-0.i586.rpm'
63-
pkg = RPM::Package.open(fixture(filename))
60+
pkg = RPM::Package.open(fixture(PACKAGE_FILENAME))
6461

6562
Dir.mktmpdir do |dir|
6663
RPM.transaction(dir) do |t|
6764
t.flags = RPM::TRANS_FLAG_TEST
68-
t.install(pkg, fixture(filename))
65+
t.install(pkg, fixture(PACKAGE_FILENAME))
6966
t.commit
7067

71-
assert File.exist?(File.join(dir, RPM['_dbpath'], 'Packages')),
72-
'rpm db exists'
68+
rpmdb_file = RPM::C.rpmvercmp(RPM::C.RPMVERSION, '4.16.0') >= 0 ? 'rpmdb.sqlite' : 'Packages'
7369

74-
assert !File.exist?('/usr/share/simple/README'),
75-
"package #{pkg} was not installed"
70+
assert File.exist?(File.join(dir, RPM['_dbpath'], rpmdb_file)), 'rpm db exists'
71+
assert !File.exist?('/usr/share/simple/README'), "package #{pkg} was not installed"
72+
ensure
73+
# Force close so that RPM does not try to do it
74+
# when the tmpdir is deleted
75+
t.db.close
7676
end
7777
end
7878
end
7979

8080
def test_install_and_remove
8181
pkg = RPM::Package.open(fixture(PACKAGE_FILENAME))
8282

83-
skip("NoMethodError: undefined method `expandMacros' for RPM::C:Module")
84-
8583
Dir.mktmpdir do |dir|
8684
RPM.transaction(dir) do |t|
8785
begin
8886
t.install(pkg, fixture(PACKAGE_FILENAME))
8987
t.commit
9088

91-
assert File.exist?(File.join(dir, RPM['_dbpath'], 'Packages')),
92-
'rpm db exists'
89+
rpmdb_file = RPM::C.rpmvercmp(RPM::C.RPMVERSION, '4.16.0') >= 0 ? 'rpmdb.sqlite' : 'Packages'
9390

94-
assert File.exist?(File.join(dir, '/usr/share/simple/README')),
95-
"package #{pkg} should be installed"
91+
assert File.exist?(File.join(dir, RPM['_dbpath'], rpmdb_file)), 'rpm db exists'
92+
assert File.exist?(File.join(dir, '/usr/share/simple/README')), "package #{pkg} should be installed"
9693
ensure
9794
# Force close so that RPM does not try to do it
9895
# when the tmpdir is deleted
9996
t.db.close
10097
end
10198
end
10299

100+
skip("Commit hangs on package delete")
101+
103102
RPM.transaction(dir) do |t|
104103
begin
105104
assert_raises TypeError do
106105
t.delete(Object.new)
107106
end
108107

109108
t.delete(pkg)
110-
111109
t.order
112110
t.clean
113-
114111
t.commit
115112

116-
assert !File.exist?(File.join(dir, '/usr/share/simple/README')),
117-
"package #{pkg} should not be installed"
113+
assert !File.exist?(File.join(dir, '/usr/share/simple/README')), "package #{pkg} should not be installed"
118114
ensure
119115
# Force close so that RPM does not try to do it
120116
# when the tmpdir is deleted

0 commit comments

Comments
 (0)