Class: RPM::Package

Inherits:
Object
  • Object
show all
Defined in:
ext/rpm/package.c

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.clear_cacheObject



27
28
29
30
31
32
# File 'ext/rpm/package.c', line 27

static VALUE
package_clear_cache(VALUE klass){
	st_free_table(tbl);
	tbl = NULL;
	return klass;
}

.create(name, version) ⇒ Package

Creates a new package object

Parameters:

  • name (String)

    Package name

  • version (Version)

    Package version

Returns:



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'ext/rpm/package.c', line 98

static VALUE
package_s_create(VALUE klass, VALUE name, VALUE version)
{
	Header hdr;
	VALUE pkg;

	if ((TYPE(name) != T_STRING) || (
             rb_obj_is_kind_of(version, rpm_cVersion) == Qfalse))  {
		rb_raise(rb_eTypeError, "illegal argument type");
	}

	hdr = headerNew();
        headerAddEntry(hdr,RPMTAG_NAME,RPM_STRING_TYPE,RSTRING_PTR(name),1);
        headerAddEntry(hdr,RPMTAG_VERSION,RPM_STRING_TYPE,RSTRING_PTR(rpm_version_get_v(version)),1);
        headerAddEntry(hdr,RPMTAG_RELEASE,RPM_STRING_TYPE,RSTRING_PTR(rpm_version_get_r(version)),1);
        if(!NIL_P(rpm_version_get_e(version))){
		int e = NUM2INT(rpm_version_get_e(version));
        	headerAddEntry(hdr,RPMTAG_EPOCH,RPM_INT32_TYPE,&e,1);
	}
	pkg = package_new_from_header(klass, hdr);
  return pkg;
}

.load(str) ⇒ Package

Create a new package object from data

Parameters:

  • str (String)

    Header data

Returns:



209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'ext/rpm/package.c', line 209

static VALUE
package_s_load(VALUE klass, VALUE str)
{
	VALUE pkg, temp;
	Header hdr;
	FD_t fd;

	Check_Type(str, T_STRING);

	temp = ruby_rpm_make_temp_name();
	fd = Fopen(RSTRING_PTR((temp)), "wb+");
	Fwrite(RSTRING_PTR((str)), RSTRING_LEN(str), 1, fd);
	Fseek(fd, 0, SEEK_SET);
	hdr = headerRead(fd, HEADER_MAGIC_YES);
	Fclose(fd);
	unlink(RSTRING_PTR((temp)));

	if (!hdr) {
		rb_raise(rb_eArgError, "unable load RPM::Package");
	}

	pkg = package_new_from_header(klass, hdr);
	headerFree(hdr);

	return pkg;
}

.new(filename) ⇒ Package

Creates a Package object from a rpm located on disk

Examples:

pkg = RPM::Package.open('/home/foo/myprogram-1.0-x86_64.rpm')
pkg.name => 'myprogram'
pkg.version => '1.0'

Parameters:

  • filename (String)

    Path to filename

Returns:



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'ext/rpm/package.c', line 147

static VALUE
package_s_open(VALUE klass, VALUE filename)
{
	VALUE pkg = Qnil;
	FD_t fd;
	Header hdr;
	rpmRC rc;

	if (TYPE(filename) != T_STRING) {
		rb_raise(rb_eTypeError, "illegal argument type");
	}

	fd = Fopen(RSTRING_PTR((filename)), "r");
	if (!fd) {
		rb_raise(rb_eRuntimeError, "can not open file %s",
				 RSTRING_PTR((filename)));
	}

    rc = read_header_from_file(fd, RSTRING_PTR((filename)), &hdr);
	Fclose(fd);

	switch (rc) {
#if RPM_VERSION_CODE < RPM_VERSION(4,1,0)
	case RPMRC_BADSIZE:
#else
	case RPMRC_NOTTRUSTED:
	case RPMRC_NOKEY:
		/* MO_TODO: zaki: should I warn these two status to users? */
#endif
	case RPMRC_OK:
		//headerFree(sigs);
		pkg = package_new_from_header(klass, hdr);
		headerFree(hdr);
		break;

#if RPM_VERSION_CODE < RPM_VERSION(4,1,0)
	case RPMRC_BADMAGIC:
		rb_raise(rb_eRuntimeError, "bad magic");
		break;

#else
	case RPMRC_NOTFOUND:
		rb_raise(rb_eRuntimeError, "bad magic");
		break;

#endif
	case RPMRC_FAIL:
#if RPM_VERSION_CODE < RPM_VERSION(4,1,0)
	case RPMRC_SHORTREAD:
#endif
		rb_raise(rb_eRuntimeError, "error reading pakcage");
		break;
	}

	return pkg;
}

