ruby-rpm 1.3.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,8 +7,11 @@
7
7
  /* $Id: package.c 45 2004-06-04 15:11:20Z kazuhiko $ */
8
8
 
9
9
  #include "private.h"
10
+ #include <st.h>
10
11
 
12
+ #ifndef stpcpy
11
13
  char *stpcpy( char *dest, const char *source );
14
+ #endif
12
15
 
13
16
  VALUE rpm_cPackage;
14
17
  VALUE rpm_sChangeLog;
@@ -16,6 +19,11 @@ VALUE rpm_sChangeLog;
16
19
  static ID id_signature;
17
20
  struct st_table *tbl = NULL;
18
21
 
22
+ #if RPM_VERSION(5,0,0) <= RPM_VERSION_CODE
23
+ #define headerGetEntryMinMemory(hdr,tag,type,ptr,cnt) \
24
+ headerGetEntry(hdr,tag,type,(void**)ptr,cnt)
25
+ #endif
26
+
19
27
  static VALUE
20
28
  package_clear_cache(VALUE klass){
21
29
  st_free_table(tbl);
@@ -81,6 +89,12 @@ package_new_from_header(VALUE klass, Header hdr)
81
89
  return p;
82
90
  }
83
91
 
92
+ /*
93
+ * Creates a new package object
94
+ * @param [String] name Package name
95
+ * @param [Version] version Package version
96
+ * @return [Package]
97
+ */
84
98
  static VALUE
85
99
  package_s_create(VALUE klass, VALUE name, VALUE version)
86
100
  {
@@ -121,6 +135,15 @@ static rpmRC read_header_from_file(FD_t fd, const char *filename, Header *hdr)
121
135
  return rc;
122
136
  }
123
137
 
138
+ /*
139
+ * Creates a +Package+ object from a rpm located on disk
140
+ * @param [String] filename Path to filename
141
+ * @return [Package]
142
+ * @example
143
+ * pkg = RPM::Package.open('/home/foo/myprogram-1.0-x86_64.rpm')
144
+ * pkg.name => 'myprogram'
145
+ * pkg.version => '1.0'
146
+ */
124
147
  static VALUE
125
148
  package_s_open(VALUE klass, VALUE filename)
126
149
  {
@@ -178,6 +201,11 @@ package_s_open(VALUE klass, VALUE filename)
178
201
  return pkg;
179
202
  }
180
203
 
204
+ /*
205
+ * Create a new package object from data
206
+ * @param [String] str Header data
207
+ * @return [Package]
208
+ */
181
209
  static VALUE
182
210
  package_s_load(VALUE klass, VALUE str)
183
211
  {
@@ -236,6 +264,10 @@ rpm_package_new_from_N_EVR(VALUE name, VALUE version)
236
264
  }
237
265
  #endif
238
266
 
267
+ /*
268
+ * Add a dependency to the package header
269
+ * @param [Dependency] dep Dependency to add
270
+ */
239
271
  VALUE
240
272
  rpm_package_add_dependency(VALUE pkg,VALUE dep)
241
273
  {
@@ -264,6 +296,11 @@ rpm_package_add_dependency(VALUE pkg,VALUE dep)
264
296
  return Qnil;
265
297
  }
266
298
 
299
+ /*
300
+ * Add a int32 value to the package header
301
+ * @param [Number] tag Tag
302
+ * @param [Number] val Value
303
+ */
267
304
  VALUE
268
305
  rpm_package_add_int32(VALUE pkg,VALUE tag,VALUE val)
269
306
  {
@@ -282,6 +319,11 @@ rpm_package_add_int32(VALUE pkg,VALUE tag,VALUE val)
282
319
  return Qnil;
283
320
  }
284
321
 
322
+ /*
323
+ * Add a list of strings to the package header
324
+ * @param [Number] tag Tag
325
+ * @param [Array<String>] val Strings to add
326
+ */
285
327
  VALUE
286
328
  rpm_package_add_string_array(VALUE pkg,VALUE tag,VALUE val)
287
329
  {
@@ -292,6 +334,11 @@ rpm_package_add_string_array(VALUE pkg,VALUE tag,VALUE val)
292
334
  return Qnil;
293
335
  }
294
336
 
337
+ /*
338
+ * Add a binary value to the package header
339
+ * @param [Number] tag Tag
340
+ * @param [String] val String to add
341
+ */
295
342
  VALUE
296
343
  rpm_package_add_string(VALUE pkg,VALUE tag,VALUE val)
297
344
  {
@@ -302,6 +349,11 @@ rpm_package_add_string(VALUE pkg,VALUE tag,VALUE val)
302
349
  return Qnil;
303
350
  }
