Class: RPM::DB
- Inherits:
-
Data
- Object
- Data
- RPM::DB
- Includes:
- Enumerable
- Defined in:
- lib/rpm.rb,
ext/rpm/db.c
Class Method Summary collapse
- .each_match(tag, val) ⇒ Object
- .init(*args) ⇒ Object
- .new(*args) ⇒ Object
- .open(*args) ⇒ Object
-
.packages(label = nil) ⇒ Object
def DB.packages.
- .rebuild(*args) ⇒ Object
Instance Method Summary collapse
- #close ⇒ Object
- #closed? ⇒ Boolean
- #each ⇒ Object
- #each_match(key, val) ⇒ Object
- #home ⇒ Object
- #init_iterator(key, val) ⇒ Object
- #root ⇒ Object
- #transaction(*args) ⇒ Object
- #writable? ⇒ Boolean
Class Method Details
.each_match(tag, val) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/rpm.rb', line 22 def DB.each_match(tag, val) begin db = RPM::DB.new db.each_match(tag, val) {|*a| yield a} end GC.start end |
.init(*args) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'ext/rpm/db.c', line 110
static VALUE
db_s_init(int argc, VALUE* argv, VALUE obj)
{
int writable = 0;
const char* root;
switch (argc) {
case 0:
rb_raise(rb_eArgError, "too few argument(1..2)");
case 1: case 2:
if (TYPE(argv[0]) != T_STRING) {
rb_raise(rb_eTypeError, "illegal argument type");
}
root = RSTRING(argv[0])->ptr;
if (argc == 2) {
writable = RTEST(argv[1]);
}
break;
default:
rb_raise(rb_eArgError, "too many argument(1..2)");
}
if (rpmdbInit(root, writable ? O_RDWR | O_CREAT : O_RDONLY)) {
rb_raise(rb_eRuntimeError, "can not initialize database in %s",
RSTRING(rb_str_concat(rb_str_new2(root),
rb_str_new2("/var/lib/rpm")))->ptr);
}
return Qnil;
}
|
.new(*args) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'ext/rpm/db.c', line 53
static VALUE
db_s_open(int argc, VALUE* argv, VALUE obj)
{
VALUE db;
rpm_db_t* rdb;
int writable = 0;
const char* root = "";
switch (argc) {
case 0:
break;
case 1:
writable = RTEST(argv[0]);
break;
case 2:
if (!NIL_P(argv[1])) {
if (TYPE(argv[1]) != T_STRING) {
rb_raise(rb_eTypeError, "illegal argument type");
}
root = RSTRING(argv[1])->ptr;
}
writable = RTEST(argv[0]);
break;
default:
rb_raise(rb_eArgError, "too many argument(0..2)");
}
rdb = ALLOC_N(rpm_db_t,1);
if (rpmdbOpen(root, &(rdb->db), writable ? O_RDWR | O_CREAT : O_RDONLY, 0644)) {
free(rdb);
rb_raise(rb_eRuntimeError, "can not open database in %s",
RSTRING(rb_str_concat(rb_str_new2(root),
rb_str_new2("/var/lib/rpm")))->ptr);
}
rdb->ref_count = 0;
db_ref(rdb);
db = Data_Wrap_Struct(rpm_cDB, NULL, db_free, rdb);
if (!writable) {
rb_obj_freeze(db);
}
return db;
}
|
.open(*args) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'ext/rpm/db.c', line 53
static VALUE
db_s_open(int argc, VALUE* argv, VALUE obj)
{
VALUE db;
rpm_db_t* rdb;
int writable = 0;
const char* root = "";
switch (argc) {
case 0:
break;
case 1:
writable = RTEST(argv[0]);
break;
case 2:
if (!NIL_P(argv[1])) {
if (TYPE(argv[1]) != T_STRING) {
rb_raise(rb_eTypeError, "illegal argument type");
}
root = RSTRING(argv[1])->ptr;
}
writable = RTEST(argv[0]);
break;
default:
rb_raise(rb_eArgError, "too many argument(0..2)");
}
rdb = ALLOC_N(rpm_db_t,1);
if (rpmdbOpen(root, &(rdb->db), writable ? O_RDWR | O_CREAT : O_RDONLY, 0644)) {
free(rdb);
rb_raise(rb_eRuntimeError, "can not open database in %s",
RSTRING(rb_str_concat(rb_str_new2(root),
rb_str_new2("/var/lib/rpm")))->ptr);
}
rdb->ref_count = 0;
db_ref(rdb);
db = Data_Wrap_Struct(rpm_cDB, NULL, db_free, rdb);
if (!writable) {
rb_obj_freeze(db);
}
return db;
}
|
.packages(label = nil) ⇒ Object
def DB.packages
30 31 32 33 34 35 36 37 38 |
# File 'lib/rpm.rb', line 30 def DB.packages packages = nil begin db = RPM::DB.new packages = db.packages end GC.start packages end |
.rebuild(*args) ⇒ Object
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 |
# File 'ext/rpm/db.c', line 152
static VALUE
db_s_rebuild(int argc, VALUE* argv, VALUE obj)
{
const char* root = "";
int ret;
switch (argc) {
case 0:
break;
case 1:
if (!NIL_P(argv[0])) {
if (TYPE(argv[0]) != T_STRING) {
rb_raise(rb_eTypeError, "illegal argument type");
}
root = RSTRING(argv[0])->ptr;
}
break;
default:
rb_raise(rb_eArgError, "too many arguments(0..1)");
break;
}
#if RPM_VERSION_CODE < RPM_VERSION(4,1,0)
ret = rpmdbRebuild(root);
#else
ret = rpmdbRebuild(root, NULL, NULL);
#endif
if (ret) {
rb_raise(rb_eRuntimeError, "can not rebuild database in %s",
RSTRING(rb_str_concat(rb_str_new2(root),
rb_str_new2("/var/lib/rpm")))->ptr);
}
return Qnil;
}
|
Instance Method Details
#close ⇒ Object
198 199 200 201 202 203 204 205 |
# File 'ext/rpm/db.c', line 198
VALUE
rpm_db_close(VALUE db)
{
db_unref((rpm_db_t*)DATA_PTR(db));
DATA_PTR(db) = NULL;
rb_gc();
return Qnil;
}
|
#closed? ⇒ Boolean
207 208 209 210 211 |
# File 'ext/rpm/db.c', line 207
VALUE
rpm_db_is_closed(VALUE vdb)
{
return DATA_PTR(vdb) ? Qfalse : Qtrue;
}
|
#each ⇒ Object
258 259 260 261 262 263 |
# File 'ext/rpm/db.c', line 258
VALUE
rpm_db_each(VALUE db)
{
check_closed(db);
return rpm_db_each_match(db,INT2NUM(RPMDBI_PACKAGES),Qnil);
}
|
#each_match(key, val) ⇒ Object
244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'ext/rpm/db.c', line 244
VALUE
rpm_db_each_match(VALUE db, VALUE key, VALUE val)
{
VALUE mi;
check_closed(db);
mi = rpm_db_init_iterator (db, key, val);
if (!NIL_P(mi))
return rpm_mi_each (mi);
return Qnil;
}
|
#home ⇒ Object
229 230 231 232 233 234 |
# File 'ext/rpm/db.c', line 229
VALUE
rpm_db_get_home(VALUE db)
{
check_closed(db);
return rb_str_new2(RPM_DB(db)->db_home);
}
|
#init_iterator(key, val) ⇒ Object
1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 |
# File 'ext/rpm/db.c', line 1039
VALUE
rpm_db_init_iterator(VALUE db, VALUE key, VALUE val)
{
rpm_mi_t* mi;
check_closed(db);
if (!NIL_P(val) && TYPE(val) != T_STRING) {
rb_raise(rb_eTypeError, "illegal argument type");
}
mi = ALLOC_N(rpm_mi_t,1);
if ((mi->mi = rpmdbInitIterator(RPM_DB(db), NUM2INT(rb_Integer(key)),
NIL_P(val) ? NULL : RSTRING(val)->ptr,
NIL_P(val) ? 0 : RSTRING(val)->len))){
mi->db = (rpm_db_t*)DATA_PTR(db);
db_ref(mi->db);
return Data_Wrap_Struct(rpm_cMatchIterator, NULL, mi_free, mi);
}
free(mi);
/* FIXME: returning nil here is a pain; for ruby, it would be nicer
to return an empty array */
return Qnil;
}
|
#root ⇒ Object
222 223 224 225 226 227 |
# File 'ext/rpm/db.c', line 222
VALUE
rpm_db_get_root(VALUE db)
{
check_closed(db);
return rb_str_new2(RPM_DB(db)->db_root);
}
|
#transaction(*args) ⇒ Object
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 |
# File 'ext/rpm/db.c', line 294
VALUE
rpm_db_transaction(int argc, VALUE* argv, VALUE db)
{
VALUE trans;
rpm_trans_t* ts;
const char* root = "/";
#if 0
if (OBJ_FROZEN(db)) {
rb_error_frozen("RPM::DB");
}
#endif
switch (argc) {
case 0:
break;
case 1:
if (TYPE(argv[0]) != T_STRING) {
rb_raise(rb_eTypeError, "illegal argument type");
}
root = RSTRING(argv[0])->ptr;
break;
default:
rb_raise(rb_eArgError, "argument too many(0..1)");
}
ts = ALLOC(rpm_trans_t);
#if RPM_VERSION_CODE < RPM_VERSION(4,1,0)
ts->ts = rpmtransCreateSet(RPM_DB(db), root);
#else
ts->ts = rpmtsCreate();
rpmtsSetRootDir(ts->ts, root);
#endif
ts->script_fd = 0;
ts->db = DATA_PTR(db);
trans = Data_Wrap_Struct(rpm_cTransaction, NULL, transaction_free, ts);
db_ref(ts->db);
rb_ivar_set(trans, id_db, db);
rb_catch("abort", transaction_yield, trans);
if (rb_ivar_get(trans, id_aborted) == Qtrue) {
return Qfalse;
} else if (rb_ivar_get(trans, id_commited) != Qtrue && !OBJ_FROZEN(db)) {
rb_catch("abort", transaction_commit, trans);
}
return rb_ivar_get(trans, id_pl);
}
|
#writable? ⇒ Boolean
237 238 239 240 241 242 |
# File 'ext/rpm/db.c', line 237
VALUE
rpm_db_is_writable(VALUE db)
{
check_closed(db);
return OBJ_FROZEN(db) ? Qfalse : Qtrue;
}
|