.open(filename) ⇒ Package

Creates a Package object from a rpm located on disk

Examples:

pkg = RPM::Package.open('/home/foo/myprogram-1.0-x86_64.rpm')
pkg.name => 'myprogram'
pkg.version => '1.0'

Parameters:

  • filename (String)

    Path to filename

Returns:



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'ext/rpm/package.c', line 147

static VALUE
package_s_open(VALUE klass, VALUE filename)
{
	VALUE pkg = Qnil;
	FD_t fd;
	Header hdr;
	rpmRC rc;

	if (TYPE(filename) != T_STRING) {
		rb_raise(rb_eTypeError, "illegal argument type");
	}

	fd = Fopen(RSTRING_PTR((filename)), "r");
	if (!fd) {
		rb_raise(rb_eRuntimeError, "can not open file %s",
				 RSTRING_PTR((filename)));
	}

    rc = read_header_from_file(fd, RSTRING_PTR((filename)), &hdr);
	Fclose(fd);

	switch (rc) {
#if RPM_VERSION_CODE < RPM_VERSION(4,1,0)
	case RPMRC_BADSIZE:
#else
	case RPMRC_NOTTRUSTED:
	case RPMRC_NOKEY:
		/* MO_TODO: zaki: should I warn these two status to users? */
#endif
	case RPMRC_OK:
		//headerFree(sigs);
		pkg = package_new_from_header(klass, hdr);
		headerFree(hdr);
		break;

#if RPM_VERSION_CODE < RPM_VERSION(4,1,0)
	case RPMRC_BADMAGIC:
		rb_raise(rb_eRuntimeError, "bad magic");
		break;

#else
	case RPMRC_NOTFOUND:
		rb_raise(rb_eRuntimeError, "bad magic");
		break;

#endif
	case RPMRC_FAIL:
#if RPM_VERSION_CODE < RPM_VERSION(4,1,0)
	case RPMRC_SHORTREAD:
#endif
		rb_raise(rb_eRuntimeError, "error reading pakcage");
		break;
	}

	return pkg;
}

.use_cache=(b) ⇒ Object



34
35
36
37
38
39
40
41
# File 'ext/rpm/package.c', line 34

static VALUE
package_use_cache(VALUE klass,VALUE b){
	if((b==Qtrue)&&(tbl==NULL))
		tbl = (struct st_table*)st_init_numtable();
	else if (b == Qfalse)
		package_clear_cache(klass);
	return klass;
}

Instance Method Details

#[](tag) ⇒ Object

Access a header entry

Examples:

pkg => #<RPM::Package name="xmlgraphics-fop", version=#<RPM::Version v="1.0", r="22.4">>
pkg[RPM::TAG_NAME] => "xmlgraphics-fop"

Parameters:

  • tag (Number)

    Tag to return

Returns:

  • Value of the entry



390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
# File 'ext/rpm/package.c', line 390

