rpm 0.0.0 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/MIT-LICENSE +24 -0
- data/README.rdoc +298 -0
- data/Rakefile +32 -1
- data/lib/rpm/compat.rb +43 -0
- data/lib/rpm/db.rb +125 -0
- data/lib/rpm/dependency.rb +132 -0
- data/lib/rpm/ffi/header.rb +37 -0
- data/lib/rpm/ffi/rpmcallback.rb +26 -0
- data/lib/rpm/ffi/rpmdb.rb +22 -0
- data/lib/rpm/ffi/rpmds.rb +51 -0
- data/lib/rpm/ffi/rpmfi.rb +34 -0
- data/lib/rpm/ffi/rpmlib.rb +15 -0
- data/lib/rpm/ffi/rpmlog.rb +24 -0
- data/lib/rpm/ffi/rpmmacro.rb +38 -0
- data/lib/rpm/ffi/rpmprob.rb +42 -0
- data/lib/rpm/ffi/rpmps.rb +13 -0
- data/lib/rpm/ffi/rpmtag.rb +299 -0
- data/lib/rpm/ffi/rpmtd.rb +37 -0
- data/lib/rpm/ffi/rpmts.rb +70 -0
- data/lib/rpm/ffi/rpmtypes.rb +29 -0
- data/lib/rpm/ffi.rb +44 -0
- data/lib/rpm/file.rb +132 -0
- data/lib/rpm/gem_version.rb +7 -0
- data/lib/rpm/match_iterator.rb +73 -0
- data/lib/rpm/package.rb +344 -0
- data/lib/rpm/transaction.rb +130 -0
- data/lib/rpm/utils.rb +10 -0
- data/lib/rpm/version.rb +154 -1
- data/lib/rpm.rb +74 -3
- data/rpm.gemspec +10 -4
- data/test/data/a.spec +49 -0
- data/test/data/simple-1.0-0.i586.rpm +0 -0
- data/test/data/simple.spec +42 -0
- data/test/helper.rb +7 -0
- data/test/test_dependency.rb +29 -0
- data/test/test_file.rb +12 -0
- data/test/test_lib.rb +36 -0
- data/test/test_package.rb +60 -0
- data/test/test_rpm.rb +37 -0
- data/test/test_transaction.rb +61 -0
- data/test/test_version.rb +63 -0
- metadata +74 -13
- data/README +0 -3
data/MIT-LICENSE
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
|
2
|
+
Copyright © 2011 Duncan Mac-Vicar Prett <dmacvicar@suse.de>
|
3
|
+
Copyright © 2011 SUSE Linux Products GmbH
|
4
|
+
Copyright © 2002 Kenta Murata
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
7
|
+
a copy of this software and associated documentation files (the
|
8
|
+
"Software"), to deal in the Software without restriction, including
|
9
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
10
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
+
permit persons to whom the Software is furnished to do so, subject to
|
12
|
+
the following conditions:
|
13
|
+
|
14
|
+
The above copyright notice and this permission notice shall be
|
15
|
+
included in all copies or substantial portions of the Software.
|
16
|
+
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
21
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
22
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
23
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
24
|
+
|
data/README.rdoc
ADDED
@@ -0,0 +1,298 @@
|
|
1
|
+
|
2
|
+
= RPM bindings for ruby
|
3
|
+
|
4
|
+
* http://github.com/dmacvicar/ruby-rpm
|
5
|
+
|
6
|
+
= WARNING
|
7
|
+
|
8
|
+
This is an alpha release! There is still work to be done
|
9
|
+
|
10
|
+
= Quickstart
|
11
|
+
|
12
|
+
== Working with RPM package files
|
13
|
+
|
14
|
+
require 'rpm'
|
15
|
+
|
16
|
+
pkg = RPM::Package.open("file.rpm")
|
17
|
+
pkg.arch => "x86_64"
|
18
|
+
|
19
|
+
pkg.files.each do |file|
|
20
|
+
puts file.path
|
21
|
+
end
|
22
|
+
|
23
|
+
pkg.changelog.each do |entry|
|
24
|
+
puts "#{entry.name} #{entry.time} #{entry.text}"
|
25
|
+
end
|
26
|
+
|
27
|
+
== Querying the rpm database
|
28
|
+
|
29
|
+
require 'rpm'
|
30
|
+
|
31
|
+
RPM.transaction do |ts|
|
32
|
+
ts.each do |pkg|
|
33
|
+
puts pkg
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
= Introduction
|
38
|
+
|
39
|
+
This library is a replacement for the ruby-rpm gem, originally
|
40
|
+
writen by Kenta Murata around 2002 for the Kondara distribution. Later
|
41
|
+
mantained by David Lutterkort and myself.
|
42
|
+
|
43
|
+
Why?
|
44
|
+
|
45
|
+
* The original gem supports ancient rpm versions not in use anymore
|
46
|
+
* The original gem was written in C using MRI API
|
47
|
+
* The #ifdef'ing required to support multiple rpm versions made the code
|
48
|
+
hard to maintain
|
49
|
+
|
50
|
+
This gem:
|
51
|
+
|
52
|
+
* Is pure ruby
|
53
|
+
* Is documented
|
54
|
+
* Has as a goal to support only the latest rpm version plus the ones in
|
55
|
+
use some releases back in popular rpm based distros
|
56
|
+
* Uses FFI, so it should work with other interpreters
|
57
|
+
(Because https://github.com/rubinius/rubinius/issues/682 it currently does
|
58
|
+
not work on Rubinius)
|
59
|
+
* Does not target rpm5, but it may support it someday
|
60
|
+
|
61
|
+
As an example the code that implements RPM::Package was reduced
|
62
|
+
from 1130 lines of code to 320.
|
63
|
+
|
64
|
+
= Architecture
|
65
|
+
|
66
|
+
The gem is divided in two modules:
|
67
|
+
|
68
|
+
* RPM::FFI:: which contains the 1:1 mapping to the librpm API
|
69
|
+
Not all functions are attached, only the ones we actually use.
|
70
|
+
* RPM:: contains the actual higher level API
|
71
|
+
|
72
|
+
= Status, Compatibility and Differences with ruby-rpm
|
73
|
+
|
74
|
+
* Tested rpm 4.9 only
|
75
|
+
* You can use symbols: instead of RPM::TAG_DESCRIPTION you
|
76
|
+
can use just :description. 'rpm/compat' is by default loaded
|
77
|
+
and provides compatibility with the RPM::TAG_* style constants
|
78
|
+
* RPM::DB is not supported. Use RPM::Transaction
|
79
|
+
* Spec and Source classes are not implemented yet
|
80
|
+
|
81
|
+
== API Checklist and TODO
|
82
|
+
|
83
|
+
* RPM
|
84
|
+
|
85
|
+
[ ] RPM#expand
|
86
|
+
[X] RPM#[]
|
87
|
+
[X] RPM#[]=
|
88
|
+
[ ] RPM#readrc
|
89
|
+
[ ] RPM#init_macros
|
90
|
+
[ ] RPM#verbosity
|
91
|
+
[ ] RPM#verbosity=
|
92
|
+
|
93
|
+
* RPM::Package
|
94
|
+
|
95
|
+
[X] Package#open
|
96
|
+
[X] Package#new
|
97
|
+
[X] Package#create
|
98
|
+
[ ] Package#load
|
99
|
+
[ ] Package#clear_cache
|
100
|
+
[ ] Package#use_cache
|
101
|
+
[X] Package#[]
|
102
|
+
[ ] Package#delete_tag
|
103
|
+
[X] Package#sprintf
|
104
|
+
[?] Package#signature
|
105
|
+
[X] Package#arch
|
106
|
+
[X] Package#name
|
107
|
+
[X] Package#version
|
108
|
+
[X] Package#files
|
109
|
+
[X] Package#provides
|
110
|
+
[X] Package#requires
|
111
|
+
[X] Package#conflicts
|
112
|
+
[X] Package#obsoletes
|
113
|
+
[X] Package#changelog
|
114
|
+
[ ] Package#add_dependency
|
115
|
+
[ ] Package#add_string
|
116
|
+
[ ] Package#add_string_array
|
117
|
+
[ ] Package#add_int32
|
118
|
+
[ ] Package#dump
|
119
|
+
[X] Package#to_s
|
120
|
+
[ ] Package#inspect
|
121
|
+
[ ] Package#copy_to
|
122
|
+
|
123
|
+
* RPM::Dependency
|
124
|
+
|
125
|
+
[X] Dependency#initialize
|
126
|
+
[X] Dependency#name
|
127
|
+
[X] Dependency#version
|
128
|
+
[X] Dependency#flags
|
129
|
+
[X] Dependency#owner
|
130
|
+
[X] Dependency#lt?
|
131
|
+
[X] Dependency#gt?
|
132
|
+
[X] Dependency#eq?
|
133
|
+
[X] Dependency#le?
|
134
|
+
[X] Dependency#ge?
|
135
|
+
[X] Dependency#satisfy?
|
136
|
+
[X] Dependency#nametag
|
137
|
+
[X] Dependency#versiontag
|
138
|
+
[X] Dependency#flagstag
|
139
|
+
|
140
|
+
* RPM::Provide
|
141
|
+
[X] Provide#initialize
|
142
|
+
|
143
|
+
* RPM::Require
|
144
|
+
[X] Require#initialize
|
145
|
+
[ ] Require#pre?
|
146
|
+
|
147
|
+
* RPM::Conflict
|
148
|
+
[X] Conflict#initialize
|
149
|
+
|
150
|
+
* RPM::Obsolete
|
151
|
+
[X] Obsolete#initialize
|
152
|
+
|
153
|
+
* RPM::ChangeLog
|
154
|
+
|
155
|
+
[X] ChangeLog#time
|
156
|
+
[X] ChangeLog#name
|
157
|
+
[X] ChangeLog#text
|
158
|
+
|
159
|
+
* RPM::Version
|
160
|
+
|
161
|
+
[X] Version (Comparable)
|
162
|
+
[X] Version#initialize
|
163
|
+
[X] Version#<=>
|
164
|
+
[X] Version#newer?
|
165
|
+
[X] Version#older?
|
166
|
+
[X] Version#v
|
167
|
+
[X] Version#r
|
168
|
+
[X] Version#e
|
169
|
+
[X] Version#to_s
|
170
|
+
[X] Version#to_vre
|
171
|
+
[X] Version#inspect
|
172
|
+
[X] Version#hash
|
173
|
+
|
174
|
+
* RPM::File
|
175
|
+
|
176
|
+
[X] File#initialize
|
177
|
+
[X] File#path
|
178
|
+
[ ] File#to_s (alias path)
|
179
|
+
[X] File#md5sum
|
180
|
+
[X] File#link_to
|
181
|
+
[X] File#size
|
182
|
+
[X] File#mtime
|
183
|
+
[X] File#owner
|
184
|
+
[X] File#group
|
185
|
+
[X] File#rdev
|
186
|
+
[X] File#mode
|
187
|
+
[X] File#attr
|
188
|
+
[X] File#state
|
189
|
+
[X] File#symlink?
|
190
|
+
[X] File#config?
|
191
|
+
[X] File#doc?
|
192
|
+
[X] File#donotuse?
|
193
|
+
[X] File#missingok?
|
194
|
+
[X] File#specfile?
|
195
|
+
[X] File#ghost?
|
196
|
+
[X] File#license?
|
197
|
+
[X] File#readme?
|
198
|
+
[X] File#exclude?
|
199
|
+
[X] File#replaced?
|
200
|
+
[X] File#notinstalled?
|
201
|
+
[X] File#netshared?
|
202
|
+
|
203
|
+
* RPM::DB
|
204
|
+
|
205
|
+
[ ] DB (Enumerable)
|
206
|
+
[ ] DB#new
|
207
|
+
[ ] DB#open
|
208
|
+
[ ] DB#init
|
209
|
+
[ ] DB#rebuild
|
210
|
+
[ ] DB#close
|
211
|
+
[ ] DB#closed?
|
212
|
+
[ ] DB#root
|
213
|
+
[ ] DB#home
|
214
|
+
[ ] DB#writable?
|
215
|
+
[ ] DB#each_match
|
216
|
+
[ ] DB#each
|
217
|
+
[ ] DB#transaction
|
218
|
+
[ ] DB#init_iterator
|
219
|
+
[ ] DB#dup
|
220
|
+
[ ] DB#clone
|
221
|
+
|
222
|
+
* RPM::MatchIterator
|
223
|
+
|
224
|
+
[X] MatchIterator (Enumerable)
|
225
|
+
[X] MatchIterator#each
|
226
|
+
[X] MatchIterator#next_iterator
|
227
|
+
[X] MatchIterator#offset
|
228
|
+
[X] MatchIterator#set_iterator_re
|
229
|
+
[X] MatchIterator#regexp
|
230
|
+
[X] MatchIterator#set_iterator_version
|
231
|
+
[X] MatchIterator#version
|
232
|
+
[X] MatchIterator#get_iterator_count
|
233
|
+
[X] MatchIterator#length
|
234
|
+
|
235
|
+
* RPM::Transaction
|
236
|
+
|
237
|
+
[ ] Transaction#db
|
238
|
+
[ ] Transaction#script_file
|
239
|
+
[ ] Transaction#script_file=
|
240
|
+
[ ] Transaction#install
|
241
|
+
[ ] Transaction#upgrade
|
242
|
+
[ ] Transaction#available
|
243
|
+
[ ] Transaction#delete
|
244
|
+
[ ] Transaction#check
|
245
|
+
[ ] Transaction#order
|
246
|
+
[ ] Transaction#keys
|
247
|
+
[ ] Transaction#commit
|
248
|
+
[ ] Transaction#abort
|
249
|
+
[ ] Transaction#dup
|
250
|
+
[ ] Transaction#clone
|
251
|
+
|
252
|
+
* RPM::Source
|
253
|
+
|
254
|
+
[ ] Source#initialize
|
255
|
+
[ ] Source#fullname
|
256
|
+
[ ] Source#to_s (alias fullname)
|
257
|
+
[ ] Source#num
|
258
|
+
[ ] Source#no?
|
259
|
+
|
260
|
+
* RPM::Patch
|
261
|
+
* RPM::Icon
|
262
|
+
|
263
|
+
* RPM::Spec
|
264
|
+
|
265
|
+
[ ] Spec#open
|
266
|
+
[ ] Spec#new
|
267
|
+
[ ] Spec#buildroot
|
268
|
+
[ ] Spec#buildsubdir
|
269
|
+
[ ] Spec#buildarchs
|
270
|
+
[ ] Spec#buildrequires
|
271
|
+
[ ] Spec#build_restrictions
|
272
|
+
[ ] Spec#sources
|
273
|
+
[ ] Spec#packages
|
274
|
+
[ ] Spec#build
|
275
|
+
[ ] Spec#expand_macros
|
276
|
+
[ ] Spec#dup
|
277
|
+
[ ] Spec#clone
|
278
|
+
|
279
|
+
== TODO
|
280
|
+
|
281
|
+
* Check Package#signature should return String?
|
282
|
+
=> ruby-rpm seems to return symbol
|
283
|
+
* Food for thought: Package dependencies and changelog
|
284
|
+
methods could just use []. Calling headerGet directly saves
|
285
|
+
us from doing one iteration per attribute
|
286
|
+
* Not sure if Spec can be implemented as it was before with
|
287
|
+
newer rpms.
|
288
|
+
|
289
|
+
= LICENSE
|
290
|
+
|
291
|
+
* Copyright © 2011 Duncan Mac-Vicar Prett <dmacvicar@suse.de>
|
292
|
+
* Copyright © 2011 SUSE Linux Products GmbH
|
293
|
+
|
294
|
+
* This gem is a pure-ruby rewrite of ruby-rpm:
|
295
|
+
Copyright © 2002 Kenta Murata. Relicensed with his permission.
|
296
|
+
|
297
|
+
Licensed under the MIT license. See MIT-LICENSE for details.
|
298
|
+
|
data/Rakefile
CHANGED
@@ -1 +1,32 @@
|
|
1
|
-
|
1
|
+
$:.push(File.join(File.dirname(__FILE__), 'lib'))
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
require 'rpm/gem_version'
|
4
|
+
require 'rake/testtask'
|
5
|
+
|
6
|
+
task :default => [:test]
|
7
|
+
|
8
|
+
Rake::TestTask.new do |t|
|
9
|
+
t.libs << File.expand_path('../test', __FILE__)
|
10
|
+
t.libs << File.expand_path('../', __FILE__)
|
11
|
+
t.test_files = FileList['test/test*.rb']
|
12
|
+
t.verbose = true
|
13
|
+
t.loader = :direct
|
14
|
+
end
|
15
|
+
|
16
|
+
extra_docs = ['README*', 'TODO*', 'CHANGELOG*']
|
17
|
+
|
18
|
+
begin
|
19
|
+
require 'yard'
|
20
|
+
YARD::Rake::YardocTask.new(:doc) do |t|
|
21
|
+
t.files = ['lib/**/*.rb', *extra_docs]
|
22
|
+
t.options = ['--no-private']
|
23
|
+
end
|
24
|
+
rescue LoadError
|
25
|
+
STDERR.puts "Install yard if you want prettier docs"
|
26
|
+
require 'rdoc/task'
|
27
|
+
Rake::RDocTask.new(:doc) do |rdoc|
|
28
|
+
rdoc.rdoc_dir = "doc"
|
29
|
+
rdoc.title = "rpm for Ruby #{RPM::GEM_VERSION}"
|
30
|
+
extra_docs.each { |ex| rdoc.rdoc_files.include ex }
|
31
|
+
end
|
32
|
+
end
|
data/lib/rpm/compat.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'rpm'
|
2
|
+
|
3
|
+
module RPM
|
4
|
+
|
5
|
+
# compatibility
|
6
|
+
TAG.to_h.each do |k,v|
|
7
|
+
const_set "TAG_#{k.to_s.upcase}", v.to_i
|
8
|
+
end
|
9
|
+
|
10
|
+
LOG.to_h.each do |k, v|
|
11
|
+
const_set "LOG_#{k.to_s.upcase}", v.to_i
|
12
|
+
end
|
13
|
+
|
14
|
+
SENSE.to_h.each do |k, v|
|
15
|
+
const_set "SENSE_#{k.to_s.upcase}", v.to_i
|
16
|
+
end
|
17
|
+
|
18
|
+
# RPMFILE_*
|
19
|
+
FILE.to_h.each do |k, v|
|
20
|
+
const_set "FILE_#{k.to_s.upcase}", v.to_i
|
21
|
+
end
|
22
|
+
|
23
|
+
# RPMFILE_STATE_*
|
24
|
+
FILE_STATE.to_h.each do |k, v|
|
25
|
+
const_set "FILE_STATE_#{k.to_s.upcase}", v.to_i
|
26
|
+
end
|
27
|
+
|
28
|
+
# RPMTRANS_FLAG_*
|
29
|
+
TRANS_FLAG.to_h.each do |k, v|
|
30
|
+
const_set "TRANS_FLAG_#{k.to_s.upcase}", v.to_i
|
31
|
+
end
|
32
|
+
|
33
|
+
# RPMPROB_FILTER_*
|
34
|
+
PROB_FILTER.to_h.each do |k, v|
|
35
|
+
const_set "PROB_FILTER_#{k.to_s.upcase}", v.to_i
|
36
|
+
end
|
37
|
+
|
38
|
+
# RPMPROB_FILTER_*
|
39
|
+
MIRE.to_h.each do |k, v|
|
40
|
+
const_set "MIRE_#{k.to_s.upcase}", v.to_i
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
data/lib/rpm/db.rb
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
require 'fcntl'
|
2
|
+
|
3
|
+
module RPM
|
4
|
+
|
5
|
+
class DB
|
6
|
+
|
7
|
+
include Enumerable
|
8
|
+
|
9
|
+
# @visibility private
|
10
|
+
# @param ts [Transaction] transaction object
|
11
|
+
def initialize(ts, opts={})
|
12
|
+
opts[:writable] ||= false
|
13
|
+
|
14
|
+
@ts = ts
|
15
|
+
RPM::FFI.rpmtsOpenDB(@ts.ptr, opts[:writable] ? Fcntl::O_RDWR | Fcntl::O_CREAT : Fcntl::O_RDONLY )
|
16
|
+
end
|
17
|
+
|
18
|
+
# @return [RPM::MatchIterator] Creates an iterator for +tag+ and +val+
|
19
|
+
def init_iterator(tag, val)
|
20
|
+
@ts.init_iterator(tag, val)
|
21
|
+
end
|
22
|
+
|
23
|
+
#
|
24
|
+
# @yield [Package] Called for each match
|
25
|
+
# @param [Number] key RPM tag key
|
26
|
+
# @param [String] val Value to match
|
27
|
+
# @example
|
28
|
+
# RPM.transaction do |t|
|
29
|
+
# t.each_match(RPM::TAG_ARCH, "x86_64") do |pkg|
|
30
|
+
# puts pkg.name
|
31
|
+
# end
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
def each_match(key, val, &block)
|
35
|
+
@ts.each_match(key, val, &block)
|
36
|
+
end
|
37
|
+
|
38
|
+
#
|
39
|
+
# @yield [Package] Called for each package in the database
|
40
|
+
# @example
|
41
|
+
# db.each do |pkg|
|
42
|
+
# puts pkg.name
|
43
|
+
# end
|
44
|
+
#
|
45
|
+
def each(&block)
|
46
|
+
@ts.each(&block)
|
47
|
+
end
|
48
|
+
|
49
|
+
# @visibility private
|
50
|
+
def ptr
|
51
|
+
RPM::FFI.rpmtsGetRdb(@ts.ptr)
|
52
|
+
end
|
53
|
+
|
54
|
+
def close
|
55
|
+
RPM::FFI.rpmtsCloseDB(@ts.ptr)
|
56
|
+
end
|
57
|
+
|
58
|
+
def closed?
|
59
|
+
ptr.null?
|
60
|
+
end
|
61
|
+
|
62
|
+
#
|
63
|
+
# The package database is opened, but transactional processing
|
64
|
+
# (@see RPM::DB#transaction) cannot be done for when +writable+ is false.
|
65
|
+
# When +writable+ is +false+ then the generated object gets freezed.
|
66
|
+
# @param [Boolean] writable Whether the database is writable. Default is +false+.
|
67
|
+
# @param [String] root Root path for the database, default is empty.
|
68
|
+
# @return [RPM::DB]
|
69
|
+
#
|
70
|
+
# @example
|
71
|
+
# db = RPM::DB.open
|
72
|
+
# db.each do |pkg|
|
73
|
+
# puts pkg.name
|
74
|
+
# end
|
75
|
+
#
|
76
|
+
def self.open(writable=false, root='/', &block)
|
77
|
+
open_for_transaction(Transaction.new(:root => root), :writable => false, &block)
|
78
|
+
end
|
79
|
+
|
80
|
+
# @visibility private
|
81
|
+
def self.open_for_transaction(ts, opts={})
|
82
|
+
db = new(ts, opts)
|
83
|
+
return db unless block_given?
|
84
|
+
|
85
|
+
begin
|
86
|
+
yield db
|
87
|
+
ensure
|
88
|
+
db.close unless db.closed?
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
# @deprecated Not possible to get home value in
|
94
|
+
# newer RPM versions
|
95
|
+
def home
|
96
|
+
raise NotImplementedError
|
97
|
+
end
|
98
|
+
|
99
|
+
# @return [String] The root path of the database
|
100
|
+
def root
|
101
|
+
RPM::FFI.rpmtsRootDir(@ts.ptr)
|
102
|
+
end
|
103
|
+
|
104
|
+
# @deprecated Use RPM::Transaction#each
|
105
|
+
def self.each
|
106
|
+
DB.open do |db|
|
107
|
+
it = MatchIterator.from_ptr(RPM::FFI.rpmdbInitIterator(db.ptr, 0, nil, 0))
|
108
|
+
if block_given?
|
109
|
+
it.each do |pkg|
|
110
|
+
yield pkg
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
# @return number of instances of +name+ in the
|
117
|
+
# database
|
118
|
+
def count_packages(name)
|
119
|
+
end
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
require 'rpm'
|
2
|
+
|
3
|
+
module RPM
|
4
|
+
|
5
|
+
class Dependency
|
6
|
+
|
7
|
+
# @return [String] dependency name
|
8
|
+
attr_accessor :name
|
9
|
+
# @return [String] dependency version
|
10
|
+
attr_accessor :version
|
11
|
+
# @return [String] dependency flags
|
12
|
+
attr_accessor :flags
|
13
|
+
# @return [Package] package this dependency belongs to
|
14
|
+
attr_accessor :owner
|
15
|
+
|
16
|
+
attr_accessor :nametag
|
17
|
+
attr_accessor :versiontag
|
18
|
+
attr_accessor :flagstag
|
19
|
+
|
20
|
+
def initialize(name, version, flags, owner)
|
21
|
+
|
22
|
+
RPM::Utils.check_type(version, RPM::Version)
|
23
|
+
|
24
|
+
@name = name
|
25
|
+
@version = version
|
26
|
+
@flags = flags
|
27
|
+
@owner = owner
|
28
|
+
end
|
29
|
+
|
30
|
+
# @param [Package, Dependency, Version] other
|
31
|
+
# @return [Boolean] true if +other+ satisfies this dependency
|
32
|
+
def satisfy?(other)
|
33
|
+
case other
|
34
|
+
when RPM::Package then
|
35
|
+
other.provides.each do |prov|
|
36
|
+
return true if self.satisfy?(prov)
|
37
|
+
end
|
38
|
+
return false
|
39
|
+
when RPM::Dependency then
|
40
|
+
RPM::FFI.rpmdsCompare(
|
41
|
+
RPM::FFI.rpmdsSingle(:providename, other.name,
|
42
|
+
other.version.to_vre, other.flags),
|
43
|
+
RPM::FFI.rpmdsSingle(:providename, name,
|
44
|
+
version.to_vre, flags)) != 0
|
45
|
+
when RPM::Version then
|
46
|
+
RPM::FFI.rpmdsCompare(
|
47
|
+
RPM::FFI.rpmdsSingle(:providename, name,
|
48
|
+
other.to_vre, other.to_vre.empty? ? 0 : :equal),
|
49
|
+
RPM::FFI.rpmdsSingle(:providename, name,
|
50
|
+
version.to_vre, flags)) != 0
|
51
|
+
else
|
52
|
+
raise(TypeError, "#{other} is not a Version or Dependency")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# @return [Boolean] true if '<' or '=<' are used to compare the version
|
57
|
+
def lt?
|
58
|
+
flags & RPM::SENSE[:less]
|
59
|
+
end
|
60
|
+
|
61
|
+
# @return [Boolean] true if '>' or '>=' are used to compare the version
|
62
|
+
def gt?
|
63
|
+
flags & RPM::SENSE[:greater]
|
64
|
+
end
|
65
|
+
|
66
|
+
# @return [Boolean] true if '=', '=<' or '>=' are used to compare the version
|
67
|
+
def eq?
|
68
|
+
flags & RPM::SENSE[:equal]
|
69
|
+
end
|
70
|
+
|
71
|
+
# @return [Boolean] true if '=<' is used to compare the version
|
72
|
+
def le?
|
73
|
+
(flags & RPM::SENSE[:less]) && (flags & RPMSENSE[:equal])
|
74
|
+
end
|
75
|
+
|
76
|
+
# @return [Boolean] true if '>=' is used to compare the version
|
77
|
+
def ge?
|
78
|
+
(flags & RPM::SENSE[:greater]) && (flags & RPMSENSE[:equal])
|
79
|
+
end
|
80
|
+
|
81
|
+
# @return [Boolean] true if this is a pre-requires
|
82
|
+
def pre?
|
83
|
+
flags & RPM::SENSE[:prereq]
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
class Provide < Dependency
|
89
|
+
|
90
|
+
def initialize(name, version, flags, owner)
|
91
|
+
super(name, version, flags, owner)
|
92
|
+
@nametag = RPM::TAG[:providename]
|
93
|
+
@versiontag = RPM::TAG[:provideversion]
|
94
|
+
@flagstag = RPM::TAG[:provideflags]
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
class Require < Dependency
|
100
|
+
|
101
|
+
def initialize(name, version, flags, owner)
|
102
|
+
super(name, version, flags, owner)
|
103
|
+
@nametag = RPM::TAG[:requirename]
|
104
|
+
@versiontag = RPM::TAG[:requireversion]
|
105
|
+
@flagstag = RPM::TAG[:requireflags]
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
class Conflict < Dependency
|
111
|
+
|
112
|
+
def initialize(name, version, flags, owner)
|
113
|
+
super(name, version, flags, owner)
|
114
|
+
@nametag = RPM::TAG[:conflictname]
|
115
|
+
@versiontag = RPM::TAG[:conflictversion]
|
116
|
+
@flagstag = RPM::TAG[:conflictflags]
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
class Conflict < Dependency
|
122
|
+
|
123
|
+
def initialize(name, version, flags, owner)
|
124
|
+
super(name, version, flags, owner)
|
125
|
+
@nametag = RPM::TAG[:conflictname]
|
126
|
+
@versiontag = RPM::TAG[:conflictversion]
|
127
|
+
@flagstag = RPM::TAG[:conflictflags]
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
|
2
|
+
module RPM
|
3
|
+
|
4
|
+
module FFI
|
5
|
+
|
6
|
+
typedef :pointer, :header
|
7
|
+
|
8
|
+
attach_function 'headerNew', [], :header
|
9
|
+
attach_function 'headerFree', [:header], :header
|
10
|
+
attach_function 'headerLink', [:header], :header
|
11
|
+
# ..
|
12
|
+
HEADERGET_DEFAULT = 0,
|
13
|
+
HEADERGET_MINMEM = (1 << 0)
|
14
|
+
HEADERGET_EXT = (1 << 1)
|
15
|
+
HEADERGET_RAW = (1 << 2)
|
16
|
+
HEADERGET_ALLOC = (1 << 3)
|
17
|
+
HEADERGET_ARGV = (1 << 4)
|
18
|
+
|
19
|
+
# ..
|
20
|
+
attach_function 'headerGet', [:header, :rpmTagVal, :pointer, :uint32], :int
|
21
|
+
attach_function 'headerPut', [:header, :pointer, :uint32], :int
|
22
|
+
# ...
|
23
|
+
attach_function 'headerFormat', [:header, :string, :pointer], :pointer
|
24
|
+
# ...
|
25
|
+
attach_function 'headerNVR', [:header, :pointer, :pointer, :pointer], :int
|
26
|
+
# ...
|
27
|
+
attach_function 'headerGetAsString', [:header, :rpmTagVal], :string
|
28
|
+
# ...
|
29
|
+
attach_function 'headerPutString', [:header, :rpmTagVal, :string], :int
|
30
|
+
# ...
|
31
|
+
attach_function 'headerPutUint32', [:header, :rpmTagVal, :pointer, :rpm_count_t], :int
|
32
|
+
# ...
|
33
|
+
attach_function 'rpmReadPackageFile', [:header, :FD_t, :string, :pointer], Rc
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|