rpm 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +10 -0
- data/ChangeLog +5 -0
- data/README.rdoc +11 -1
- data/lib/rpm/{ffi → c}/header.rb +1 -1
- data/lib/rpm/c/rpmcallback.rb +28 -0
- data/lib/rpm/c/rpmcli.rb +7 -0
- data/lib/rpm/{ffi → c}/rpmdb.rb +1 -1
- data/lib/rpm/{ffi → c}/rpmds.rb +1 -6
- data/lib/rpm/{ffi → c}/rpmfi.rb +1 -1
- data/lib/rpm/c/rpmio.rb +21 -0
- data/lib/rpm/{ffi → c}/rpmlib.rb +1 -1
- data/lib/rpm/{ffi → c}/rpmlog.rb +3 -1
- data/lib/rpm/{ffi → c}/rpmmacro.rb +1 -10
- data/lib/rpm/{ffi → c}/rpmprob.rb +17 -3
- data/lib/rpm/{ffi → c}/rpmps.rb +1 -1
- data/lib/rpm/{ffi → c}/rpmtag.rb +12 -4
- data/lib/rpm/{ffi → c}/rpmtd.rb +1 -1
- data/lib/rpm/{ffi → c}/rpmts.rb +6 -2
- data/lib/rpm/{ffi → c}/rpmtypes.rb +3 -1
- data/lib/rpm/c.rb +47 -0
- data/lib/rpm/db.rb +5 -5
- data/lib/rpm/dependency.rb +10 -10
- data/lib/rpm/gem_version.rb +1 -1
- data/lib/rpm/match_iterator.rb +5 -5
- data/lib/rpm/package.rb +55 -55
- data/lib/rpm/problem.rb +71 -0
- data/lib/rpm/transaction.rb +186 -35
- data/lib/rpm/version.rb +3 -4
- data/lib/rpm.rb +16 -24
- data/rpm.gemspec +1 -1
- data/test/data/simple-1.0-0.i586.rpm +0 -0
- data/test/data/simple.spec +0 -4
- data/test/data/simple_with_deps-1.0-0.i586.rpm +0 -0
- data/test/data/simple_with_deps.spec +41 -0
- data/test/helper.rb +1 -1
- data/test/test_dependency.rb +1 -1
- data/test/test_lib.rb +13 -13
- data/test/test_package.rb +24 -3
- data/test/test_problem.rb +20 -0
- data/test/test_transaction.rb +115 -14
- data/test/test_version.rb +2 -0
- metadata +80 -69
- data/lib/rpm/ffi/rpmcallback.rb +0 -26
- data/lib/rpm/ffi.rb +0 -44
data/lib/rpm/version.rb
CHANGED
@@ -98,20 +98,19 @@ module RPM
|
|
98
98
|
#
|
99
99
|
def <=>(other)
|
100
100
|
RPM::Utils.check_type(other, RPM::Version)
|
101
|
-
ret = RPM::
|
101
|
+
ret = RPM::C.rpmvercmp(to_vre_epoch_zero, other.to_vre_epoch_zero)
|
102
102
|
end
|
103
103
|
|
104
104
|
# @param [Version] other Version to compare against
|
105
105
|
# @return [Boolean] true if the version is newer than +other+
|
106
106
|
def newer?(other)
|
107
|
-
|
107
|
+
self > other
|
108
108
|
end
|
109
109
|
|
110
|
-
|
111
110
|
# @param [Version] other Version to compare against
|
112
111
|
# @return [Boolean] true if the version is older than +other+
|
113
112
|
def older?(other)
|
114
|
-
|
113
|
+
self < other
|
115
114
|
end
|
116
115
|
|
117
116
|
# String representation in the form "v-r"
|
data/lib/rpm.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
|
2
|
-
require 'rpm/
|
2
|
+
require 'rpm/c'
|
3
3
|
require 'rpm/package'
|
4
4
|
require 'rpm/db'
|
5
|
+
require 'rpm/problem'
|
5
6
|
require 'rpm/transaction'
|
6
7
|
require 'rpm/match_iterator'
|
7
8
|
require 'rpm/version'
|
@@ -10,23 +11,15 @@ require 'rpm/utils'
|
|
10
11
|
|
11
12
|
module RPM
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
TAG = RPM::C::Tag
|
15
|
+
LOG = RPM::C::Log
|
16
|
+
SENSE = RPM::C::Sense
|
17
|
+
FILE = RPM::C::FileAttrs
|
18
|
+
FILE_STATE = RPM::C::FileState
|
19
|
+
TRANS_FLAG = RPM::C::TransFlags
|
20
|
+
PROB_FILTER = RPM::C::ProbFilter
|
21
|
+
MIRE = RPM::C::RegexpMode
|
16
22
|
|
17
|
-
# call #attach_function to attach to malloc, free, memcpy, bcopy, etc.
|
18
|
-
attach_function :malloc, [:size_t], :pointer
|
19
|
-
end
|
20
|
-
|
21
|
-
TAG = RPM::FFI::Tag
|
22
|
-
LOG = RPM::FFI::Log
|
23
|
-
SENSE = RPM::FFI::Sense
|
24
|
-
FILE = RPM::FFI::FileAttrs
|
25
|
-
FILE_STATE = RPM::FFI::FileState
|
26
|
-
TRANS_FLAG = RPM::FFI::TransFlags
|
27
|
-
PROB_FILTER = RPM::FFI::ProbFilter
|
28
|
-
MIRE = RPM::FFI::RegexpMode
|
29
|
-
|
30
23
|
# Creates a new transaction and pass it
|
31
24
|
# to the given block
|
32
25
|
#
|
@@ -43,14 +36,13 @@ module RPM
|
|
43
36
|
yield ts
|
44
37
|
end
|
45
38
|
|
46
|
-
|
47
39
|
# @param [String] name Name of the macro
|
48
40
|
# @return [String] value of macro +name+
|
49
41
|
def self.[](name)
|
50
42
|
val = String.new
|
51
43
|
buffer = ::FFI::MemoryPointer.new(:pointer, 1024)
|
52
44
|
buffer.write_string("%{#{name}}")
|
53
|
-
ret = RPM::
|
45
|
+
ret = RPM::C.expandMacros(nil, nil, buffer, 1024)
|
54
46
|
buffer.read_string
|
55
47
|
end
|
56
48
|
|
@@ -59,16 +51,16 @@ module RPM
|
|
59
51
|
# @param [String] value Value of the macro or +nil+ to delete it
|
60
52
|
def self.[]=(name, value)
|
61
53
|
if value.nil?
|
62
|
-
RPM::
|
54
|
+
RPM::C.delMacro(nil, name.to_s)
|
63
55
|
else
|
64
|
-
RPM::
|
56
|
+
RPM::C.addMacro(nil, name.to_s, "", value.to_s, RPM::C::RMIL_DEFAULT)
|
65
57
|
end
|
66
58
|
end
|
67
59
|
|
68
60
|
end
|
69
|
-
|
70
|
-
RPM::
|
71
|
-
RPM::
|
61
|
+
|
62
|
+
RPM::C.rpmReadConfigFiles(nil, nil)
|
63
|
+
RPM::C.rpmInitMacros(nil, RPM::C.MACROFILES)
|
72
64
|
|
73
65
|
# TODO
|
74
66
|
# set verbosity
|
data/rpm.gemspec
CHANGED
Binary file
|
data/test/data/simple.spec
CHANGED
Binary file
|
@@ -0,0 +1,41 @@
|
|
1
|
+
Name: simple_with_deps
|
2
|
+
Version: 1.0
|
3
|
+
Release: 0
|
4
|
+
License: GPL
|
5
|
+
Summary: Simple dummy package
|
6
|
+
Url: http://www.dummmy.com
|
7
|
+
Group: Development
|
8
|
+
Requires: a
|
9
|
+
Requires: b > 1.0
|
10
|
+
Conflicts: c d
|
11
|
+
Obsoletes: f
|
12
|
+
BuildRoot: %{_tmppath}/%{name}-%{version}-build
|
13
|
+
|
14
|
+
%description
|
15
|
+
Dummy package
|
16
|
+
|
17
|
+
%description -l es
|
18
|
+
Paquete de muestra
|
19
|
+
|
20
|
+
%prep
|
21
|
+
|
22
|
+
%build
|
23
|
+
mkdir -p %{buildroot}%{_datadir}/%{name}
|
24
|
+
echo "Hello" > %{buildroot}%{_datadir}/%{name}/README
|
25
|
+
echo "Hola" > %{buildroot}%{_datadir}/%{name}/README.es
|
26
|
+
|
27
|
+
%install
|
28
|
+
|
29
|
+
%clean
|
30
|
+
%{?buildroot:%__rm -rf "%{buildroot}"}
|
31
|
+
|
32
|
+
%files
|
33
|
+
%defattr(-,root,root)
|
34
|
+
%{_datadir}/%{name}/README
|
35
|
+
%{_datadir}/%{name}/README.es
|
36
|
+
|
37
|
+
%changelog
|
38
|
+
* Wed Nov 06 2011 Duncan Mac-Vicar P. <dmacvicar@suse.de>
|
39
|
+
- Fix something
|
40
|
+
* Tue Nov 05 2011 Duncan Mac-Vicar P. <dmacvicar@suse.de>
|
41
|
+
- Fix something else
|
data/test/helper.rb
CHANGED
data/test/test_dependency.rb
CHANGED
data/test/test_lib.rb
CHANGED
@@ -3,34 +3,34 @@ require File.join(File.dirname(__FILE__), 'helper')
|
|
3
3
|
class RPM_Lib_Tests < Test::Unit::TestCase
|
4
4
|
|
5
5
|
def test_lib_lib
|
6
|
-
assert_kind_of String, RPM::
|
6
|
+
assert_kind_of String, RPM::C.RPMVERSION
|
7
7
|
# "x.y.z"
|
8
|
-
assert(RPM::
|
9
|
-
assert_kind_of Fixnum, RPM::
|
8
|
+
assert(RPM::C.RPMVERSION.size >= 5)
|
9
|
+
assert_kind_of Fixnum, RPM::C.rpm_version_code
|
10
10
|
# >= 4.0.0
|
11
|
-
assert(RPM::
|
11
|
+
assert(RPM::C.rpm_version_code >= ((4 << 16) + (0 << 8) + (0 << 0)))
|
12
12
|
end
|
13
13
|
|
14
14
|
def test_lib_header
|
15
|
-
ptr = RPM::
|
16
|
-
RPM::
|
15
|
+
ptr = RPM::C.headerNew
|
16
|
+
RPM::C.headerFree(ptr)
|
17
17
|
end
|
18
18
|
|
19
19
|
def test_lib_ts
|
20
|
-
ts = RPM::
|
21
|
-
RPM::
|
22
|
-
it = RPM::
|
20
|
+
ts = RPM::C.rpmtsCreate
|
21
|
+
RPM::C.rpmtsSetRootDir(ts, "/")
|
22
|
+
it = RPM::C.rpmtsInitIterator(ts, 0, nil, 0)
|
23
23
|
hdrs = []
|
24
|
-
while (not (hdr = RPM::
|
24
|
+
while (not (hdr = RPM::C.rpmdbNextIterator(it)).null?)
|
25
25
|
hdrs << hdr
|
26
|
-
assert_kind_of String, RPM::
|
26
|
+
assert_kind_of String, RPM::C.headerGetAsString(hdr, :name)
|
27
27
|
end
|
28
|
-
RPM::
|
28
|
+
RPM::C.rpmdbFreeIterator(it)
|
29
29
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def test_lib_macros
|
33
|
-
assert_kind_of String, RPM::
|
33
|
+
assert_kind_of String, RPM::C.MACROFILES
|
34
34
|
end
|
35
35
|
|
36
36
|
end
|
data/test/test_package.rb
CHANGED
@@ -18,7 +18,7 @@ class RPM_Header_Tests < Test::Unit::TestCase
|
|
18
18
|
|
19
19
|
assert_equal "simple-1.0-0-i586", pkg.to_s
|
20
20
|
|
21
|
-
assert_equal '
|
21
|
+
assert_equal '3b5f9d468c877166532c662e29f43bc3', pkg.signature
|
22
22
|
|
23
23
|
assert_kind_of RPM::Package, pkg
|
24
24
|
assert_equal 'simple', pkg[:name]
|
@@ -45,11 +45,13 @@ class RPM_Header_Tests < Test::Unit::TestCase
|
|
45
45
|
assert pkg.provides.map(&:name).include?("simple(x86-32)")
|
46
46
|
assert pkg.provides.map(&:name).include?("simple")
|
47
47
|
|
48
|
-
assert pkg.requires.map(&:name).include?("/bin/sh")
|
49
|
-
|
50
48
|
assert pkg.files.map(&:path).include?("/usr/share/simple/README")
|
51
49
|
assert pkg.files.map(&:path).include?("/usr/share/simple/README.es")
|
52
50
|
|
51
|
+
assert pkg.conflicts.empty?
|
52
|
+
assert pkg.requires.map(&:name).include?('rpmlib(PayloadIsLzma)')
|
53
|
+
assert pkg.obsoletes.empty?
|
54
|
+
|
53
55
|
file = pkg.files.select {|x| x.path == "/usr/share/simple/README" }.first
|
54
56
|
assert_nil file.link_to
|
55
57
|
assert !file.symlink?
|
@@ -57,4 +59,23 @@ class RPM_Header_Tests < Test::Unit::TestCase
|
|
57
59
|
assert_equal ["- Fix something", "- Fix something else"], pkg.changelog.map(&:text)
|
58
60
|
end
|
59
61
|
|
62
|
+
def test_dependencies
|
63
|
+
pkg = RPM::Package.open(fixture('simple_with_deps-1.0-0.i586.rpm'))
|
64
|
+
assert_equal 'simple_with_deps', pkg.name
|
65
|
+
|
66
|
+
assert pkg.provides.map(&:name).include?('simple_with_deps(x86-32)')
|
67
|
+
assert pkg.provides.map(&:name).include?('simple_with_deps')
|
68
|
+
|
69
|
+
assert pkg.requires.map(&:name).include?("a")
|
70
|
+
b = pkg.requires.find {|x| x.name == 'b'}
|
71
|
+
assert_not_nil b
|
72
|
+
assert_equal '1.0', b.version.to_s
|
73
|
+
|
74
|
+
assert pkg.conflicts.map(&:name).include?('c')
|
75
|
+
assert pkg.conflicts.map(&:name).include?('d')
|
76
|
+
|
77
|
+
assert pkg.obsoletes.map(&:name).include?('f')
|
78
|
+
|
79
|
+
end
|
80
|
+
|
60
81
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'helper')
|
2
|
+
|
3
|
+
class RPM_Header_Tests < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_create
|
6
|
+
problem = RPM::Problem.create(:requires, "foo-1.0-0", "foo.rpm", "bar-1.0-0", "Hello", 1)
|
7
|
+
assert_equal "foo.rpm", problem.key
|
8
|
+
assert_equal :requires, problem.type
|
9
|
+
assert_equal "Hello", problem.str
|
10
|
+
assert_equal "Hello is needed by (installed) bar-1.0-0", problem.to_s
|
11
|
+
|
12
|
+
# Create a RPM::Problem from an existing pointer
|
13
|
+
problem2 = RPM::Problem.new(problem.ptr)
|
14
|
+
assert_equal problem.key, problem2.key
|
15
|
+
assert_equal problem.type, problem2.type
|
16
|
+
assert_equal problem.str, problem2.str
|
17
|
+
assert_equal problem.to_s, problem2.to_s
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
data/test/test_transaction.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
-
|
1
|
+
require_relative('helper')
|
2
2
|
require 'tmpdir'
|
3
|
+
require 'pathname'
|
3
4
|
|
4
5
|
class RPM_Transaction_Tests < Test::Unit::TestCase
|
5
6
|
|
7
|
+
PACKAGE_FILENAME = 'simple-1.0-0.i586.rpm'
|
8
|
+
|
6
9
|
def test_flags
|
7
10
|
RPM.transaction do |t|
|
8
11
|
assert_equal RPM::TRANS_FLAG_NONE, t.flags
|
@@ -21,7 +24,7 @@ class RPM_Transaction_Tests < Test::Unit::TestCase
|
|
21
24
|
RPM.transaction do |t|
|
22
25
|
it = t.init_iterator(nil, nil)
|
23
26
|
it.regexp(:name, :glob, '*audio*')
|
24
|
-
it.each do |pkg|
|
27
|
+
it.each do |pkg|
|
25
28
|
assert pkg.name.include?("audio"), "'#{pkg.name}' contains 'audio'"
|
26
29
|
end
|
27
30
|
end
|
@@ -32,30 +35,128 @@ class RPM_Transaction_Tests < Test::Unit::TestCase
|
|
32
35
|
RPM.transaction do |t|
|
33
36
|
it = t.init_iterator(nil, nil)
|
34
37
|
it.version(RPM::Version.new('2.1'))
|
35
|
-
it.each do |
|
36
|
-
|
38
|
+
it.each do |sig|
|
39
|
+
# FIXME check that this worked
|
37
40
|
end
|
38
41
|
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_install
|
42
|
-
|
43
|
-
filename = 'simple-1.0-0.i586.rpm'
|
44
|
-
pkg = RPM::Package.open(fixture(filename))
|
42
|
+
end
|
45
43
|
|
44
|
+
def test_basic_transaction_setters
|
46
45
|
Dir.mktmpdir do |dir|
|
47
46
|
RPM.transaction do |t|
|
48
47
|
assert_equal "/", t.root_dir
|
49
48
|
t.root_dir = dir
|
49
|
+
assert_equal dir + '/', t.root_dir
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
Dir.mktmpdir do |dir|
|
54
|
+
RPM.transaction(dir) do |t|
|
50
55
|
assert_equal dir + '/', t.root_dir
|
51
|
-
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_test_flag_install
|
61
|
+
filename = 'simple-1.0-0.i586.rpm'
|
62
|
+
pkg = RPM::Package.open(fixture(filename))
|
63
|
+
|
64
|
+
Dir.mktmpdir do |dir|
|
65
|
+
RPM.transaction(dir) do |t|
|
66
|
+
|
52
67
|
t.flags = RPM::TRANS_FLAG_TEST
|
53
|
-
|
54
|
-
t.
|
55
|
-
|
68
|
+
t.install(pkg, fixture(filename))
|
69
|
+
t.commit
|
70
|
+
|
71
|
+
assert File.exist?(File.join(dir, '/var/lib/rpm/Packages')),
|
72
|
+
"rpm db exists"
|
73
|
+
|
74
|
+
assert !File.exist?('/usr/share/simple/README'),
|
75
|
+
"package #{pkg} was not installed"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_install_and_remove
|
81
|
+
pkg = RPM::Package.open(fixture(PACKAGE_FILENAME))
|
82
|
+
|
83
|
+
Dir.mktmpdir do |dir|
|
84
|
+
RPM.transaction(dir) do |t|
|
85
|
+
begin
|
86
|
+
t.install(pkg, fixture(PACKAGE_FILENAME))
|
87
|
+
t.commit
|
88
|
+
|
89
|
+
assert File.exist?(File.join(dir, '/var/lib/rpm/Packages')),
|
90
|
+
"rpm db exists"
|
91
|
+
|
92
|
+
assert File.exist?(File.join(dir, '/usr/share/simple/README')),
|
93
|
+
"package #{pkg} should be installed"
|
94
|
+
ensure
|
95
|
+
# Force close so that RPM does not try to do it
|
96
|
+
# when the tmpdir is deleted
|
97
|
+
t.db.close
|
98
|
+
end
|
56
99
|
end
|
100
|
+
|
101
|
+
RPM.transaction(dir) do |t|
|
102
|
+
begin
|
103
|
+
|
104
|
+
assert_raise TypeError do
|
105
|
+
t.delete(Object.new)
|
106
|
+
end
|
107
|
+
|
108
|
+
t.delete(pkg)
|
109
|
+
|
110
|
+
t.order
|
111
|
+
t.clean
|
112
|
+
|
113
|
+
t.commit
|
114
|
+
|
115
|
+
assert !File.exist?(File.join(dir, '/usr/share/simple/README')),
|
116
|
+
"package #{pkg} should not be installed"
|
117
|
+
|
118
|
+
ensure
|
119
|
+
# Force close so that RPM does not try to do it
|
120
|
+
# when the tmpdir is deleted
|
121
|
+
t.db.close
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
57
125
|
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_install_with_custom_callback
|
129
|
+
pkg = RPM::Package.open(fixture(PACKAGE_FILENAME))
|
130
|
+
|
131
|
+
Dir.mktmpdir do |dir|
|
132
|
+
RPM.transaction(dir) do |t|
|
133
|
+
begin
|
134
|
+
t.install(pkg, fixture(PACKAGE_FILENAME))
|
58
135
|
|
136
|
+
t.check do |problem|
|
137
|
+
STDERR.puts "Problem: #{problem}"
|
138
|
+
end
|
139
|
+
|
140
|
+
t.order
|
141
|
+
t.clean
|
142
|
+
|
143
|
+
t.commit do |data|
|
144
|
+
next case data.type
|
145
|
+
when :inst_open_file then
|
146
|
+
@f = File.open(data.key, 'r')
|
147
|
+
when :inst_close_file then @f.close
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
assert File.exist?(File.join(dir, '/usr/share/simple/README')),
|
152
|
+
"package #{pkg} should be installed"
|
153
|
+
ensure
|
154
|
+
# Force close so that RPM does not try to do it
|
155
|
+
# when the tmpdir is deleted
|
156
|
+
t.db.close
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
59
160
|
end
|
60
161
|
|
61
162
|
end
|