VALUE
rpm_package_aref(VALUE pkg, VALUE tag)
{
#if RPM_VERSION_CODE < RPM_VERSION(4,6,0) || RPM_VERSION_CODE >= RPM_VERSION(5,0,0)
	rpmTag tagval = NUM2INT(tag);
	VALUE val = Qnil;
	void* data;
	rpmTagType type;
	int_32 count;
	register int i;
	int ary_p = 0;
	int i18n_p = 0;

	if (!headerGetEntryMinMemory(RPM_HEADER(pkg), tagval, (hTYP_t)&type,
									 (hPTR_t*)&data, (hCNT_t)&count)) {
		goto leave;
	}
	switch (tagval) {
	case RPMTAG_DIRINDEXES:
	case RPMTAG_FILESIZES:
	case RPMTAG_FILESTATES:
	case RPMTAG_FILEMODES:
	case RPMTAG_FILERDEVS:
	case RPMTAG_FILEMTIMES:
	case RPMTAG_FILEMD5S:
	case RPMTAG_FILEFLAGS:
	case RPMTAG_FILEUSERNAME:
	case RPMTAG_FILEGROUPNAME:
	case RPMTAG_PROVIDEFLAGS:
	case RPMTAG_REQUIREFLAGS:
	case RPMTAG_CONFLICTFLAGS:
	case RPMTAG_OBSOLETEFLAGS:
		ary_p = 1;
		break;

	case RPMTAG_GROUP:
	case RPMTAG_SUMMARY:
	case RPMTAG_DISTRIBUTION:
	case RPMTAG_VENDOR:
	case RPMTAG_LICENSE:
	case RPMTAG_PACKAGER:
	case RPMTAG_DESCRIPTION:
		i18n_p = 1;
		break;
  default:
    break;
	}

	switch (type) {
	case RPM_BIN_TYPE:
		val = rb_str_new(data, count);
		break;

#if RPM_VERSION_CODE < RPM_VERSION(5,0,0)
	case RPM_CHAR_TYPE:
#endif
	case RPM_INT8_TYPE:
		if (count == 1 && !ary_p) {
			val = INT2NUM(*(int_8*)data);
		} else {
			val = rb_ary_new();
			for (i = 0; i < count; i++) {
				rb_ary_push(val, INT2NUM(((int_8*)data)[i]));
			}
		}
		break;

	case RPM_INT16_TYPE:
		if (count == 1 && !ary_p) {
			val = INT2NUM(*(int_16*)data);
		} else {
			val = rb_ary_new();
			for (i = 0; i < count; i++) {
				rb_ary_push(val, INT2NUM(((int_16*)data)[i]));
			}
		}
		break;

	case RPM_INT32_TYPE:
		if (count == 1 && !ary_p) {
			val = INT2NUM(*(int_32*)data);
		} else {
			val = rb_ary_new();
			for (i = 0; i < count; i++) {
				rb_ary_push(val, INT2NUM(((int_32*)data)[i]));
			}
		}
		break;

	case RPM_STRING_TYPE:
		if (count == 1 && !ary_p) {
			val = rb_str_new2((char*)data);
		} else {
			char** p = (char**)data;
			val = rb_ary_new();
			for (i = 0; i < count; i++) {
				rb_ary_push(val, rb_str_new2(p[i]));
			}
		}
		release_entry(type, data);
		break;

	case RPM_STRING_ARRAY_TYPE:
		{
			char** p = (char**)data;
			if (i18n_p) {
				char** i18ntab;
				rpmTagType i18nt;
				int_32 i18nc;

				if (!headerGetEntryMinMemory(
						RPM_HEADER(pkg), HEADER_I18NTABLE, (hTYP_t)&i18nt,
						(hPTR_t*)&i18ntab, (hCNT_t)&i18nc)) {
					goto strary;
				}

				val = rb_hash_new();
				for (i = 0; i < count; i++) {
					VALUE lang = rb_str_new2(i18ntab[i]);
					VALUE str = rb_str_new2(p[i]);
					rb_hash_aset(val, lang, str);
				}
				release_entry(i18nt, (void*)i18ntab);
			} else {
			strary:
				val = rb_ary_new();
				for (i = 0; i < count; i++) {
					rb_ary_push(val, rb_str_new2(p[i]));
				}
			}
			release_entry(type, data);
		}
		break;

	default:
		goto leave;
	}
 leave:
	return val;
}

#_dump(limit) ⇒ Object



1032
1033
1034
1035
1036
# File 'ext/rpm/package.c', line 1032

VALUE
rpm_package__dump(VALUE pkg, VALUE limit)
{
	return rpm_package_dump(pkg);
}

#add_binary(tag, val) ⇒ Object

Add a binary value to the package header

Parameters:

  • tag (Number)

    Tag

  • val (String)

    Value



357
358
359
360
361
362
363
364
365
# File 'ext/rpm/package.c', line 357

VALUE
rpm_package_add_binary(VALUE pkg,VALUE tag,VALUE val)
{
	if ((TYPE(val) != T_STRING))  {
		rb_raise(rb_eTypeError, "illegal argument type");
	}
	headerAddEntry(RPM_HEADER(pkg),NUM2INT(tag),RPM_BIN_TYPE,RSTRING_PTR((val)),RSTRING_LEN(val));
  return Qnil;
}

#add_dependency(dep) ⇒ Object

Add a dependency to the package header

Parameters:



271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
# File 'ext/rpm/package.c', line 271

