Пример #1
0
/*
 * Initialize the package database
 * The database {RPM::DB#root} / var / lib /rpm is created.
 *
 * @param [String] root Root of the database
 * @param [Boolean] writable Whether the database is writable. Default +false+.
 */
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_PTR(argv[0]);
		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_PTR(rb_str_concat(rb_str_new2(root),
									   rb_str_new2("/var/lib/rpm"))));
	}

	return Qnil;
}
Пример #2
0
int rpmtsInitDB(rpmts ts, int dbmode)
{
    rpmtxn txn = rpmtxnBegin(ts, RPMTXN_WRITE);
    int rc = -1;
    if (txn)
	    rc = rpmdbInit(ts->rootDir, dbmode);
    rpmtxnEnd(txn);
    return rc;
}
Пример #3
0
int rpmtsInitDB(rpmts ts, int dbmode)
{
    rpmlock lock = rpmtsAcquireLock(ts);
    int rc = -1;
    if (lock)
	    rc = rpmdbInit(ts->rootDir, dbmode);
    rpmlockFree(lock);
    return rc;
}