ruby-rpm 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,28 @@
1
+ /* -*- mode: C; c-basic-offset: 4; tab-width: 4; -*- */
2
+ /* Ruby/RPM
3
+ *
4
+ * Copyright (C) 2004 YAMAZAKI Makoto <zaki@zakky.org>
5
+ */
6
+
7
+ /* $Id: rpm40_compat.c 11 2004-03-13 14:54:21Z zaki $ */
8
+
9
+ #include "private.h"
10
+
11
+
12
+ #if RPM_VERSION(4,2,0) <= RPM_VERSION_CODE
13
+
14
+ rpmRC
15
+ rpmReadPackageInfo(FD_t fd, Header * sigp, Header * hdrp)
16
+ {
17
+ rpmRC rc;
18
+
19
+ rpmts ts = rpmtsCreate();
20
+ rc = rpmReadPackageFile(ts, fd, "readRPM", hdrp);
21
+ ts = rpmtsFree(ts);
22
+
23
+ if (sigp) *sigp = NULL; /* XXX HACK */
24
+
25
+ return rc;
26
+ }
27
+
28
+ #endif /* RPM_VERSION(4,2,0) <= RPM_VERSION_CODE */
@@ -0,0 +1,9 @@
1
+ #ifndef rpm40_compat_h_Included
2
+ #define rpm40_compat_h_Included 1
3
+
4
+
5
+ rpmRC
6
+ rpmReadPackageInfo(FD_t fd, Header * sigp, Header * hdrp);
7
+
8
+
9
+ #endif
@@ -0,0 +1,181 @@
1
+ /* -*- mode: C; c-basic-offset: 4; tab-width: 4; -*- */
2
+ /* Ruby/RPM
3
+ *
4
+ * Copyright (C) 2002 Kenta MURATA <muraken2@nifty.com>.
5
+ */
6
+
7
+ /* $Id: ruby-rpm.h 27 2004-05-23 04:54:24Z zaki $ */
8
+
9
+ #ifndef ruby_rpm_h_Included
10
+ #define ruby_rpm_h_Included 1
11
+
12
+ #include <ruby.h>
13
+
14
+ #define RUBY_RPM_VERSION "1.1.10"
15
+
16
+ extern VALUE rpm_mRPM;
17
+ extern VALUE rpm_cConflict;
18
+ extern VALUE rpm_cDB;
19
+ extern VALUE rpm_cDependency;
20
+ extern VALUE rpm_cFile;
21
+ extern VALUE rpm_cIcon;
22
+ extern VALUE rpm_cMatchIterator;
23
+ extern VALUE rpm_cObsolete;
24
+ extern VALUE rpm_cPackage;
25
+ extern VALUE rpm_cPatch;
26
+ extern VALUE rpm_cProvide;
27
+ extern VALUE rpm_cRequire;
28
+ extern VALUE rpm_cSource;
29
+ extern VALUE rpm_cSpec;
30
+ extern VALUE rpm_cTransaction;
31
+ extern VALUE rpm_cVersion;
32
+ extern VALUE rpm_sChangeLog;
33
+ extern VALUE rpm_sCallbackData;
34
+ extern VALUE rpm_sProblem;
35
+
36
+ /* db.c */
37
+ VALUE rpm_db_open(int writable, const char* root);
38
+ void rpm_db_init(const char* root, int writable);
39
+ void rpm_db_rebuild(const char* root);
40
+ VALUE rpm_db_get_root(VALUE db);
41
+ VALUE rpm_db_get_home(VALUE db);
42
+ VALUE rpm_db_is_writable(VALUE db);
43
+ VALUE rpm_db_each_match(VALUE db, VALUE key, VALUE val);
44
+ VALUE rpm_db_each(VALUE db);
45
+ VALUE rpm_db_transaction(int argc, VALUE* argv, VALUE db);
46
+ VALUE rpm_transaction_get_db(VALUE trans);
47
+ VALUE rpm_transaction_get_script_file(VALUE trans);
48
+ VALUE rpm_transaction_set_script_file(VALUE trans, VALUE file);
49
+ VALUE rpm_transaction_install(VALUE trans, VALUE pkg, VALUE key);
50
+ VALUE rpm_transaction_upgrade(VALUE trans, VALUE pkg, VALUE key);
51
+ VALUE rpm_transaction_available(VALUE trans, VALUE pkg, VALUE key);
52
+ VALUE rpm_transaction_delete(VALUE trans, VALUE name);
53
+ VALUE rpm_transaction_check(VALUE trans);
54
+ VALUE rpm_transaction_order(VALUE trans);
55
+ VALUE rpm_transaction_keys(VALUE trans);
56
+ VALUE rpm_transaction_commit(int argc, VALUE* argv, VALUE trans);
57
+ VALUE rpm_transaction_abort(VALUE trans);
58
+ VALUE rpm_db_init_iterator(VALUE db, VALUE key, VALUE val);
59
+ VALUE rpm_mi_next_iterator(VALUE mi);
60
+ VALUE rpm_mi_each(VALUE mi);
61
+ VALUE rpm_mi_get_iterator_count(VALUE mi);
62
+ VALUE rpm_mi_get_iterator_offset(VALUE mi);
63
+ VALUE rpm_mi_set_iterator_re(VALUE mi,VALUE tag, VALUE mode, VALUE re);
64
+ VALUE rpm_mi_set_iterator_version(VALUE mi, VALUE version);
65
+
66
+
67
+ /* dependency.c */
68
+ VALUE rpm_provide_new(const char* name, VALUE version, int flags, VALUE target);
69
+ VALUE rpm_require_new(const char* name, VALUE version, int flags, VALUE target);
70
+ VALUE rpm_conflict_new(const char* name, VALUE version, int flags, VALUE target);
71
+ VALUE rpm_obsolete_new(const char* name, VALUE version, int flags, VALUE target);
72
+ VALUE rpm_dependency_get_name(VALUE dep);
73
+ VALUE rpm_dependency_get_version(VALUE dep);
74
+ VALUE rpm_dependency_get_flags(VALUE dep);
75
+ VALUE rpm_dependency_get_target(VALUE dep);
76
+ VALUE rpm_dependency_is_lt(VALUE dep);
77
+ VALUE rpm_dependency_is_gt(VALUE dep);
78
+ VALUE rpm_dependency_is_eq(VALUE dep);
79
+ VALUE rpm_dependency_is_le(VALUE dep);
80
+ VALUE rpm_dependency_is_ge(VALUE dep);
81
+ VALUE rpm_require_is_pre(VALUE req);
82
+ VALUE rpm_dependency_get_nametag(VALUE dep);
83
+ VALUE rpm_dependency_get_versiontag(VALUE dep);
84
+ VALUE rpm_dependency_get_flagstag(VALUE dep);
85
+
86
+
87
+ /* file.c */
88
+ VALUE rpm_file_new(const char* path, const char* md5sum, const char* link_to,
89
+ size_t size, time_t mtime, const char* owner, const char* group,
90
+ dev_t rdev, mode_t mode, rpmfileAttrs attr, rpmfileState state);
91
+ VALUE rpm_file_get_path(VALUE file);
92
+ VALUE rpm_file_get_md5sum(VALUE file);
93
+ VALUE rpm_file_get_link_to(VALUE file);
94
+ VALUE rpm_file_get_size(VALUE file);
95
+ VALUE rpm_file_get_mtime(VALUE file);
96
+ VALUE rpm_file_get_owner(VALUE file);
97
+ VALUE rpm_file_get_group(VALUE file);
98
+ VALUE rpm_file_get_rdev(VALUE file);
99
+ VALUE rpm_file_get_mode(VALUE file);
100
+ VALUE rpm_file_get_attr(VALUE file);
101
+ VALUE rpm_file_get_state(VALUE file);
102
+ VALUE rpm_file_is_symlink(VALUE file);
103
+ VALUE rpm_file_is_config(VALUE file);
104
+ VALUE rpm_file_is_doc(VALUE file);
105
+ VALUE rpm_file_is_donotuse(VALUE file);
106
+ VALUE rpm_file_is_missingok(VALUE file);
107
+ VALUE rpm_file_is_noreplace(VALUE file);
108
+ VALUE rpm_file_is_specfile(VALUE file);
109
+ VALUE rpm_file_is_ghost(VALUE file);
110
+ VALUE rpm_file_is_license(VALUE file);
111
+ VALUE rpm_file_is_readme(VALUE file);
112
+ VALUE rpm_file_is_exclude(VALUE file);
113
+ VALUE rpm_file_is_replaced(VALUE file);
114
+ VALUE rpm_file_is_notinstalled(VALUE file);
115
+ VALUE rpm_file_is_netshared(VALUE file);
116
+
117
+ /* package.c */
118
+ VALUE rpm_package_new_from_header(Header hdr);
119
+ #if RPM_VERSION(4,1,0) <= RPM_VERSION_CODE
120
+ VALUE rpm_package_new_from_N_EVR(VALUE name, VALUE version);
121
+ #endif
122
+ VALUE rpm_package_aref(VALUE pkg, VALUE tag);
123
+ VALUE rpm_package_get_name(VALUE pkg);
124
+ VALUE rpm_package_get_version(VALUE pkg);
125
+ VALUE rpm_package_get_signature(VALUE pkg);
126
+ VALUE rpm_package_get_files(VALUE pkg);
127
+ VALUE rpm_package_get_provides(VALUE pkg);
128
+ VALUE rpm_package_get_requires(VALUE pkg);
129
+ VALUE rpm_package_get_conflicts(VALUE pkg);
130
+ VALUE rpm_package_get_obsoletes(VALUE pkg);
131
+ VALUE rpm_package_get_changelog(VALUE pkg);
132
+ VALUE rpm_package_dump(VALUE pkg);
133
+ VALUE rpm_package_add_dependency(VALUE pkg,VALUE dep);
134
+ VALUE rpm_package_add_string(VALUE pkg,VALUE tag,VALUE val);
135
+ VALUE rpm_package_add_string_array(VALUE pkg,VALUE tag,VALUE val);
136
+ VALUE rpm_package_add_int32(VALUE pkg,VALUE tag,VALUE val);
137
+ VALUE rpm_package_add_binary(VALUE pkg,VALUE tag,VALUE val);
138
+
139
+
140
+ /* rpm.c */
141
+ VALUE rpm_macro_aref(VALUE name);
142
+ VALUE rpm_macro_aset(VALUE name, VALUE val);
143
+ void rpm_readrc(const char* rcpath);
144
+ void rpm_init_marcros(const char* path);
145
+ VALUE rpm_get_verbosity(void);
146
+ void rpm_set_verbosity(VALUE verbosity);
147
+
148
+ /* source.c */
149
+ VALUE rpm_source_new(const char* fullname, unsigned int num, int no);
150
+ VALUE rpm_patch_new(const char* fullname, unsigned int num, int no);
151
+ VALUE rpm_icon_new(const char* fullname, unsigned int num, int no);
152
+ VALUE rpm_source_get_fullname(VALUE src);
153
+ VALUE rpm_source_get_filename(VALUE src);
154
+ VALUE rpm_source_get_num(VALUE src);
155
+ VALUE rpm_source_is_no(VALUE src);
156
+
157
+ /* spec.c */
158
+ VALUE rpm_spec_open(const char* filename);
159
+ VALUE rpm_spec_get_buildroot(VALUE spec);
160
+ VALUE rpm_spec_get_buildsubdir(VALUE spec);
161
+ VALUE rpm_spec_get_buildarchs(VALUE spec);
162
+ VALUE rpm_spec_get_buildrequires(VALUE spec);
163
+ VALUE rpm_spec_get_buildconflicts(VALUE spec);
164
+ VALUE rpm_spec_get_build_restrictions(VALUE spec);
165
+ VALUE rpm_spec_get_sources(VALUE spec);
166
+ VALUE rpm_spec_get_packages(VALUE spec);
167
+
168
+ /* version.c */
169
+ VALUE rpm_version_new(const char* vr);
170
+ VALUE rpm_version_new2(const char* vr, int e);
171
+ VALUE rpm_version_new3(const char* v, const char* r, int e);
172
+ VALUE rpm_version_cmp(VALUE ver, VALUE other);
173
+ VALUE rpm_version_is_newer(VALUE ver, VALUE other);
174
+ VALUE rpm_version_is_older(VALUE ver, VALUE other);
175
+ VALUE rpm_version_get_v(VALUE ver);
176
+ VALUE rpm_version_get_r(VALUE ver);
177
+ VALUE rpm_version_get_e(VALUE ver);
178
+ VALUE rpm_version_to_s(VALUE ver);
179
+ VALUE rpm_version_to_vre(VALUE ver);
180
+
181
+ #endif /* !ruby_rpm_h_Included */
@@ -0,0 +1,152 @@
1
+ /* -*- mode: C; c-basic-offset: 4; tab-width: 4; -*- */
2
+ /* Ruby/RPM
3
+ *
4
+ * Copyright (C) 2002 Kenta MURATA <muraken2@nifty.com>.
5
+ */
6
+
7
+ /* $Id: source.c 22 2004-03-29 03:42:35Z zaki $ */
8
+
9
+ #include "private.h"
10
+
11
+ VALUE rpm_cSource;
12
+ VALUE rpm_cPatch;
13
+ VALUE rpm_cIcon;
14
+
15
+ static ID id_full;
16
+ static ID id_fn;
17
+ static ID id_num;
18
+ static ID id_no;
19
+
20
+ static VALUE
21
+ source_initialize(int argc, VALUE* argv, VALUE src)
22
+ {
23
+ switch (argc) {
24
+ case 0: case 1:
25
+ rb_raise(rb_eArgError, "argument too few(2..3)");
26
+
27
+ case 2: case 3:
28
+ if (TYPE(argv[0]) != T_STRING) {
29
+ rb_raise(rb_eTypeError, "illegal argument type");
30
+ }
31
+
32
+ rb_ivar_set(src, id_full, argv[0]);
33
+ rb_ivar_set(src, id_num, rb_Integer(argv[1]));
34
+ if (argc == 3) {
35
+ rb_ivar_set(src, id_no, RTEST(argv[2]) ? Qtrue : Qfalse);
36
+ } else {
37
+ rb_ivar_set(src, id_no, Qfalse);
38
+ }
39
+ break;
40
+
41
+ default:
42
+ rb_raise(rb_eArgError, "argument too many(2..3)");
43
+ }
44
+
45
+ return src;
46
+ }
47
+
48
+ VALUE
49
+ rpm_source_new(const char* fullname, unsigned int num, int no)
50
+ {
51
+ VALUE src, argv[3];
52
+
53
+ argv[0] = rb_str_new2(fullname);
54
+ argv[1] = UINT2NUM(num);
55
+ argv[2] = no ? Qtrue : Qfalse;
56
+
57
+ src = rb_newobj();
58
+ OBJSETUP(src, rpm_cSource, T_OBJECT);
59
+ rb_obj_call_init(src, 3, argv);
60
+
61
+ return src;
62
+ }
63
+
64
+ VALUE
65
+ rpm_patch_new(const char* fullname, unsigned int num, int no)
66
+ {
67
+ VALUE src, argv[3];
68
+
69
+ argv[0] = rb_str_new2(fullname);
70
+ argv[1] = UINT2NUM(num);
71
+ argv[2] = no ? Qtrue : Qfalse;
72
+
73
+ src = rb_newobj();
74
+ OBJSETUP(src, rpm_cPatch, T_OBJECT);
75
+ rb_obj_call_init(src, 3, argv);
76
+
77
+ return src;
78
+ }
79
+
80
+ VALUE
81
+ rpm_icon_new(const char* fullname, unsigned int num, int no)
82
+ {
83
+ VALUE src, argv[3];
84
+
85
+ argv[0] = rb_str_new2(fullname);
86
+ argv[1] = UINT2NUM(num);
87
+ argv[2] = no ? Qtrue : Qfalse;
88
+
89
+ src = rb_newobj();
90
+ OBJSETUP(src, rpm_cIcon, T_OBJECT);
91
+ rb_obj_call_init(src, 3, argv);
92
+
93
+ return src;
94
+ }
95
+
96
+ VALUE
97
+ rpm_source_get_fullname(VALUE src)
98
+ {
99
+ return rb_ivar_get(src, id_full);
100
+ }
101
+
102
+ VALUE
103
+ rpm_source_get_filename(VALUE src)
104
+ {
105
+ VALUE fn = rb_ivar_get(src, id_fn);
106
+
107
+ if (NIL_P(fn)) {
108
+ VALUE full = rb_ivar_get(src, id_full);
109
+ const char* p = strrchr(RSTRING(full)->ptr, '/');
110
+ if (p == NULL) {
111
+ p = RSTRING(full)->ptr;
112
+ } else {
113
+ p++;
114
+ }
115
+ fn = rb_str_new2(p);
116
+ rb_ivar_set(src, id_fn, fn);
117
+ }
118
+
119
+ return fn;
120
+ }
121
+
122
+ VALUE
123
+ rpm_source_get_num(VALUE src)
124
+ {
125
+ return rb_ivar_get(src, id_num);
126
+ }
127
+
128
+ VALUE
129
+ rpm_source_is_no(VALUE src)
130
+ {
131
+ return rb_ivar_get(src, id_no);
132
+ }
133
+
134
+ void
135
+ Init_rpm_source(void)
136
+ {
137
+ rpm_cSource = rb_define_class_under(rpm_mRPM, "Source", rb_cObject);
138
+ rb_define_method(rpm_cSource, "initialize", source_initialize, -1);
139
+ rb_define_method(rpm_cSource, "fullname", rpm_source_get_fullname, 0);
140
+ rb_define_alias(rpm_cSource, "to_s", "fullname");
141
+ rb_define_method(rpm_cSource, "filename", rpm_source_get_filename, 0);
142
+ rb_define_method(rpm_cSource, "num", rpm_source_get_num, 0);
143
+ rb_define_method(rpm_cSource, "no?", rpm_source_is_no, 0);
144
+
145
+ rpm_cPatch = rb_define_class_under(rpm_mRPM, "Patch", rpm_cSource);
146
+ rpm_cIcon = rb_define_class_under(rpm_mRPM, "Icon", rpm_cSource);
147
+
148
+ id_full = rb_intern("fullname");
149
+ id_fn = rb_intern("filename");
150
+ id_num = rb_intern("num");
151
+ id_no = rb_intern("no");
152
+ }
@@ -0,0 +1,346 @@
1
+ /* -*- mode: C; c-basic-offset: 4; tab-width: 4; -*- */
2
+ /* Ruby/RPM
3
+ *
4
+ * Copyright (C) 2002 Kenta MURATA <muraken2@nifty.com>.
5
+ */
6
+
7
+ /* $Id: spec.c 44 2004-06-03 16:58:10Z kazuhiko $ */
8
+
9
+ #include "private.h"
10
+
11
+ VALUE rpm_cSpec;
12
+
13
+ static ID id_ba;
14
+ static ID id_br;
15
+ static ID id_bc;
16
+ static ID id_src;
17
+ static ID id_pkg;
18
+ static ID id_rest;
19
+
20
+ #if RPM_VERSION_CODE < RPM_VERSION(4,1,0)
21
+ static void
22
+ spec_free(Spec rspec)
23
+ {
24
+ freeSpec(rspec);
25
+ }
26
+
27
+ #else
28
+ static void
29
+ ts_free(rpmts ts)
30
+ {
31
+ ts = rpmtsFree(ts);
32
+ }
33
+
34
+ #endif
35
+
36
+ static VALUE
37
+ spec_s_open(VALUE klass, VALUE filename)
38
+ {
39
+ #if RPM_VERSION_CODE < RPM_VERSION(4,1,0)
40
+ Spec rspec;
41
+ #else
42
+ rpmts ts = NULL;
43
+ #endif
44
+
45
+ if (TYPE(filename) != T_STRING) {
46
+ rb_raise(rb_eTypeError, "illegal argument type");
47
+ }
48
+
49
+ #if RPM_VERSION_CODE < RPM_VERSION(4,1,0)
50
+ switch (parseSpec(&rspec, RSTRING(filename)->ptr, "/", NULL, 0, "", NULL, 1, 1)) {
51
+ case 0:
52
+ if (rspec != NULL) {
53
+ break;
54
+ }
55
+
56
+ case RPMERR_BADSPEC:
57
+ default:
58
+ rb_raise(rb_eRuntimeError, "specfile `%s' parsing failed", RSTRING(filename)->ptr);
59
+ }
60
+ return Data_Wrap_Struct(klass, NULL, spec_free, rspec);
61
+ #else
62
+ ts = rpmtsCreate();
63
+ switch (parseSpec(ts, RSTRING(filename)->ptr, "/", NULL, 0, "", NULL, 1, 1)) {
64
+ case 0:
65
+ if (ts != NULL) {
66
+ break;
67
+ }
68
+
69
+ case RPMERR_BADSPEC:
70
+ default:
71
+ rb_raise(rb_eRuntimeError, "specfile `%s' parsing failed", RSTRING(filename)->ptr);
72
+ }
73
+ return Data_Wrap_Struct(klass, NULL, ts_free, ts);
74
+ #endif
75
+ }
76
+
77
+ VALUE
78
+ rpm_spec_open(const char* filename)
79
+ {
80
+ return spec_s_open(rpm_cSpec, rb_str_new2(filename));
81
+ }
82
+
83
+ VALUE
84
+ rpm_spec_get_buildroot(VALUE spec)
85
+ {
86
+ if (RPM_SPEC(spec)->buildRootURL) {
87
+ return rb_str_new2(RPM_SPEC(spec)->buildRootURL);
88
+ }
89
+ return Qnil;
90
+ }
91
+
92
+ VALUE
93
+ rpm_spec_get_buildsubdir(VALUE spec)
94
+ {
95
+ if (RPM_SPEC(spec)->buildSubdir) {
96
+ return rb_str_new2(RPM_SPEC(spec)->buildSubdir);
97
+ }
98
+ return Qnil;
99
+ }
100
+
101
+ VALUE
102
+ rpm_spec_get_buildarchs(VALUE spec)
103
+ {
104
+ VALUE ba = rb_ivar_get(spec, id_ba);
105
+
106
+ if (NIL_P(ba)) {
107
+ register int i;
108
+ ba = rb_ary_new();
109
+ for (i = 0; i < RPM_SPEC(spec)->BACount; i++) {
110
+ rb_ary_push(ba, rb_str_new2(RPM_SPEC(spec)->BANames[i]));
111
+ }
112
+ rb_ivar_set(spec, id_ba, ba);
113
+ }
114
+
115
+ return ba;
116
+ }
117
+
118
+ VALUE
119
+ rpm_spec_get_buildrequires(VALUE spec)
120
+ {
121
+ VALUE br = rb_ivar_get(spec, id_br);
122
+
123
+ if (NIL_P(br)) {
124
+ const char** names;
125
+ const char** vers;
126
+ int_32* flags;
127
+ int_32 count;
128
+ rpmTagType nt, vt, type;
129
+ register int i;
130
+
131
+ br = rb_ary_new();
132
+ if (!headerGetEntryMinMemory(RPM_SPEC(spec)->buildRestrictions,
133
+ RPMTAG_REQUIRENAME, (hTYP_t)&nt,
134
+ (hPTR_t*)&names, (hCNT_t)&count)) {
135
+ goto leave;
136
+ }
137
+
138
+ get_entry(RPM_SPEC(spec)->buildRestrictions, RPMTAG_REQUIREVERSION,
139
+ &vt, (void*)&vers);
140
+ get_entry(RPM_SPEC(spec)->buildRestrictions, RPMTAG_REQUIREFLAGS,
141
+ &type, (void*)&flags);
142
+
143
+ for (i = 0; i < count; i++) {
144
+ rb_ary_push(br, rpm_require_new(names[i], rpm_version_new(vers[i]),
145
+ flags[i], spec));
146
+ }
147
+
148
+ release_entry(nt, names);
149
+ release_entry(vt, vers);
150
+
151
+ rb_ivar_set(spec, id_br, br);
152
+ }
153
+
154
+ leave:
155
+ return br;
156
+ }
157
+
158
+ VALUE
159
+ rpm_spec_get_buildconflicts(VALUE spec)
160
+ {
161
+ VALUE bc = rb_ivar_get(spec, id_bc);
162
+
163
+ if (NIL_P(bc)) {
164
+ const char** names;
165
+ const char** vers;
166
+ int_32* flags;
167
+ int_32 count;
168
+ rpmTagType nt, vt, type;
169
+ register int i;
170
+
171
+ bc = rb_ary_new();
172
+ if (!headerGetEntryMinMemory(RPM_SPEC(spec)->buildRestrictions,
173
+ RPMTAG_CONFLICTNAME, (hTYP_t)&nt,
174
+ (hPTR_t*)&names, (hCNT_t)&count)) {
175
+ goto leave;
176
+ }
177
+
178
+ get_entry(RPM_SPEC(spec)->buildRestrictions, RPMTAG_CONFLICTVERSION,
179
+ &vt, (void*)&vers);
180
+ get_entry(RPM_SPEC(spec)->buildRestrictions, RPMTAG_CONFLICTFLAGS,
181
+ &type, (void*)&flags);
182
+
183
+ for (i = 0; i < count; i++) {
184
+ rb_ary_push(bc, rpm_conflict_new(names[i], rpm_version_new(vers[i]),
185
+ flags[i], spec));
186
+ }
187
+
188
+ release_entry(nt, names);
189
+ release_entry(vt, vers);
190
+
191
+ rb_ivar_set(spec, id_bc, bc);
192
+ }
193
+ leave:
194
+ return bc;
195
+ }
196
+
197
+ VALUE
198
+ rpm_spec_get_build_restrictions(VALUE spec)
199
+ {
200
+ VALUE cache = rb_ivar_get(spec, id_rest);
201
+
202
+ if (NIL_P(cache)) {
203
+ cache = rpm_package_new_from_header(RPM_SPEC(spec)->buildRestrictions);
204
+ rb_ivar_set(spec, id_rest, cache);
205
+ }
206
+
207
+ return cache;
208
+ }
209
+
210
+ VALUE
211
+ rpm_spec_get_sources(VALUE spec)
212
+ {
213
+ VALUE src = rb_ivar_get(spec, id_src);
214
+
215
+ if (NIL_P(src)) {
216
+ struct Source* s = RPM_SPEC(spec)->sources;
217
+
218
+ src = rb_ary_new();
219
+ while (s != NULL) {
220
+ VALUE obj;
221
+
222
+ if (s->flags & RPMBUILD_ISSOURCE) {
223
+ obj = rpm_source_new(s->fullSource, s->num, s->flags & RPMBUILD_ISNO);
224
+ } else if (s->flags & RPMBUILD_ISPATCH) {
225
+ obj = rpm_patch_new(s->fullSource, s->num, s->flags & RPMBUILD_ISNO);
226
+ } else if (s->flags & RPMBUILD_ISICON) {
227
+ obj = rpm_icon_new(s->fullSource, s->num, s->flags & RPMBUILD_ISNO);
228
+ }
229
+
230
+ rb_ary_push(src, obj);
231
+ s = s->next;
232
+ }
233
+
234
+ rb_ivar_set(spec, id_src, src);
235
+ }
236
+
237
+ return src;
238
+ }
239
+
240
+ VALUE
241
+ rpm_spec_get_packages(VALUE spec)
242
+ {
243
+ VALUE pkg = rb_ivar_get(spec, id_pkg);
244
+
245
+ if (NIL_P(pkg)) {
246
+ Package p = RPM_SPEC(spec)->packages;
247
+
248
+ pkg = rb_ary_new();
249
+ while (p != NULL) {
250
+ if (p->fileList)
251
+ rb_ary_push(pkg, rpm_package_new_from_header(p->header));
252
+ p = p->next;
253
+ }
254
+
255
+ rb_ivar_set(spec, id_pkg, pkg);
256
+ }
257
+
258
+ return pkg;
259
+ }
260
+
261
+ VALUE
262
+ rpm_spec_build(int argc, VALUE* argv, VALUE spec)
263
+ {
264
+ int flags, test;
265
+ rpmRC rc;
266
+
267
+ switch (argc) {
268
+ case 0:
269
+ rb_raise(rb_eArgError, "argument too few(1..2)");
270
+
271
+ case 1:
272
+ flags = NUM2INT(argv[0]);
273
+ test = 0;
274
+ break;
275
+
276
+ case 2:
277
+ flags = NUM2INT(argv[0]);
278
+ test = RTEST(argv[1]);
279
+ break;
280
+
281
+ default:
282
+ rb_raise(rb_eArgError, "argument too many(0..1)");
283
+ }
284
+
285
+ #if RPM_VERSION_CODE < RPM_VERSION(4,1,0)
286
+ rc = buildSpec(RPM_SPEC(spec), flags,test);
287
+ #else
288
+ rpmts ts = NULL;
289
+ ts = rpmtsCreate();
290
+ rc = buildSpec(ts, RPM_SPEC(spec), flags,test);
291
+ ts_free(ts);
292
+ #endif
293
+
294
+ return INT2NUM(rc);
295
+ }
296
+
297
+ VALUE
298
+ rpm_spec_expand_macros(VALUE spec, VALUE name)
299
+ {
300
+ char buf[BUFSIZ];
301
+ char* tmp;
302
+ VALUE val;
303
+
304
+ if (TYPE(name) != T_STRING) {
305
+ rb_raise(rb_eTypeError, "illegal argument type");
306
+ }
307
+
308
+ sprintf(buf, "%%{%s}", RSTRING(name)->ptr);
309
+ tmp = strdup(buf);
310
+ expandMacros(RPM_SPEC(spec), RPM_SPEC(spec)->macros, buf, BUFSIZ);
311
+ if (strcmp(tmp, buf) == 0) {
312
+ val = Qnil;
313
+ } else {
314
+ val = rb_str_new2(buf);
315
+ }
316
+ free(tmp);
317
+
318
+ return val;
319
+ }
320
+
321
+ void
322
+ Init_rpm_spec(void)
323
+ {
324
+ rpm_cSpec = rb_define_class_under(rpm_mRPM, "Spec", rb_cData);
325
+ rb_define_singleton_method(rpm_cSpec, "open", spec_s_open, 1);
326
+ rb_define_singleton_method(rpm_cSpec, "new", spec_s_open, 1);
327
+ rb_define_method(rpm_cSpec, "buildroot", rpm_spec_get_buildroot, 0);
328
+ rb_define_method(rpm_cSpec, "buildsubdir", rpm_spec_get_buildsubdir, 0);
329
+ rb_define_method(rpm_cSpec, "buildarchs", rpm_spec_get_buildarchs, 0);
330
+ rb_define_method(rpm_cSpec, "buildrequires", rpm_spec_get_buildrequires, 0);
331
+ rb_define_method(rpm_cSpec, "buildconflicts", rpm_spec_get_buildconflicts, 0);
332
+ rb_define_method(rpm_cSpec, "build_restrictions", rpm_spec_get_build_restrictions, 0);
333
+ rb_define_method(rpm_cSpec, "sources", rpm_spec_get_sources, 0);
334
+ rb_define_method(rpm_cSpec, "packages", rpm_spec_get_packages, 0);
335
+ rb_define_method(rpm_cSpec, "build", rpm_spec_build, -1);
336
+ rb_define_method(rpm_cSpec, "expand_macros", rpm_spec_expand_macros, 1);
337
+ rb_undef_method(rpm_cSpec, "dup");
338
+ rb_undef_method(rpm_cSpec, "clone");
339
+
340
+ id_ba = rb_intern("buildarchs");
341
+ id_br = rb_intern("buildrequires");
342
+ id_bc = rb_intern("buildconflicts");
343
+ id_src = rb_intern("sources");
344
+ id_pkg = rb_intern("packages");
345
+ id_rest = rb_intern("build_restrictions");
346
+ }