VALUE
rpm_package_add_dependency(VALUE pkg,VALUE dep)
{
	int nametag;
	int versiontag;
	int flagstag;
	char* name;
	char* evr;
	int flag;

	if ( rb_obj_is_kind_of(dep, rpm_cDependency) == Qfalse )  {
		rb_raise(rb_eTypeError, "illegal argument type");
	}

	nametag = NUM2INT(rpm_dependency_get_nametag(dep));
	versiontag = NUM2INT(rpm_dependency_get_versiontag(dep));
	flagstag = NUM2INT(rpm_dependency_get_flagstag(dep));

	name = RSTRING_PTR((rpm_dependency_get_name(dep)));
	evr = RSTRING_PTR((rpm_version_to_vre(rpm_dependency_get_version(dep))));
	flag = NUM2INT(rpm_dependency_get_flags(dep));

	headerAddOrAppendEntry(RPM_HEADER(pkg),nametag,RPM_STRING_ARRAY_TYPE,&name,1);
	headerAddOrAppendEntry(RPM_HEADER(pkg),versiontag,RPM_STRING_ARRAY_TYPE,&evr,1);
	headerAddOrAppendEntry(RPM_HEADER(pkg),flagstag,RPM_INT32_TYPE,&flag,1);
  return Qnil;
}

#add_int32(tag, val) ⇒ Object

Add a int32 value to the package header

Parameters:

  • tag (Number)

    Tag

  • val (Number)

    Value



304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
# File 'ext/rpm/package.c', line 304

VALUE
rpm_package_add_int32(VALUE pkg,VALUE tag,VALUE val)
{
	int_32 v;
	if (TYPE(val) == T_FIXNUM) {
		v = (int_32) FIX2LONG(val);
	}
	else if (TYPE(val) == T_BIGNUM) {
		v = (int_32) NUM2LONG(val);
	}
	else {
		rb_raise(rb_eTypeError, "illegal argument type");
	}

	headerAddOrAppendEntry(RPM_HEADER(pkg),NUM2INT(tag),RPM_INT32_TYPE,&v,1);
  return Qnil;
}

#add_string(tag, val) ⇒ Object

Add a binary value to the package header

Parameters:

  • tag (Number)

    Tag

  • val (String)

    String to add



342
343
344
345
346
347
348
349
350
# File 'ext/rpm/package.c', line 342

VALUE
rpm_package_add_string(VALUE pkg,VALUE tag,VALUE val)
{
	if ((TYPE(val) != T_STRING))  {
		rb_raise(rb_eTypeError, "illegal argument type");
	}
	headerAddEntry(RPM_HEADER(pkg),NUM2INT(tag),RPM_STRING_TYPE,RSTRING_PTR((val)),1);
  return Qnil;
}

#add_string_array(tag, val) ⇒ Object

Add a list of strings to the package header

Parameters:

  • tag (Number)

    Tag

  • val (Array<String>)

    Strings to add



327
328
329
330
331
332
333
334
335
# File 'ext/rpm/package.c', line 327

VALUE
rpm_package_add_string_array(VALUE pkg,VALUE tag,VALUE val)
{
	if ((TYPE(val) != T_STRING))  {
		rb_raise(rb_eTypeError, "illegal argument type");
	}
	headerAddOrAppendEntry(RPM_HEADER(pkg),NUM2INT(tag),RPM_STRING_ARRAY_TYPE,RARRAY_PTR(val),1);
  return Qnil;
}

#archString

Returns This package architecture.

Returns:

  • (String)

    This package architecture



695
696
697
698
699
700
701
702
703
704
# File 'ext/rpm/package.c', line 695

VALUE
rpm_package_get_arch(VALUE pkg)
{
	VALUE arch;
	const char* a;
	headerNEVRA(RPM_HEADER(pkg), NULL, NULL, NULL, NULL, &a);
	arch = a ? rb_str_new2(a) : Qnil;

	return arch;
}

#changelogArray<RPM::Changelog>

Returns changelog of the package as an array of entries.

Returns:

  • (Array<RPM::Changelog>)

    changelog of the package as an array of entries



931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
# File 'ext/rpm/package.c', line 931