304
351
 
352
+ /*
353
+ * Add a binary value to the package header
354
+ * @param [Number] tag Tag
355
+ * @param [String] val Value
356
+ */
305
357
  VALUE
306
358
  rpm_package_add_binary(VALUE pkg,VALUE tag,VALUE val)
307
359
  {
@@ -312,6 +364,10 @@ rpm_package_add_binary(VALUE pkg,VALUE tag,VALUE val)
312
364
  return Qnil;
313
365
  }
314
366
 
367
+ /*
368
+ * Deletes a tag of the package header
369
+ * @param [Number] tag Tag
370
+ */
315
371
  VALUE
316
372
  rpm_package_delete_tag(VALUE pkg, VALUE tag)
317
373
  {
@@ -323,10 +379,18 @@ rpm_package_delete_tag(VALUE pkg, VALUE tag)
323
379
  return val;
324
380
  }
325
381
 
326
- #if RPM_VERSION_CODE < RPM_VERSION(4,6,0)
382
+ /*
383
+ * Access a header entry
384
+ * @param [Number] tag Tag to return
385
+ * @return [] Value of the entry
386
+ * @example
387
+ * pkg => #<RPM::Package name="xmlgraphics-fop", version=#<RPM::Version v="1.0", r="22.4">>
388
+ * pkg[RPM::TAG_NAME] => "xmlgraphics-fop"
389
+ */
327
390
  VALUE
328
391
  rpm_package_aref(VALUE pkg, VALUE tag)
