Class: RPM::Transaction
- Inherits:
-
Data
- Object
- Data
- RPM::Transaction
- Defined in:
- ext/rpm/db.c
Instance Method Summary collapse
-
#abort ⇒ Object
To abort the transaction.
- #available(pkg, key) ⇒ Object
-
#check ⇒ Array<Dependency>, +nil+
Check the dependencies.
-
#commit(*args) {|CallbackData| ... } ⇒ Object
Performs the transaction.
-
#db ⇒ RPM::DB
The database associated with this transaction.
-
#delete(pkg) ⇒ Object
Add a delete operation to the transaction.
-
#install(pkg, key) ⇒ Object
Add a install operation to the transaction.
-
#keys ⇒ Array<String>
An array of keys corresponding to all transactions that have been added.
-
#order ⇒ Object
To determine the processing order.
-
#script_file ⇒ File
Get transaction script file handle i.e stdout/stderr on scriptlet execution.
-
#script_file=(file) ⇒ Object
Set the transaction script file handle i.e stdout/stderr on scriptlet execution.
-
#upgrade(pkg, key) ⇒ Object
Add a upgrade operation to the transaction.
Instance Method Details
#abort ⇒ Object
To abort the transaction. Database is not changed.
1132 1133 1134 1135 1136 1137 1138 |
# File 'ext/rpm/db.c', line 1132
VALUE
rpm_transaction_abort(VALUE trans)
{
rb_ivar_set(trans, id_aborted, Qtrue);
rb_throw("abort", Qnil);
return Qnil; /* NOT REACHED */
}
|
#available(pkg, key) ⇒ Object
518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 |
# File 'ext/rpm/db.c', line 518
VALUE
rpm_transaction_available(VALUE trans, VALUE pkg, VALUE key)
{
VALUE keys;
if (rb_obj_is_kind_of(pkg, rpm_cPackage) == Qfalse ||
TYPE(key) != T_STRING) {
rb_raise(rb_eTypeError, "illegal argument type");
}
keys = rb_ivar_get(trans, id_keys);
if (NIL_P(keys)) {
keys = rb_ary_new();
rb_ivar_set(trans, id_keys, keys);
}
if (rb_ary_includes(keys, key) == Qtrue) {
rb_raise(rb_eArgError, "key must be unique");
}
rb_ary_push(keys, key);
#if RPM_VERSION_CODE < RPM_VERSION(4,1,0)
rpmtransAvailablePackage(RPM_TRANSACTION(trans), RPM_HEADER(pkg),
RSTRING_PTR(key));
#else
rb_raise(rb_eNotImpError, "need rpmtsAvailablePackage");
// FIXME: What is the analog for rpmtsAvailablePackage
// in newer RPM's ?
//rpmtsAvailablePackage(RPM_TRANSACTION(trans), RPM_HEADER(pkg),
// RSTRING(key)->ptr);
#endif
return Qnil;
}
|
#check ⇒ Array<Dependency>, +nil+
Check the dependencies.
695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 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 756 757 758 759 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 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 |
# File 'ext/rpm/db.c', line 695
VALUE
rpm_transaction_check(VALUE trans)
{
#if RPM_VERSION_CODE < RPM_VERSION(4,1,0)
rpmDependencyConflict conflicts;
int num;
rpmdepCheck(RPM_TRANSACTION(trans), &conflicts, &num);
if (num) {
VALUE list = rb_ary_new();
register int i;
for (i = 0; i < num; i++) {
VALUE dep;
switch (conflicts[i].sense) {
case RPMDEP_SENSE_REQUIRES:
dep = rpm_require_new(conflicts[i].needsName,
rpm_version_new(conflicts[i].needsVersion),
conflicts[i].needsFlags,
rpm_package_new_from_header(conflicts[i].byHeader));
break;
case RPMDEP_SENSE_CONFLICTS:
dep = rpm_conflict_new(conflicts[i].needsName,
rpm_version_new(conflicts[i].needsVersion),
conflicts[i].needsFlags,
rpm_package_new_from_header(conflicts[i].byHeader));
break;
}
rb_ary_push(list, dep);
}
rpmdepFreeConflicts(conflicts, num);
return list;
}
return Qnil;
#else
int rc;
rpmps ps;
int num;
VALUE list = Qnil;
rc = rpmtsCheck(RPM_TRANSACTION(trans));
ps = rpmtsProblems(RPM_TRANSACTION(trans));
/* get rid of duplicate problems */
rpmpsTrim(ps, RPMPROB_FILTER_NONE);
num = rpmpsNumProblems(ps);
#ifdef RPMPS_OPAQUE
rpmpsi psi = rpmpsInitIterator(ps);
if (num > 0) {
list = rb_ary_new();
}
while (rpmpsNextIterator(psi) >= 0) {
rpmProblem p = rpmpsGetProblem(psi);
VALUE dep;
switch (rpmProblemGetType(p)) {
case RPMPROB_REQUIRES: {
char *buf = strdup (rpmProblemGetAltNEVR(p));
/* TODO: zaki: NULL check*/
char *end;
char *name = buf+2;
char *relation = NULL;
char *evr = NULL;
rpmsenseFlags sense_flags = 0;
end = strchr ( name, ' ');
if ( end ) {
*end = '\0';
relation = end + 1;
end = strchr ( relation, ' ');
if ( end ) {
*end = '\0';
evr = end + 1;
}
for ( ; (*relation) != '\0'; relation++ ) {
if ( (*relation) == '=' ) {
sense_flags |= RPMSENSE_EQUAL;
} else if ( (*relation) == '>' ) {
sense_flags |= RPMSENSE_GREATER;
} else if ( (*relation) == '<' ) {
sense_flags |= RPMSENSE_LESS;
}
}
}
dep = rpm_require_new(name,
rpm_version_new(evr ? evr : ""),
sense_flags,
package_new_from_NEVR(
rpmProblemGetPkgNEVR(p)
));
free ( buf );
rb_ary_push(list, dep);
break;
}
default:
break;
}
}
#else
if (ps != NULL && 0 < num) {
rpmProblem p;
int i;
list = rb_ary_new();
for (i = 0; i < num; i++) {
const char *altNEVR;
VALUE dep;
p = ps->probs + i;
altNEVR = (p->altNEVR ? p->altNEVR : "? ?altNEVR?");
if (p->ignoreProblem)
continue;
#if 0 /* XXX shouldn't be needed at all due to rpmpsTrim() */
/* Filter already appended problems. */
for (j = 0; j < i; j++) {
if (!sameProblem(p, ps->probs + j))
break;
}
if (j < i)
continue;
#endif
if ( p->type == RPMPROB_REQUIRES ) {
char *buf = strdup ( altNEVR );
/* TODO: zaki: NULL check*/
char *end;
char *name = buf+2;
char *relation = NULL;
char *evr = "";
rpmsenseFlags sense_flags = 0;
end = strchr ( name, ' ');
if ( end ) {
*end = '\0';
relation = end + 1;
end = strchr ( relation, ' ');
if ( end ) {
*end = '\0';
evr = end + 1;
}
for ( ; (*relation) != '\0'; relation++ ) {
if ( (*relation) == '=' ) {
sense_flags |= RPMSENSE_EQUAL;
} else if ( (*relation) == '>' ) {
sense_flags |= RPMSENSE_GREATER;
} else if ( (*relation) == '<' ) {
sense_flags |= RPMSENSE_LESS;
}
}
}
dep = rpm_require_new(name,
rpm_version_new(evr),
sense_flags,
package_new_from_NEVR(p->pkgNEVR)
);
free ( buf );
rb_ary_push(list, dep);
} else {
#if 0
RPMPROB_CONFLICT:
RPMPROB_BADARCH:
RPMPROB_BADOS:
RPMPROB_PKG_INSTALLED:
RPMPROB_BADRELOCATE:
RPMPROB_NEW_FILE_CONFLICT:
RPMPROB_FILE_CONFLICT:
RPMPROB_OLDPACKAGE:
RPMPROB_DISKSPACE:
RPMPROB_DISKNODES:
RPMPROB_BADPRETRANS:
#endif
break;
}
#if 0
printf ("%d, type=%d, ignoreProblem=%d, str1=%s pkgNEVR=%s, %s\n",
i, p->type, p->ignoreProblem, p->str1, p->pkgNEVR, altNEVR);
#endif
}
}
#endif /* RPMPS_OPAQUE */
ps = rpmpsFree(ps);
return list;
#endif
}
|
#commit(*args) {|CallbackData| ... } ⇒ Object
Performs the transaction.
968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 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 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 |
# File 'ext/rpm/db.c', line 968
VALUE
rpm_transaction_commit(int argc, VALUE* argv, VALUE trans)
{
#if RPM_VERSION_CODE < RPM_VERSION(4,1,0)
rpmProblemSet probset;
int flags = RPMTRANS_FLAG_NONE;
int ignores = RPMPROB_FILTER_NONE;
int rc;
VALUE db;
db = rb_ivar_get(trans, id_db);
if (OBJ_FROZEN(db)) {
rb_error_frozen("RPM::DB");
}
switch (argc) {
case 0:
break;
case 1: case 2:
flags = NUM2INT(rb_Integer(argv[0]));
if (argc == 2) {
ignores = NUM2INT(rb_Integer(argv[1]));
}
break;
default:
rb_raise(rb_eArgError, "too many arguments(0..2)");
}
if (rb_block_given_p() == Qtrue)
rc = rpmRunTransactions(RPM_TRANSACTION(trans), transaction_callback,
(void*)trans, NULL, &probset, flags, ignores);
else{
VALUE keys;
/* rpmcli.h:extern int packagesTotal; */
packagesTotal = 0;
keys = rpm_transaction_keys(trans);
if (!NIL_P(keys))
packagesTotal = NUM2INT(rb_funcall(keys,rb_intern("length"),0));
rc = rpmRunTransactions(RPM_TRANSACTION(trans), rpmShowProgress,
(void*)((long)(INSTALL_HASH|INSTALL_LABEL)),
NULL, &probset, flags, ignores);
}
if (probset != NULL) {
VALUE list = rb_ary_new();
register int i;
for (i = 0; i < probset->numProblems; i++) {
rpmProblem prob = probset->probs + i;
VALUE prb = rb_struct_new(rpm_sProblem,
INT2NUM(prob->type),
(VALUE)prob->key,
rpm_package_new_from_header(prob->h),
rb_str_new2(rpmProblemString(prob)));
rb_ary_push(list, prb);
}
rb_ivar_set(trans, id_pl, list);
}
#else
rpmps ps;
int flags = RPMTRANS_FLAG_NONE;
int ignores = RPMPROB_FILTER_NONE;
int rc;
VALUE db;
db = rb_ivar_get(trans, id_db);
if (OBJ_FROZEN(db)) {
rb_error_frozen("RPM::DB");
}
switch (argc) {
case 0:
break;
case 1: case 2:
flags = NUM2INT(rb_Integer(argv[0]));
if (argc == 2) {
ignores = NUM2INT(rb_Integer(argv[1]));
}
break;
default:
rb_raise(rb_eArgError, "too many arguments(0..2)");
}
/* Drop added/available package indices and dependency sets. */
//rpmtsClean(RPM_TRANSACTION(trans)); // zaki: required?
if (rb_block_given_p() == Qtrue) {
rpmtsSetNotifyCallback(RPM_TRANSACTION(trans),
(rpmCallbackFunction)transaction_callback,(void *)trans);
}else{
VALUE keys;
/* rpmcli.h:extern int rpmcliPackagesTotal; */
rpmcliPackagesTotal = 0;
keys = rpm_transaction_keys(trans);
if (!NIL_P(keys))
rpmcliPackagesTotal = NUM2INT(rb_funcall(keys,rb_intern("length"),0));
rpmtsSetNotifyCallback(RPM_TRANSACTION(trans), rpmShowProgress,
(void*)((long)(INSTALL_HASH|INSTALL_LABEL)));
}
rc = rpmtsRun(RPM_TRANSACTION(trans), NULL, ignores);
ps = rpmtsProblems(RPM_TRANSACTION(trans));
{
VALUE list = rb_ary_new();
#ifdef RPMPS_OPAQUE
rpmpsi psi = rpmpsInitIterator(ps);
while (rpmpsNextIterator(psi) >= 0) {
rpmProblem p = rpmpsGetProblem(psi);
VALUE prb = rb_struct_new(rpm_sProblem,
INT2NUM(rpmProblemGetType(p)),
(VALUE)rpmProblemGetKey(p),
package_new_from_NEVR(
rpmProblemGetAltNEVR(p)+2
),
rb_str_new2(rpmProblemString(p)));
rb_ary_push(list, prb);
}
#else
if (ps != NULL && rpmpsNumProblems(ps) > 0) {
register int i;
for (i = 0; i < rpmpsNumProblems(ps); i++) {
rpmProblem p = ps->probs + i;
const char *altNEVR = (p->altNEVR ? p->altNEVR : "? ?altNEVR?");
VALUE prb = rb_struct_new(rpm_sProblem,
INT2NUM(p->type),
(VALUE)p->key,
package_new_from_NEVR(altNEVR+2),
rb_str_new2(rpmProblemString(p)));
rb_ary_push(list, prb);
}
}
#endif
rb_ivar_set(trans, id_pl, list);
}
if (ps) ps = rpmpsFree(ps);
#endif
rb_ivar_set(trans, id_commited, Qtrue);
rb_throw("abort", Qnil);
return Qnil; /* NOT REACHED */
}
|
#db ⇒ RPM::DB
Returns The database associated with this transaction.
410 411 412 413 414 |
# File 'ext/rpm/db.c', line 410
VALUE
rpm_transaction_get_db(VALUE trans)
{
return rb_ivar_get(trans, id_db);
}
|
#delete(pkg) ⇒ Object
Add a delete operation to the transaction
557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 |
# File 'ext/rpm/db.c', line 557
VALUE
rpm_transaction_delete(VALUE trans, VALUE pkg)
{
VALUE db;
VALUE mi;
db = rb_ivar_get(trans, id_db);
if (TYPE(pkg) == T_STRING)
mi = rpm_db_init_iterator(db, INT2NUM(RPMDBI_LABEL), pkg);
else if (rb_obj_is_kind_of(pkg, rpm_cPackage) != Qfalse) {
VALUE sigmd5 = rpm_package_aref(pkg,INT2NUM(RPMTAG_SIGMD5));
if (sigmd5 != Qnil){
mi = rpm_db_init_iterator(db, INT2NUM(RPMTAG_SIGMD5), sigmd5);
}else{
VALUE name = rpm_package_aref(pkg,INT2NUM(RPMDBI_LABEL));
mi = rpm_db_init_iterator(db, INT2NUM(RPMDBI_LABEL), name);
}
} else if ( rb_obj_is_kind_of(pkg, rpm_cDependency) ==Qfalse &&
rb_respond_to(pkg,rb_intern("name")) && rb_respond_to(pkg,rb_intern("version"))){
mi = rpm_db_init_iterator(db, INT2NUM(RPMDBI_LABEL),rb_funcall(pkg,rb_intern("name"),0));
rpm_mi_set_iterator_version(mi,rb_funcall(pkg,rb_intern("version"),0));
} else
rb_raise(rb_eTypeError, "illegal argument type");
VALUE p;
while (!NIL_P(p = rpm_mi_next_iterator(mi))) {
VALUE off = rpm_mi_get_iterator_offset(mi);
if (!NIL_P(off)){
#if RPM_VERSION_CODE < RPM_VERSION(4,1,0)
rpmtransRemovePackage(RPM_TRANSACTION(trans), NUM2INT(off));
#else
rpmtsAddEraseElement(RPM_TRANSACTION(trans), RPM_HEADER(p), NUM2INT(off));
#endif
}
}
return Qnil;
}
|
#install(pkg, key) ⇒ Object
Add a install operation to the transaction
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 |
# File 'ext/rpm/db.c', line 451
VALUE
rpm_transaction_install(VALUE trans, VALUE pkg, VALUE key)
{
VALUE keys;
if (rb_obj_is_kind_of(pkg, rpm_cPackage) == Qfalse ||
TYPE(key) != T_STRING) {
rb_raise(rb_eTypeError, "illegal argument type");
}
keys = rb_ivar_get(trans, id_keys);
if (NIL_P(keys)) {
keys = rb_ary_new();
rb_ivar_set(trans, id_keys, keys);
}
if (rb_ary_includes(keys, key) == Qtrue) {
rb_raise(rb_eArgError, "key must be unique");
}
rb_ary_push(keys, key);
#if RPM_VERSION_CODE < RPM_VERSION(4,1,0)
rpmtransAddPackage(RPM_TRANSACTION(trans), RPM_HEADER(pkg), NULL,
RSTRING_PTR(key), 0, NULL);
#else
rpmtsAddInstallElement(RPM_TRANSACTION(trans), RPM_HEADER(pkg),
RSTRING_PTR(key), 0, NULL);
#endif
return Qnil;
}
|
#keys ⇒ Array<String>
Returns an array of keys corresponding to all transactions that have been added.
908 909 910 911 912 |
# File 'ext/rpm/db.c', line 908
VALUE
rpm_transaction_keys(VALUE trans)
{
return rb_ivar_get(trans, id_keys);
}
|
#order ⇒ Object
To determine the processing order.
893 894 895 896 897 898 899 900 901 902 |
# File 'ext/rpm/db.c', line 893
VALUE
rpm_transaction_order(VALUE trans)
{
#if RPM_VERSION_CODE < RPM_VERSION(4,1,0)
rpmdepOrder(RPM_TRANSACTION(trans));
#else
rpmtsOrder(RPM_TRANSACTION(trans));
#endif
return Qnil;
}
|
#script_file ⇒ File
Returns Get transaction script file handle i.e stdout/stderr on scriptlet execution.
420 421 422 423 424 |
# File 'ext/rpm/db.c', line 420
VALUE
rpm_transaction_get_script_file(VALUE trans)
{
return rb_ivar_get(trans, id_sf);
}
|
#script_file=(file) ⇒ Object
Set the transaction script file handle
i.e stdout/stderr on scriptlet execution
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 |
# File 'ext/rpm/db.c', line 431
VALUE
rpm_transaction_set_script_file(VALUE trans, VALUE file)
{
if (TYPE(file) != T_FILE) {
rb_raise(rb_eTypeError, "illegal argument type");
}
rb_ivar_set(trans, id_sf, file);
RPM_SCRIPT_FD(trans) = fdDup(NUM2INT(rb_Integer(file)));
#if RPM_VERSION_CODE < RPM_VERSION(4,1,0)
rpmtransSetScriptFd(RPM_TRANSACTION(trans), RPM_SCRIPT_FD(trans));
#else
rpmtsSetScriptFd(RPM_TRANSACTION(trans), RPM_SCRIPT_FD(trans));
#endif
return Qnil;
}
|
#upgrade(pkg, key) ⇒ Object
Add a upgrade operation to the transaction
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 |
# File 'ext/rpm/db.c', line 487
VALUE
rpm_transaction_upgrade(VALUE trans, VALUE pkg, VALUE key)
{
VALUE keys;
if (rb_obj_is_kind_of(pkg, rpm_cPackage) == Qfalse ||
TYPE(key) != T_STRING) {
rb_raise(rb_eTypeError, "illegal argument type");
}
keys = rb_ivar_get(trans, id_keys);
if (NIL_P(keys)) {
keys = rb_ary_new();
rb_ivar_set(trans, id_keys, keys);
}
if (rb_ary_includes(keys, key) == Qtrue) {
rb_raise(rb_eArgError, "key must be unique");
}
rb_ary_push(keys, key);
#if RPM_VERSION_CODE < RPM_VERSION(4,1,0)
rpmtransAddPackage(RPM_TRANSACTION(trans), RPM_HEADER(pkg), NULL,
RSTRING_PTR(key), 1, NULL);
#else
rpmtsAddInstallElement(RPM_TRANSACTION(trans), RPM_HEADER(pkg),
RSTRING_PTR(key), 1, NULL);
#endif
return Qnil;
}
|