VALUE
rpm_package_get_changelog(VALUE pkg)
{
#if RPM_VERSION_CODE < RPM_VERSION(4,6,0) || RPM_VERSION_CODE >= RPM_VERSION(5,0,0)
	VALUE cl;
	register int i;

	char **times,**names,**texts;
	rpmTagType timetype,nametype,texttype;
	int_32 count;

	cl = rb_ary_new();

	if (!headerGetEntryMinMemory(RPM_HEADER(pkg), RPMTAG_CHANGELOGTIME, (hTYP_t)&timetype,
						 (hPTR_t*)&times, (hCNT_t)&count)) {
		return cl;
	}
	if (!headerGetEntryMinMemory(RPM_HEADER(pkg), RPMTAG_CHANGELOGNAME, (hTYP_t)&nametype,
						 (hPTR_t*)&names, (hCNT_t)&count)) {
		release_entry(timetype, (void*)times);
		return cl;
	}
	if (!headerGetEntryMinMemory(RPM_HEADER(pkg), RPMTAG_CHANGELOGTEXT, (hTYP_t)&texttype,
						 (hPTR_t*)&texts, (hCNT_t)&count)) {
		release_entry(timetype, (void*)times);
		release_entry(nametype, (void*)names);
		return cl;
	}

	for (i = 0; i < count; i++) {
		VALUE chglog = rb_struct_new(
			rpm_sChangeLog,
			rb_time_new((time_t)times[i], (time_t)0),
			rb_str_new2(names[i]),
			rb_str_new2(texts[i]));
		rb_ary_push(cl, chglog);
	}
	return cl;
}

#conflictsArray<RPM::Conflict>

Returns Conflict list for this package.

Returns:



913
914
915
916
917
# File 'ext/rpm/package.c', line 913

VALUE
rpm_package_get_conflicts(VALUE pkg)
{
	return rpm_package_get_dependency(pkg,RPMTAG_CONFLICTNAME,RPMTAG_CONFLICTVERSION,RPMTAG_CONFLICTFLAGS,rpm_conflict_new);
}

#copy_to(to, tags) ⇒ Object



236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'ext/rpm/package.c', line 236

VALUE
rpm_package_copy_tags(VALUE from,VALUE to,VALUE tags)
{
#if RPM_VERSION_CODE < RPM_VERSION(4,6,0)
#define rpmTag int_32
#endif
	rpmTag *copy_tags;
	int length = NUM2INT(rb_funcall(tags,rb_intern("length"),0));
	int i;

	copy_tags = ALLOCA_N(rpmTag,length);
	for (i=0;i<length;i++)
		copy_tags[i] = NUM2INT(rb_ary_entry(tags, i));
	headerCopyTags(RPM_HEADER(from),RPM_HEADER(to),copy_tags);
    return Qnil;
}

#delete_tag(tag) ⇒ Object

Deletes a tag of the package header

Parameters:

  • tag (Number)

    Tag



371
372
373
374
375
376
377
378
379
380
# File 'ext/rpm/package.c', line 371

VALUE
rpm_package_delete_tag(VALUE pkg, VALUE tag)
{
	rpmTag tagval = NUM2INT(tag);
	VALUE val;

	val = rpm_package_aref(pkg, tag);
	headerRemoveEntry(RPM_HEADER(pkg), tagval);
	return val;
}

#dumpObject



1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
# File 'ext/rpm/package.c', line 1009

VALUE
rpm_package_dump(VALUE pkg)
{
	VALUE dump, temp;
	FD_t fd;
	off_t size;
	char* buf;

	temp = ruby_rpm_make_temp_name();
	fd = Fopen(RSTRING_PTR((temp)), "wb+");
	headerWrite(fd, RPM_HEADER(pkg), HEADER_MAGIC_YES);
	size = fdSize(fd);

	buf = mmap(NULL, size, PROT_READ, MAP_PRIVATE, Fileno(fd), 0);
	dump = rb_str_new(buf, size);
	munmap(buf, size);

	Fclose(fd);
	unlink(RSTRING_PTR((temp)));

	return dump;
}

#filesArray<RPM::File>

Returns File list for this package.

Returns:

  • (Array<RPM::File>)

    File list for this package



760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
# File 'ext/rpm/package.c', line 760