329
392
  {
393
+ #if RPM_VERSION_CODE < RPM_VERSION(4,6,0) || RPM_VERSION_CODE >= RPM_VERSION(5,0,0)
330
394
  rpmTag tagval = NUM2INT(tag);
331
395
  VALUE val = Qnil;
332
396
  void* data;
@@ -376,7 +440,9 @@ rpm_package_aref(VALUE pkg, VALUE tag)
376
440
  val = rb_str_new(data, count);
377
441
  break;
378
442
 
443
+ #if RPM_VERSION_CODE < RPM_VERSION(5,0,0)
379
444
  case RPM_CHAR_TYPE:
445
+ #endif
380
446
  case RPM_INT8_TYPE:
381
447
  if (count == 1 && !ary_p) {
382
448
  val = INT2NUM(*(int_8*)data);
@@ -462,9 +528,6 @@ rpm_package_aref(VALUE pkg, VALUE tag)
462
528
  return val;
463
529
  }
464
530
  #else
465
- VALUE
466
- rpm_package_aref(VALUE pkg, VALUE tag)
467
- {
468
531
  rpmTag tagval = NUM2INT(tag);
469
532
  VALUE val = Qnil;
470
533
  rpmtd tagc = rpmtdNew();
@@ -612,6 +675,9 @@ rpm_package_sprintf(VALUE pkg, VALUE fmt)
612
675
  return rb_str_new2(str);
613
676
  }
614
677
 
678
+ /*
679
+ * @return [String] This package name
680
+ */
615
681
  VALUE
616
682
  rpm_package_get_name(VALUE pkg)
617
683
  {
@@ -623,6 +689,9 @@ rpm_package_get_name(VALUE pkg)
623
689
  return name;
624
690
  }
625
691
 
692
+ /*
693
+ * @return [String] This package architecture
694
+ */
626
695
  VALUE
627
696
  rpm_package_get_arch(VALUE pkg)
628
697
  {
@@ -634,6 +703,9 @@ rpm_package_get_arch(VALUE pkg)
634
703
  return arch;
635
704
  }
636
705
 
706
+ /*
707
+ * @return [Number] This package signature
708
+ */
637
709
  VALUE
638
710
  rpm_package_get_signature(VALUE pkg)
639
711
  {
@@ -652,6 +724,9 @@ rpm_package_get_signature(VALUE pkg)
652
724
  return signature;
653
725
  }
654
726
 
727
+ /*
728
+ * @return [Version] Version for this package
729
+ */
655
730
  VALUE
656
731
  rpm_package_get_version(VALUE pkg)
657
732
  {
@@ -679,6 +754,9 @@ rpm_package_get_version(VALUE pkg)
679
754
  return ver;
680
755
  }
681
756
 
757
+ /*
758
+ * @return [Array<RPM::File>] File list for this package
759
+ */
682
760
  VALUE
683
761
  rpm_package_get_files(VALUE pkg)
684
762
  {
@@ -735,7 +813,7 @@ rpm_package_get_files(VALUE pkg)
735
813
  return files;
736
814
  }
737
815
 
738
- #if RPM_VERSION_CODE < RPM_VERSION(4,6,0)
816
+ #if RPM_VERSION_CODE < RPM_VERSION(4,6,0) || RPM_VERSION_CODE >= RPM_VERSION(5,0,0)
739
817
  VALUE
740
818
  rpm_package_get_dependency(VALUE pkg,int nametag,int versiontag,int flagtag,VALUE (*dependency_new)(const char*,VALUE,int,VALUE))
741
819
  {
@@ -802,7 +880,7 @@ rpm_package_get_dependency(VALUE pkg,int nametag,int versiontag,int flagtag,VALU
802
880
  while ( rpmtdNext(nametd) != -1 ) {
803
881
  rb_ary_push(deps,dependency_new(rpmtdGetString(nametd),rpm_version_new(rpmtdNextString(versiontd)),*rpmtdNextUint32(flagtd),pkg));
804
882
  }
805
-
883
+
806
884
  leave:
807
885
  rpmtdFree(nametd);
808
886
  rpmtdFree(versiontd);
@@ -811,34 +889,49 @@ rpm_package_get_dependency(VALUE pkg,int nametag,int versiontag,int flagtag,VALU
811
889
  }
812
890
  #endif
813
891
 
892
+ /*
893
+ * @return [Array<RPM::Provide>] Provides list for this package
894
+ */
814
895
  VALUE
815
896
  rpm_package_get_provides(VALUE pkg)
816
897
  {
817
898
  return rpm_package_get_dependency(pkg,RPMTAG_PROVIDENAME,RPMTAG_PROVIDEVERSION,RPMTAG_PROVIDEFLAGS,rpm_provide_new);
818
899
  }
819
900
 
901
+ /*
902
+ * @return [Array<RPM::Require>] Require list for this package
903
+ */
820
904
  VALUE
821
905
  rpm_package_get_requires(VALUE pkg)
822
906
  {
823
907
  return rpm_package_get_dependency(pkg,RPMTAG_REQUIRENAME,RPMTAG_REQUIREVERSION,RPMTAG_REQUIREFLAGS,rpm_require_new);
824
908
  }
825
909
 
910
+ /*
911
+ * @return [Array<RPM::Conflict>] Conflict list for this package
912
+ */
826
913
  VALUE
827
914
  rpm_package_get_conflicts(VALUE pkg)
828
915
  {
829
916
  return rpm_package_get_dependency(pkg,RPMTAG_CONFLICTNAME,RPMTAG_CONFLICTVERSION,RPMTAG_CONFLICTFLAGS,rpm_conflict_new);
830
917
  }
831
918
 
919
+ /*
920
+ * @return [Array<RPM::Obsolete>] Obsoletes list for this package
921
+ */
832
922
  VALUE
833
923
  rpm_package_get_obsoletes(VALUE pkg)
834
924
  {
835
925
  return rpm_package_get_dependency(pkg,RPMTAG_OBSOLETENAME,RPMTAG_OBSOLETEVERSION,RPMTAG_OBSOLETEFLAGS,rpm_obsolete_new);
836
926
  }
837
927
 
838
- #if RPM_VERSION_CODE < RPM_VERSION(4,6,0)
928
+ /*
929
+ * @return [Array<RPM::Changelog>] changelog of the package as an array of entries
930
+ */
839
931
  VALUE
840
932
  rpm_package_get_changelog(VALUE pkg)
841
933
  {
934
+ #if RPM_VERSION_CODE < RPM_VERSION(4,6,0) || RPM_VERSION_CODE >= RPM_VERSION(5,0,0)
842
935
  VALUE cl;
843
936
  register int i;
844
937
 
@@ -875,9 +968,6 @@ rpm_package_get_changelog(VALUE pkg)
875
968
  return cl;
876
969
  }
877
970
  #else
878
- VALUE
879
- rpm_package_get_changelog(VALUE pkg)
880
- {
881
971
  VALUE cl;
882
972
  rpmtd timetd = rpmtdNew();
883
973
  rpmtd nametd = rpmtdNew();
@@ -945,6 +1035,10 @@ rpm_package__dump(VALUE pkg, VALUE limit)
945
1035
  return rpm_package_dump(pkg);
946
1036
  }
947
1037
 
1038
+ /*
1039
+ * String representation of the package: "name-version-release-arch"
1040
+ * @return [String]
1041
+ */
948
1042
  VALUE
949
1043
  rpm_package_to_s(VALUE pkg)
950
1044
  {
@@ -19,15 +19,28 @@
19
19
  #include <sys/mman.h>
20
20
  #include <sys/types.h>
21
21
  #include <sys/stat.h>
22
+ /* Looks missing in rpmds.h */
23
+ #include <sys/utsname.h>
22
24
  #include <unistd.h>
23
25
 
26
+ #if RPM_VERSION(5,0,0) <= RPM_VERSION_CODE
27
+ #include <stdint.h>
28
+ #include <rpm4compat.h>
29
+ #endif
30
+
31
+ /* To get structure definitions */
32
+ #define _RPMDB_INTERNAL
33
+ #define _RPMPS_INTERNAL
34
+
24
35
  #include <rpm/rpmcli.h>
25
- #include <rpm/rpmlib.h>
36
+ #if HAVE_RPM_RPMLIB_H
37
+ # include <rpm/rpmlib.h>
38
+ #endif
26
39
  #include <rpm/rpmdb.h>
27
40
  #include <rpm/rpmbuild.h>
28
41
  #if HAVE_RPM_RPMLOG_H
29
42
  # include <rpm/rpmlog.h>
30
- #else
43
+ #elif HAVE_RPMMESSAGES_H
31
44
  # include <rpm/rpmmessages.h>
32
45
  #endif
33
46
  #if HAVE_RPM_RPMTS_H
@@ -58,9 +71,14 @@
58
71
  #define RPM_SCRIPT_FD(v) (((rpm_trans_t*)DATA_PTR((v)))->script_fd)
59
72
 
60
73
  #if RPM_VERSION_CODE >= RPM_VERSION(4,5,90)
74
+ #if RPM_VERSION_CODE < RPM_VERSION(5,0,0)
61
75
  #define RPMDB_OPAQUE 1
62
76
  #define RPMPS_OPAQUE 1
63
77
  #else
78
+ #define RPMDB_OPAQUE 1
79
+ /* #undef RPMPS_OPAQUE */
80
+ #endif
81
+ #else
64
82
  #define RPMTS_AVAILABLE 1
65
83
  #endif
66
84
 
@@ -122,12 +140,21 @@ get_entry(Header hdr, rpmTag tag, rpmTagType* type, void** ptr)
122
140
  *ptr = NULL;
123
141
  }
124
142
  }
125
- #else
143
+ #elif RPM_VERSION_CODE < RPM_VERSION(5,0,0)
126
144
  inline static void
127
145
  get_entry(Header hdr, rpmTag tag, rpmtd tc)
128
146
  {
129
147
  headerGet(hdr, tag, tc, HEADERGET_MINMEM);
130
148
  }
149
+ #else /* rpm4compat.h */
150
+ inline static void
151
+ get_entry(Header hdr, rpmTag tag, rpmTagType* type, void** ptr)
152
+ {
153
+ if (!headerGetEntry(
154
+ hdr, (int_32)tag, (hTYP_t)type, ptr, NULL)) {
155
+ *ptr = NULL;
156
+ }
157
+ }
131
158
  #endif
132
159
 
133
160
  inline static void
@@ -16,6 +16,10 @@ m_expand(VALUE m, VALUE name)
16
16
  return rb_str_new2(rpmExpand(StringValueCStr(name), NULL));
17
17
  }
18
18
 
19
+ /*
20
+ * @param [String] name Name of the macro
21
+ * @return [String] value of macro +name+
22
+ */
19
23
  static VALUE
20
24
  m_aref(VALUE m, VALUE name)
21
25
  {
@@ -46,6 +50,11 @@ rpm_macro_aref(VALUE name)
46
50
  return m_aref(Qnil, name);
47
51
  }
48
52
 
53
+ /*
54
+ * Setup a macro
55
+ * @param [String] name Name of the macro
56
+ * @param [String] value Value of the macro or +nil+ to delete it
57
+ */
49
58
  static VALUE
50
59
  m_aset(VALUE m, VALUE name, VALUE val)
51
60
  {
@@ -67,6 +76,9 @@ rpm_macro_aset(VALUE name, VALUE val)
67
76
  return m_aset(Qnil, name, val);
68
77
  }
69
78
 
79
+ /*
80
+ * Read configuration files
81
+ */
70
82
  static VALUE
71
83
  m_readrc(int argc, VALUE* argv, VALUE m)
72
84
  {
@@ -134,6 +146,9 @@ rpm_init_marcros(const char* path)
134
146
 
135
147
  static int rpm_verbosity;
136
148
 
149
+ /*
150
+ * @return [Number] Verbosity level
151
+ */
137
152
  static VALUE
138
153
  m_get_verbosity(VALUE m)
139
154
  {
@@ -146,6 +161,10 @@ rpm_get_verbosity(void)
146
161
  return INT2NUM(rpm_verbosity);
147
162
  }
148
163
 
164
+ /*
165
+ * Sets the verbosity level
166
+ * @param [Number] verbosity Verbosity level
167
+ */
149
168
  static VALUE
150
169
  m_set_verbosity(VALUE m, VALUE verbosity)
151
170
  {
@@ -188,11 +207,11 @@ Init_rpm(void)
188
207
  {
189
208
  char *temp;
190
209
  VALUE rbtmpdir;
191
-
210
+
192
211
  rb_require("tmpdir");
193
212
 
194
213
  rbtmpdir = rb_funcall(rb_const_get(rb_cObject,
195
- rb_intern("Dir")),
214
+ rb_intern("Dir")),
196
215
  rb_intern("tmpdir"), 0);
197
216
  rpm_mRPM = rb_define_module("RPM");
198
217
 
@@ -500,7 +519,9 @@ Init_rpm(void)
500
519
  DEF_TRANS_FLAG(NOTRIGGERS);
501
520
  DEF_TRANS_FLAG(NODOCS);
502
521
  DEF_TRANS_FLAG(ALLFILES);
522
+ #if RPM_VERSION_CODE < RPM_VERSION(5,0,0)
503
523
  DEF_TRANS_FLAG(KEEPOBSOLETE);
524
+ #endif
504
525
  #if RPM_VERSION_CODE < RPM_VERSION(4,1,0)
505
526
  DEF_TRANS_FLAG(MULTILIB);
506
527
  #endif
@@ -510,7 +531,9 @@ Init_rpm(void)
510
531
  DEF_TRANS_FLAG(PKGUNDO);
511
532
  DEF_TRANS_FLAG(COMMIT);
512
533
  DEF_TRANS_FLAG(UNDO);
534
+ #if RPM_VERSION_CODE < RPM_VERSION(4,4,8)
513
535
  DEF_TRANS_FLAG(REVERSE);
536
+ #endif
514
537
  DEF_TRANS_FLAG(NOTRIGGERPREIN);
515
538
  DEF_TRANS_FLAG(NOPRE);
516
539
  DEF_TRANS_FLAG(NOPOST);
@@ -523,7 +546,7 @@ Init_rpm(void)
523
546
  DEF_TRANS_FLAG(APPLYONLY);
524
547
  #if RPM_VERSION_CODE < RPM_VERSION(4,1,0)
525
548
  DEF_TRANS_FLAG(CHAINSAW);
526
- #elif RPM_VERSION_CODE < RPM_VERSION(4,5,90)
549
+ #elif RPM_VERSION_CODE < RPM_VERSION(4,4,8)
527
550
  DEF_TRANS_FLAG(ANACONDA);
528
551
  #endif
529
552
  /* NOMD5 is not in jbj's 4.4.6 any more - Mandriva uses that */
@@ -531,10 +554,12 @@ Init_rpm(void)
531
554
  DEF_TRANS_FLAG(NOMD5);
532
555
  #endif
533
556
  #if RPM_VERSION(4,1,0) <= RPM_VERSION_CODE
557
+ #if RPM_VERSION(4,4,8) < RPM_VERSION_CODE
534
558
  DEF_TRANS_FLAG(NOSUGGEST);
535
559
  DEF_TRANS_FLAG(ADDINDEPS);
536
560
  DEF_TRANS_FLAG(NOCONFIGS);
537
561
  #endif
562
+ #endif
538
563
  #undef DEF_TRANS_FLAG
539
564
 
540
565
  #define DEF_PROB_FILTER(name) \
@@ -650,6 +675,15 @@ Init_rpm(void)
650
675
  rb_gc_register_address(&ruby_rpm_temp_format);
651
676
 
652
677
  rpmReadConfigFiles(NULL, NULL);
678
+
679
+ #if RPM_VERSION_CODE < RPM_VERSION(4,4,8)
653
680
  rpmInitMacros(NULL, macrofiles);
681
+ #elif RPM_VERSION_CODE < RPM_VERSION(4,5,90)
682
+ rpmInitMacros(NULL, rpmMacrofiles);
683
+ #elif RPM_VERSION_CODE < RPM_VERSION(5,0,0)
684
+ rpmInitMacros(NULL, macrofiles);
685
+ #else
686
+ rpmInitMacros(NULL, rpmMacrofiles);
687
+ #endif
654
688
  rpmSetVerbosity(RPMLOG_EMERG);
655
689
  }