rpm2 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.github/CODEOWNERS +1 -0
- data/.github/workflows/ci.yaml +25 -0
- data/.gitignore +8 -0
- data/.rubocop.yml +1 -0
- data/.rubocop_todo.yml +111 -0
- data/.whitesource +3 -0
- data/CHANGELOG.md +66 -0
- data/Gemfile +9 -0
- data/MIT-LICENSE +23 -0
- data/README.md +374 -0
- data/Rakefile +58 -0
- data/_docker/Dockerfile.ubi8 +8 -0
- data/_docker/Dockerfile.ubi9 +8 -0
- data/lib/rpm/c/header.rb +36 -0
- data/lib/rpm/c/rpmcallback.rb +27 -0
- data/lib/rpm/c/rpmcli.rb +6 -0
- data/lib/rpm/c/rpmdb.rb +20 -0
- data/lib/rpm/c/rpmds.rb +43 -0
- data/lib/rpm/c/rpmfi.rb +31 -0
- data/lib/rpm/c/rpmio.rb +17 -0
- data/lib/rpm/c/rpmlib.rb +12 -0
- data/lib/rpm/c/rpmlog.rb +23 -0
- data/lib/rpm/c/rpmmacro.rb +33 -0
- data/lib/rpm/c/rpmprob.rb +53 -0
- data/lib/rpm/c/rpmps.rb +11 -0
- data/lib/rpm/c/rpmtag.rb +304 -0
- data/lib/rpm/c/rpmtd.rb +34 -0
- data/lib/rpm/c/rpmts.rb +69 -0
- data/lib/rpm/c/rpmtypes.rb +28 -0
- data/lib/rpm/c.rb +49 -0
- data/lib/rpm/compat.rb +40 -0
- data/lib/rpm/db.rb +117 -0
- data/lib/rpm/dependency.rb +120 -0
- data/lib/rpm/file.rb +134 -0
- data/lib/rpm/gem_version.rb +7 -0
- data/lib/rpm/match_iterator.rb +66 -0
- data/lib/rpm/package.rb +332 -0
- data/lib/rpm/problem.rb +65 -0
- data/lib/rpm/transaction.rb +268 -0
- data/lib/rpm/utils.rb +7 -0
- data/lib/rpm/version.rb +146 -0
- data/lib/rpm.rb +88 -0
- data/lib/rpm2.rb +1 -0
- data/rpm2.gemspec +29 -0
- data/test/data/a.spec +49 -0
- data/test/data/simple-1.0-0.i586.rpm +0 -0
- data/test/data/simple.spec +38 -0
- 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 +7 -0
- data/test/test_dependency.rb +28 -0
- data/test/test_file.rb +36 -0
- data/test/test_lib.rb +33 -0
- data/test/test_package.rb +76 -0
- data/test/test_problem.rb +18 -0
- data/test/test_rpm.rb +33 -0
- data/test/test_transaction.rb +156 -0
- data/test/test_version.rb +64 -0
- metadata +133 -0
data/lib/rpm/c/rpmts.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
module RPM
|
2
|
+
module C
|
3
|
+
TransFlags = enum(:rpmtransFlags_e, [
|
4
|
+
:none, 0,
|
5
|
+
:test, (1 << 0),
|
6
|
+
:build_probs, (1 << 1),
|
7
|
+
:noscripts, (1 << 2),
|
8
|
+
:justdb, (1 << 3),
|
9
|
+
:notriggers, (1 << 4),
|
10
|
+
:nodocs, (1 << 5),
|
11
|
+
:allfiles, (1 << 6),
|
12
|
+
# bit 7 unused
|
13
|
+
:nocontexts, (1 << 8),
|
14
|
+
# bits 9-15 unused
|
15
|
+
:notriggerprein, (1 << 16),
|
16
|
+
:nopre, (1 << 17),
|
17
|
+
:nopost, (1 << 18),
|
18
|
+
:notriggerin, (1 << 19),
|
19
|
+
:notriggerun, (1 << 20),
|
20
|
+
:nopreun, (1 << 21),
|
21
|
+
:nopostun, (1 << 22),
|
22
|
+
:notriggerpostun, (11 << 23),
|
23
|
+
# bits 24-25 unused
|
24
|
+
:nocollections, (1 << 26),
|
25
|
+
:nomd5, (1 << 27),
|
26
|
+
:nofiledigest, (1 << 27),
|
27
|
+
# bits 28-29 unused
|
28
|
+
:noconfigs, (1 << 30),
|
29
|
+
:deploops, (1 << 31)
|
30
|
+
])
|
31
|
+
|
32
|
+
typedef :pointer, :rpmts
|
33
|
+
typedef :pointer, :rpmps
|
34
|
+
typedef :rpmFlags, :rpmtransFlags
|
35
|
+
|
36
|
+
attach_function 'rpmtsCheck', [:rpmts], :int
|
37
|
+
attach_function 'rpmtsOrder', [:rpmts], :int
|
38
|
+
attach_function 'rpmtsRun', %i[rpmts rpmps int], :int
|
39
|
+
attach_function 'rpmtsLink', [:rpmts], :rpmts
|
40
|
+
attach_function 'rpmtsCloseDB', [:rpmts], :int
|
41
|
+
attach_function 'rpmtsOpenDB', %i[rpmts int], :int
|
42
|
+
attach_function 'rpmtsInitDB', %i[rpmts int], :int
|
43
|
+
attach_function 'rpmtsGetDBMode', [:rpmts], :int
|
44
|
+
attach_function 'rpmtsSetDBMode', %i[rpmts int], :int
|
45
|
+
attach_function 'rpmtsRebuildDB', [:rpmts], :int
|
46
|
+
attach_function 'rpmtsVerifyDB', [:rpmts], :int
|
47
|
+
attach_function 'rpmtsInitIterator', %i[rpmts rpmDbiTagVal pointer int], :rpmdbMatchIterator
|
48
|
+
# ...
|
49
|
+
attach_function 'rpmtsProblems', [:rpmts], :rpmps
|
50
|
+
# ...
|
51
|
+
attach_function 'rpmtsClean', [:rpmts], :void
|
52
|
+
# more...
|
53
|
+
attach_function 'rpmtsFree', [:rpmts], :pointer
|
54
|
+
# ..
|
55
|
+
attach_function 'rpmtsSetNotifyCallback', %i[rpmts rpmCallbackFunction rpmCallbackData], :int
|
56
|
+
# ...
|
57
|
+
attach_function 'rpmtsRootDir', [:rpmts], :string
|
58
|
+
attach_function 'rpmtsSetRootDir', %i[rpmts string], :int
|
59
|
+
# ...
|
60
|
+
attach_function 'rpmtsGetRdb', [:rpmts], :rpmdb
|
61
|
+
# ..
|
62
|
+
attach_function 'rpmtsFlags', [:rpmts], :rpmtransFlags
|
63
|
+
attach_function 'rpmtsSetFlags', %i[rpmts rpmtransFlags], :rpmtransFlags
|
64
|
+
# ...
|
65
|
+
attach_function 'rpmtsCreate', [], :rpmts
|
66
|
+
attach_function 'rpmtsAddInstallElement', %i[rpmts header fnpyKey int rpmRelocation], :int
|
67
|
+
attach_function 'rpmtsAddEraseElement', %i[rpmts header int], :int
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
|
2
|
+
module RPM
|
3
|
+
module C
|
4
|
+
Rc = enum(
|
5
|
+
:ok, 0,
|
6
|
+
:notfound, 1,
|
7
|
+
:fail, 2,
|
8
|
+
:nottrusted, 3,
|
9
|
+
:nokey, 4
|
10
|
+
)
|
11
|
+
|
12
|
+
typedef :int32, :rpm_tag_t
|
13
|
+
typedef :uint32, :rpm_tagtype_t
|
14
|
+
typedef :uint32, :rpm_count_t
|
15
|
+
typedef :rpm_tag_t, :rpmTagVal
|
16
|
+
typedef :rpm_tag_t, :rpmDbiTagVal
|
17
|
+
|
18
|
+
typedef :uint32, :rpmFlags
|
19
|
+
typedef :uint32, :rpm_off_t
|
20
|
+
typedef :uint64, :rpm_loff_t
|
21
|
+
|
22
|
+
typedef :pointer, :FD_t
|
23
|
+
typedef :pointer, :fnpyKey
|
24
|
+
typedef :pointer, :rpmCallbackData
|
25
|
+
|
26
|
+
typedef :uint64, :rpm_loff_t
|
27
|
+
end
|
28
|
+
end
|
data/lib/rpm/c.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'ffi'
|
2
|
+
|
3
|
+
module RPM
|
4
|
+
module C
|
5
|
+
extend ::FFI::Library
|
6
|
+
|
7
|
+
begin
|
8
|
+
ffi_lib ['rpm',
|
9
|
+
'librpm.so.9',
|
10
|
+
'librpm.so.8', # Tumbleweed
|
11
|
+
'librpm.so.7', # fedora 23
|
12
|
+
'librpm.so.3', 'librpm.so.2', 'librpm.so.1']
|
13
|
+
rescue LoadError => e
|
14
|
+
raise(
|
15
|
+
"Can't find rpm libs on your system: #{e.message}"
|
16
|
+
)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'rpm/c/rpmtypes'
|
22
|
+
require 'rpm/c/rpmcallback'
|
23
|
+
require 'rpm/c/rpmtag'
|
24
|
+
require 'rpm/c/rpmlib'
|
25
|
+
|
26
|
+
module RPM
|
27
|
+
module C
|
28
|
+
|
29
|
+
def self.rpm_version_code
|
30
|
+
ver = ::RPM::C.RPMVERSION.split('.', 3)
|
31
|
+
return (ver[0].to_i<<16) + (ver[1].to_i<<8) + (ver[2].to_i<<0)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
require 'rpm/c/rpmlog'
|
38
|
+
require 'rpm/c/rpmmacro'
|
39
|
+
require 'rpm/c/rpmio'
|
40
|
+
require 'rpm/c/header'
|
41
|
+
require 'rpm/c/rpmprob'
|
42
|
+
require 'rpm/c/rpmps'
|
43
|
+
require 'rpm/c/rpmfi'
|
44
|
+
require 'rpm/c/rpmdb'
|
45
|
+
require 'rpm/c/rpmcallback'
|
46
|
+
require 'rpm/c/rpmcli'
|
47
|
+
require 'rpm/c/rpmts'
|
48
|
+
require 'rpm/c/rpmds'
|
49
|
+
require 'rpm/c/rpmtd'
|
data/lib/rpm/compat.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
|
2
|
+
module RPM
|
3
|
+
# compatibility
|
4
|
+
TAG.to_h.each do |k, v|
|
5
|
+
const_set "TAG_#{k.to_s.upcase}", v.to_i
|
6
|
+
end
|
7
|
+
|
8
|
+
LOG.to_h.each do |k, v|
|
9
|
+
const_set "LOG_#{k.to_s.upcase}", v.to_i
|
10
|
+
end
|
11
|
+
|
12
|
+
SENSE.to_h.each do |k, v|
|
13
|
+
const_set "SENSE_#{k.to_s.upcase}", v.to_i
|
14
|
+
end
|
15
|
+
|
16
|
+
# RPMFILE_*
|
17
|
+
FILE.to_h.each do |k, v|
|
18
|
+
const_set "FILE_#{k.to_s.upcase}", v.to_i
|
19
|
+
end
|
20
|
+
|
21
|
+
# RPMFILE_STATE_*
|
22
|
+
FILE_STATE.to_h.each do |k, v|
|
23
|
+
const_set "FILE_STATE_#{k.to_s.upcase}", v.to_i
|
24
|
+
end
|
25
|
+
|
26
|
+
# RPMTRANS_FLAG_*
|
27
|
+
TRANS_FLAG.to_h.each do |k, v|
|
28
|
+
const_set "TRANS_FLAG_#{k.to_s.upcase}", v.to_i
|
29
|
+
end
|
30
|
+
|
31
|
+
# RPMPROB_FILTER_*
|
32
|
+
PROB_FILTER.to_h.each do |k, v|
|
33
|
+
const_set "PROB_FILTER_#{k.to_s.upcase}", v.to_i
|
34
|
+
end
|
35
|
+
|
36
|
+
# RPMPROB_FILTER_*
|
37
|
+
MIRE.to_h.each do |k, v|
|
38
|
+
const_set "MIRE_#{k.to_s.upcase}", v.to_i
|
39
|
+
end
|
40
|
+
end
|
data/lib/rpm/db.rb
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
require 'fcntl'
|
2
|
+
|
3
|
+
module RPM
|
4
|
+
class DB
|
5
|
+
include Enumerable
|
6
|
+
|
7
|
+
# @visibility private
|
8
|
+
# @param ts [Transaction] transaction object
|
9
|
+
def initialize(ts, opts = {})
|
10
|
+
opts[:writable] ||= false
|
11
|
+
|
12
|
+
@ts = ts
|
13
|
+
RPM::C.rpmtsOpenDB(@ts.ptr, opts[:writable] ? Fcntl::O_RDWR | Fcntl::O_CREAT : Fcntl::O_RDONLY)
|
14
|
+
end
|
15
|
+
|
16
|
+
# @return [RPM::MatchIterator] Creates an iterator for +tag+ and +val+
|
17
|
+
def init_iterator(tag, val)
|
18
|
+
@ts.init_iterator(tag, val)
|
19
|
+
end
|
20
|
+
|
21
|
+
#
|
22
|
+
# @yield [Package] Called for each match
|
23
|
+
# @param [Number] key RPM tag key
|
24
|
+
# @param [String] val Value to match
|
25
|
+
# @example
|
26
|
+
# RPM.transaction do |t|
|
27
|
+
# t.each_match(RPM::TAG_ARCH, "x86_64") do |pkg|
|
28
|
+
# puts pkg.name
|
29
|
+
# end
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
def each_match(key, val, &block)
|
33
|
+
@ts.each_match(key, val, &block)
|
34
|
+
end
|
35
|
+
|
36
|
+
#
|
37
|
+
# @yield [Package] Called for each package in the database
|
38
|
+
# @example
|
39
|
+
# db.each do |pkg|
|
40
|
+
# puts pkg.name
|
41
|
+
# end
|
42
|
+
#
|
43
|
+
def each(&block)
|
44
|
+
@ts.each(&block)
|
45
|
+
end
|
46
|
+
|
47
|
+
# @visibility private
|
48
|
+
def ptr
|
49
|
+
RPM::C.rpmtsGetRdb(@ts.ptr)
|
50
|
+
end
|
51
|
+
|
52
|
+
def close
|
53
|
+
RPM::C.rpmtsCloseDB(@ts.ptr)
|
54
|
+
end
|
55
|
+
|
56
|
+
def closed?
|
57
|
+
ptr.null?
|
58
|
+
end
|
59
|
+
|
60
|
+
#
|
61
|
+
# The package database is opened, but transactional processing
|
62
|
+
# (@see RPM::DB#transaction) cannot be done for when +writable+ is false.
|
63
|
+
# When +writable+ is +false+ then the generated object gets freezed.
|
64
|
+
# @param [Boolean] writable Whether the database is writable. Default is +false+.
|
65
|
+
# @param [String] root Root path for the database, default is empty.
|
66
|
+
# @return [RPM::DB]
|
67
|
+
#
|
68
|
+
# @example
|
69
|
+
# db = RPM::DB.open
|
70
|
+
# db.each do |pkg|
|
71
|
+
# puts pkg.name
|
72
|
+
# end
|
73
|
+
#
|
74
|
+
def self.open(_writable = false, root = '/', &block)
|
75
|
+
open_for_transaction(Transaction.new(root: root), writable: false, &block)
|
76
|
+
end
|
77
|
+
|
78
|
+
# @visibility private
|
79
|
+
def self.open_for_transaction(ts, opts = {})
|
80
|
+
db = new(ts, opts)
|
81
|
+
return db unless block_given?
|
82
|
+
|
83
|
+
begin
|
84
|
+
yield db
|
85
|
+
ensure
|
86
|
+
db.close unless db.closed?
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# @deprecated Not possible to get home value in
|
91
|
+
# newer RPM versions
|
92
|
+
def home
|
93
|
+
raise NotImplementedError
|
94
|
+
end
|
95
|
+
|
96
|
+
# @return [String] The root path of the database
|
97
|
+
def root
|
98
|
+
RPM::C.rpmtsRootDir(@ts.ptr)
|
99
|
+
end
|
100
|
+
|
101
|
+
# @deprecated Use RPM::Transaction#each
|
102
|
+
def self.each
|
103
|
+
DB.open do |db|
|
104
|
+
it = MatchIterator.from_ptr(RPM::C.rpmdbInitIterator(db.ptr, 0, nil, 0))
|
105
|
+
if block_given?
|
106
|
+
it.each do |pkg|
|
107
|
+
yield pkg
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
# @return number of instances of +name+ in the
|
114
|
+
# database
|
115
|
+
def count_packages(name); end
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
|
2
|
+
module RPM
|
3
|
+
class Dependency
|
4
|
+
# @return [String] dependency name
|
5
|
+
attr_accessor :name
|
6
|
+
# @return [String] dependency version
|
7
|
+
attr_accessor :version
|
8
|
+
# @return [String] dependency flags
|
9
|
+
attr_accessor :flags
|
10
|
+
# @return [Package] package this dependency belongs to
|
11
|
+
attr_accessor :owner
|
12
|
+
|
13
|
+
attr_accessor :nametag
|
14
|
+
attr_accessor :versiontag
|
15
|
+
attr_accessor :flagstag
|
16
|
+
|
17
|
+
def initialize(name, version, flags, owner)
|
18
|
+
RPM::Utils.check_type(version, RPM::Version)
|
19
|
+
|
20
|
+
@name = name
|
21
|
+
@version = version
|
22
|
+
@flags = flags
|
23
|
+
@owner = owner
|
24
|
+
end
|
25
|
+
|
26
|
+
# @param [Package, Dependency, Version] other
|
27
|
+
# @return [Boolean] true if +other+ satisfies this dependency
|
28
|
+
def satisfy?(other)
|
29
|
+
case other
|
30
|
+
when RPM::Package then
|
31
|
+
other.provides.each do |prov|
|
32
|
+
return true if satisfy?(prov)
|
33
|
+
end
|
34
|
+
false
|
35
|
+
when RPM::Dependency then
|
36
|
+
RPM::C.rpmdsCompare(
|
37
|
+
RPM::C.rpmdsSingle(:providename, other.name,
|
38
|
+
other.version.to_vre, other.flags),
|
39
|
+
RPM::C.rpmdsSingle(:providename, name,
|
40
|
+
version.to_vre, flags)
|
41
|
+
) != 0
|
42
|
+
when RPM::Version then
|
43
|
+
RPM::C.rpmdsCompare(
|
44
|
+
RPM::C.rpmdsSingle(:providename, name,
|
45
|
+
other.to_vre, other.to_vre.empty? ? 0 : :equal),
|
46
|
+
RPM::C.rpmdsSingle(:providename, name,
|
47
|
+
version.to_vre, flags)
|
48
|
+
) != 0
|
49
|
+
else
|
50
|
+
raise(TypeError, "#{other} is not a Version or Dependency")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# @return [Boolean] true if '<' or '=<' are used to compare the version
|
55
|
+
def lt?
|
56
|
+
flags & RPM::SENSE[:less]
|
57
|
+
end
|
58
|
+
|
59
|
+
# @return [Boolean] true if '>' or '>=' are used to compare the version
|
60
|
+
def gt?
|
61
|
+
flags & RPM::SENSE[:greater]
|
62
|
+
end
|
63
|
+
|
64
|
+
# @return [Boolean] true if '=', '=<' or '>=' are used to compare the version
|
65
|
+
def eq?
|
66
|
+
flags & RPM::SENSE[:equal]
|
67
|
+
end
|
68
|
+
|
69
|
+
# @return [Boolean] true if '=<' is used to compare the version
|
70
|
+
def le?
|
71
|
+
(flags & RPM::SENSE[:less]) && (flags & RPM::SENSE[:equal])
|
72
|
+
end
|
73
|
+
|
74
|
+
# @return [Boolean] true if '>=' is used to compare the version
|
75
|
+
def ge?
|
76
|
+
(flags & RPM::SENSE[:greater]) && (flags & RPM::SENSE[:equal])
|
77
|
+
end
|
78
|
+
|
79
|
+
# @return [Boolean] true if this is a pre-requires
|
80
|
+
def pre?
|
81
|
+
flags & RPM::SENSE[:prereq]
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
class Provide < Dependency
|
86
|
+
def initialize(name, version, flags, owner)
|
87
|
+
super(name, version, flags, owner)
|
88
|
+
@nametag = RPM::TAG[:providename]
|
89
|
+
@versiontag = RPM::TAG[:provideversion]
|
90
|
+
@flagstag = RPM::TAG[:provideflags]
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
class Require < Dependency
|
95
|
+
def initialize(name, version, flags, owner)
|
96
|
+
super(name, version, flags, owner)
|
97
|
+
@nametag = RPM::TAG[:requirename]
|
98
|
+
@versiontag = RPM::TAG[:requireversion]
|
99
|
+
@flagstag = RPM::TAG[:requireflags]
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
class Conflict < Dependency
|
104
|
+
def initialize(name, version, flags, owner)
|
105
|
+
super(name, version, flags, owner)
|
106
|
+
@nametag = RPM::TAG[:conflictname]
|
107
|
+
@versiontag = RPM::TAG[:conflictversion]
|
108
|
+
@flagstag = RPM::TAG[:conflictflags]
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
class Obsolete < Dependency
|
113
|
+
def initialize(name, version, flags, owner)
|
114
|
+
super(name, version, flags, owner)
|
115
|
+
@nametag = RPM::TAG[:obsoletename]
|
116
|
+
@versiontag = RPM::TAG[:obsoleteversion]
|
117
|
+
@flagstag = RPM::TAG[:obsoleteflags]
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
data/lib/rpm/file.rb
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module RPM
|
4
|
+
class File
|
5
|
+
# @return [String] file path
|
6
|
+
attr_accessor :path
|
7
|
+
# @return [String] md5sum as string
|
8
|
+
attr_accessor :md5sum
|
9
|
+
# @return [String] Path to the destination if the file is a symbolic link
|
10
|
+
# @note
|
11
|
+
# This path is sometimes relative. To convert an absolute path from relative path:
|
12
|
+
# File.expand_path (file.link_to, File.dirname (file.path))
|
13
|
+
attr_accessor :link_to
|
14
|
+
# @return [Number] File size
|
15
|
+
attr_accessor :size
|
16
|
+
# @return [Time] File modification time.
|
17
|
+
attr_accessor :mtime
|
18
|
+
# @return [String] File owner. Nil may be returned.
|
19
|
+
attr_accessor :owner
|
20
|
+
# @return [String] Group that owns the file. Nil may be returned.
|
21
|
+
attr_accessor :group
|
22
|
+
# @return [Number] Device type of the file
|
23
|
+
attr_accessor :mode
|
24
|
+
|
25
|
+
attr_accessor :attr
|
26
|
+
attr_accessor :state
|
27
|
+
attr_accessor :rdev
|
28
|
+
|
29
|
+
# @return [Boolean] True if the file is a symbolic link
|
30
|
+
def symlink?
|
31
|
+
!@link_to.nil?
|
32
|
+
end
|
33
|
+
|
34
|
+
# @return [Boolean] True if the file is marked as a configuration file
|
35
|
+
def config?
|
36
|
+
!(@attr & RPM::C::FileAttrs[:config]).zero?
|
37
|
+
end
|
38
|
+
|
39
|
+
# @return [Boolean] True if the file is marked as documentation
|
40
|
+
def doc?
|
41
|
+
!(@attr & RPM::C::FileAttrs[:doc]).zero?
|
42
|
+
end
|
43
|
+
|
44
|
+
# @return [Boolean] True if the file is marked as do not use
|
45
|
+
# @deprecated RPMFILE_DONOTUSE was removed in recent versions of RPM.
|
46
|
+
def donotuse?
|
47
|
+
msg = 'RPMFILE_DONOTUSE was removed in recent versions of RPM.'
|
48
|
+
warn "#{Kernel.caller.first} #{msg}"
|
49
|
+
raise NotImplementedError
|
50
|
+
end
|
51
|
+
|
52
|
+
# @return [Boolean] True if the file is marked that can be missing on disk
|
53
|
+
#
|
54
|
+
# This modifier is used for files or links that are created during the %post scripts
|
55
|
+
# but will need to be removed if the package is removed
|
56
|
+
def is_missingok?
|
57
|
+
!(@attr & RPM::C::FileAttrs[:missingok]).zero?
|
58
|
+
end
|
59
|
+
|
60
|
+
# @return [Boolean] True if the file is marked as configuration not to be replaced
|
61
|
+
#
|
62
|
+
# This flag is used to protect local modifications.
|
63
|
+
# If used, the file will not overwrite an existing file that has been modified.
|
64
|
+
# If the file has not been modified on disk, the rpm command will overwrite the file. But,
|
65
|
+
# if the file has been modified on disk, the rpm command will copy the new file with an extra
|
66
|
+
# file-name extension of .rpmnew.
|
67
|
+
def is_noreplace?
|
68
|
+
!(@attr & RPM::C::FileAttrs[:noreplace]).zero?
|
69
|
+
end
|
70
|
+
|
71
|
+
# @return [Boolean] True if the file is marked as a spec file
|
72
|
+
def is_specfile?
|
73
|
+
!(@attr & RPM::C::FileAttrs[:specfile]).zero?
|
74
|
+
end
|
75
|
+
|
76
|
+
# @return [Boolean] True if the file is marked as ghost
|
77
|
+
#
|
78
|
+
# This flag indicates the file should not be included in the package.
|
79
|
+
# It can be used to name the needed attributes for a file that the program, when installed,
|
80
|
+
# will create.
|
81
|
+
# For example, you may want to ensure that a program’s log file has certain attributes.
|
82
|
+
def ghost?
|
83
|
+
!(@attr & RPM::C::FileAttrs[:ghost]).zero?
|
84
|
+
end
|
85
|
+
|
86
|
+
# @return [Boolean] True if the file is a license
|
87
|
+
def license?
|
88
|
+
!(@attr & RPM::C::FileAttrs[:license]).zero?
|
89
|
+
end
|
90
|
+
|
91
|
+
# @return [Boolean] True if the file is a README
|
92
|
+
def readme?
|
93
|
+
!(@attr & RPM::C::FileAttrs[:readme]).zero?
|
94
|
+
end
|
95
|
+
|
96
|
+
# @raise NotImplementedError
|
97
|
+
# @deprecated RPMFILE_EXCLUDE was removed in recent versions of RPM.
|
98
|
+
def exclude?
|
99
|
+
msg = 'RPMFILE_EXCLUDE was removed in recent versions of RPM.'
|
100
|
+
warn "#{Kernel.caller.first} #{msg}"
|
101
|
+
raise NotImplementedError
|
102
|
+
end
|
103
|
+
|
104
|
+
# @return [Boolean] True if the file is replaced during installation
|
105
|
+
def replaced?
|
106
|
+
!(@attr & RPM::C::FileState[:replaced]).zero?
|
107
|
+
end
|
108
|
+
|
109
|
+
# @return [Boolean] True if the file is not installed
|
110
|
+
def notinstalled?
|
111
|
+
!(@attr & RPM::C::FileState[:notinstalled]).zero?
|
112
|
+
end
|
113
|
+
|
114
|
+
# @return [Boolean] True if the file is shared over the network
|
115
|
+
def netshared?
|
116
|
+
!(@attr & RPM::C::FileState[:netshared]).zero?
|
117
|
+
end
|
118
|
+
|
119
|
+
def initialize(path, md5sum, link_to, size, mtime, owner, group, rdev, mode, attr, state)
|
120
|
+
@path = path
|
121
|
+
@md5sum = md5sum
|
122
|
+
# If link_to is "" save it as nil
|
123
|
+
@link_to = (link_to && link_to.empty? ? nil : link_to)
|
124
|
+
@size = size
|
125
|
+
@mtime = mtime
|
126
|
+
@owner = owner
|
127
|
+
@group = group
|
128
|
+
@rdev = rdev
|
129
|
+
@mode = mode
|
130
|
+
@attr = attr
|
131
|
+
@state = state
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
|
2
|
+
module RPM
|
3
|
+
class MatchIterator
|
4
|
+
include Enumerable
|
5
|
+
|
6
|
+
# @visibility private
|
7
|
+
def self.release(ptr)
|
8
|
+
RPM::C.rpmdbFreeIterator(ptr)
|
9
|
+
end
|
10
|
+
|
11
|
+
# Creates a managed MatchIterator from a raw pointer
|
12
|
+
# @visibility private
|
13
|
+
def self.from_ptr(ptr)
|
14
|
+
new(::FFI::AutoPointer.new(ptr, MatchIterator.method(:release)))
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(ptr)
|
18
|
+
@ptr = ptr
|
19
|
+
end
|
20
|
+
|
21
|
+
def each
|
22
|
+
while (pkg = next_iterator)
|
23
|
+
yield pkg
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def next_iterator
|
28
|
+
pkg_ptr = RPM::C.rpmdbNextIterator(@ptr)
|
29
|
+
return RPM::Package.new(pkg_ptr) unless pkg_ptr.null?
|
30
|
+
nil
|
31
|
+
end
|
32
|
+
|
33
|
+
# @ return header join key for current position of rpm
|
34
|
+
# database iterator
|
35
|
+
def offset
|
36
|
+
RPM::C.rpmdbGetIteratorOffset(@ptr)
|
37
|
+
end
|
38
|
+
|
39
|
+
def set_iterator_re(tag, mode, string)
|
40
|
+
ret = RPM::C.rpmdbSetIteratorRE(@ptr, tag, mode, string)
|
41
|
+
raise "Error when setting regular expression '#{string}'" if ret != 0
|
42
|
+
self
|
43
|
+
end
|
44
|
+
|
45
|
+
alias regexp set_iterator_re
|
46
|
+
|
47
|
+
def set_iterator_version(version)
|
48
|
+
unless version.is_a?(RPM::Version)
|
49
|
+
raise TypeError, 'illegal argument type'
|
50
|
+
end
|
51
|
+
|
52
|
+
set_iterator_re(:version, :default, version.v)
|
53
|
+
set_iterator_re(:release, :default, version.r) if version.r
|
54
|
+
self
|
55
|
+
end
|
56
|
+
|
57
|
+
alias version set_iterator_version
|
58
|
+
|
59
|
+
def get_iterator_count
|
60
|
+
RPM::C.rpmdbGetIteratorCount(@ptr)
|
61
|
+
end
|
62
|
+
|
63
|
+
alias count get_iterator_count
|
64
|
+
alias length get_iterator_count
|
65
|
+
end
|
66
|
+
end
|