VALUE
rpm_package_get_files(VALUE pkg)
{
	VALUE files;
	VALUE basenames = rpm_package_aref(pkg, INT2NUM(RPMTAG_BASENAMES));
	VALUE dirnames = rpm_package_aref(pkg, INT2NUM(RPMTAG_DIRNAMES));
	VALUE diridxs = rpm_package_aref(pkg, INT2NUM(RPMTAG_DIRINDEXES));
	VALUE statelist = rpm_package_aref(pkg, INT2NUM(RPMTAG_FILESTATES));
	VALUE flaglist = rpm_package_aref(pkg, INT2NUM(RPMTAG_FILEFLAGS));
	VALUE sizelist = rpm_package_aref(pkg, INT2NUM(RPMTAG_FILESIZES));
	VALUE modelist = rpm_package_aref(pkg, INT2NUM(RPMTAG_FILEMODES));
	VALUE mtimelist = rpm_package_aref(pkg, INT2NUM(RPMTAG_FILEMTIMES));
	VALUE rdevlist = rpm_package_aref(pkg, INT2NUM(RPMTAG_FILERDEVS));
	VALUE linklist = rpm_package_aref(pkg, INT2NUM(RPMTAG_FILELINKTOS));
	VALUE md5list = rpm_package_aref(pkg, INT2NUM(RPMTAG_FILEMD5S));
	VALUE ownerlist = rpm_package_aref(pkg, INT2NUM(RPMTAG_FILEUSERNAME));
	VALUE grouplist = rpm_package_aref(pkg, INT2NUM(RPMTAG_FILEGROUPNAME));
	register int i;

	files = rb_ary_new();
	if (!NIL_P(basenames)) {
		for (i = 0; i < RARRAY_LEN(basenames); i++) {
			static char buf[BUFSIZ];
			VALUE file;
			buf[0] = '\0';
			stpcpy(stpcpy(buf, RSTRING_PTR((RARRAY_PTR(dirnames))[
				           NUM2INT(RARRAY_PTR(diridxs)[i])])),
					   RSTRING_PTR((RARRAY_PTR(basenames)[i])));
			file = rpm_file_new(
				buf,
				RSTRING_PTR((RARRAY_PTR(md5list)[i])),
				(NIL_P(linklist)
				 ? NULL
				 : RSTRING_PTR((RARRAY_PTR(linklist)[i]))),
				NUM2UINT(RARRAY_PTR(sizelist)[i]),
				NUM2INT(RARRAY_PTR(mtimelist)[i]),
				(NIL_P(ownerlist)
				 ? NULL
				 : RSTRING_PTR((RARRAY_PTR(ownerlist)[i]))),
				(NIL_P(grouplist)
				 ? NULL
				 : RSTRING_PTR((RARRAY_PTR(grouplist)[i]))),
				NUM2UINT(RARRAY_PTR(rdevlist)[i]),
				NUM2UINT(RARRAY_PTR(modelist)[i]),
				(NIL_P(flaglist)
				 ? RPMFILE_NONE
				 : NUM2INT(RARRAY_PTR(flaglist)[i])),
				(NIL_P(statelist)
				 ? RPMFILE_STATE_NORMAL
				 : NUM2INT(RARRAY_PTR(statelist)[i])));
			rb_ary_push(files, file);
		}
	}
	return files;
}

#inspectObject



1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
# File 'ext/rpm/package.c', line 1068

VALUE
rpm_package_inspect(VALUE pkg)
{
	char buf[BUFSIZ];
	VALUE name = rpm_package_get_name(pkg);
	VALUE ver  = rpm_package_get_version(pkg);

	if (NIL_P(name)) {
		buf[0] = '\0';
	} else if (NIL_P(ver)) {
		snprintf(buf, BUFSIZ, "#<RPM::Package name=%s>",
				RSTRING_PTR((rb_inspect(name))));
	} else {
		snprintf(buf, BUFSIZ, "#<RPM::Package name=%s, version=%s>",
				RSTRING_PTR((rb_inspect(name))),
				RSTRING_PTR((rb_inspect(ver))));
	}

	return rb_str_new2(buf);
}

#nameString

Returns This package name.

Returns:

  • (String)

    This package name



681
682
683
684
685
686
687
688
689
690
# File 'ext/rpm/package.c', line 681

VALUE
rpm_package_get_name(VALUE pkg)
{
	VALUE name;
	const char* n;
	headerNVR(RPM_HEADER(pkg), &n, NULL, NULL);
	name = n ? rb_str_new2(n) : Qnil;

	return name;
}

#obsoletesArray<RPM::Obsolete>

Returns Obsoletes list for this package.

Returns:



922
923
924
925
926
# File 'ext/rpm/package.c', line 922

VALUE
rpm_package_get_obsoletes(VALUE pkg)
{
	return rpm_package_get_dependency(pkg,RPMTAG_OBSOLETENAME,RPMTAG_OBSOLETEVERSION,RPMTAG_OBSOLETEFLAGS,rpm_obsolete_new);
}

#providesArray<RPM::Provide>

Returns Provides list for this package.

Returns:



895
896
897
898
899
# File 'ext/rpm/package.c', line 895

VALUE
rpm_package_get_provides(VALUE pkg)
{
	return rpm_package_get_dependency(pkg,RPMTAG_PROVIDENAME,RPMTAG_PROVIDEVERSION,RPMTAG_PROVIDEFLAGS,rpm_provide_new);
}

#requiresArray<RPM::Require>

Returns Require list for this package.

Returns:



904
905
906
907
908
# File 'ext/rpm/package.c', line 904

VALUE
rpm_package_get_requires(VALUE pkg)
{
	return rpm_package_get_dependency(pkg,RPMTAG_REQUIRENAME,RPMTAG_REQUIREVERSION,RPMTAG_REQUIREFLAGS,rpm_require_new);
}

#signatureNumber

Returns This package signature.

Returns:

  • (Number)

    This package signature



709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
# File 'ext/rpm/package.c', line 709

VALUE
rpm_package_get_signature(VALUE pkg)
{
	VALUE signature = rb_ivar_get(pkg, id_signature);

	if (NIL_P(signature)) {
        	char *sigmd5;
		sigmd5 = headerSprintf(RPM_HEADER(pkg),"%{sigmd5}",
				rpmTagTable, rpmHeaderFormats, NULL);
		if(sigmd5[0]){
			signature = INT2NUM(rb_intern(sigmd5));
			rb_ivar_set(pkg, id_signature, signature);
		}
		free(sigmd5);
	}
	return signature;
}

#sprintf(fmt) ⇒ Object



663
664
665
666
667
668
669
670
671
672
673
674
675
676
# File 'ext/rpm/package.c', line 663

VALUE
rpm_package_sprintf(VALUE pkg, VALUE fmt)
{
	const char *errstr = "(unknown error)";
	const char *str;

	str = headerSprintf(RPM_HEADER(pkg), StringValueCStr(fmt),
			rpmTagTable, rpmHeaderFormats, &errstr);
	if (str == NULL) {
		rb_raise(rb_eRuntimeError, "incorrect format: %s",
				 errstr);
	}
	return rb_str_new2(str);
}

#to_sString

String representation of the package: “name-version-release-arch”

Returns:

  • (String)


1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
# File 'ext/rpm/package.c', line 1042

VALUE
rpm_package_to_s(VALUE pkg)
{
	char buf[BUFSIZ];
	VALUE name = rpm_package_get_name(pkg);
	VALUE ver  = rpm_package_get_version(pkg);
	VALUE arch = rpm_package_get_arch(pkg);

	if (NIL_P(name)) {
		buf[0] = '\0';
	} else if (NIL_P(ver)) {
		snprintf(buf, BUFSIZ, "%s", RSTRING_PTR((name)));
	} else if (NIL_P(arch)) {
		snprintf(buf, BUFSIZ, "%s-%s",
				RSTRING_PTR((name)),
				RSTRING_PTR((rpm_version_to_s(ver))));
	} else {
		snprintf(buf, BUFSIZ, "%s-%s-%s",
				RSTRING_PTR((name)),
				RSTRING_PTR((rpm_version_to_s(ver))),
				RSTRING_PTR((arch)));
	}

	return rb_str_new2(buf);
}

#versionVersion

Returns Version for this package.

Returns:

  • (Version)

    Version for this package



730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
# File 'ext/rpm/package.c', line 730

VALUE
rpm_package_get_version(VALUE pkg)
{
	VALUE ver;
	const char* v;
	const char* r;
	VALUE e;

	headerNVR(RPM_HEADER(pkg), NULL, &v, &r);
	if (!v) {
		ver = Qnil;
	} else if (!r) {
		ver = rpm_version_new(v);
	} else {
		e = rpm_package_aref(pkg, INT2NUM(RPMTAG_EPOCH));
		if (NIL_P(e)) {
			char* buf = ALLOCA_N(char, strlen(v) + strlen(r) + 2);
			sprintf(buf, "%s-%s", v, r);
			ver = rpm_version_new(buf);
		} else {
			ver = rpm_version_new3(v, r, NUM2INT(e));
		}
	}

	return ver;
}