Ejemplo n.º 1
0
/** Initializes a transaction
 * @param self a Handle object
 * ...
 * @return a Transaction object with the same underlying object
 */
PyObject* pyalpm_trans_init(PyObject *self, PyObject *args, PyObject *kwargs) {
  alpm_handle_t *handle = ALPM_HANDLE(self);
  PyObject *result;
  const char* keywords[] = { INDEX_FLAGS(flagnames), NULL };
  char flags[18] = "\0\0\0\0\0" /* 5 */ "\0\0\0\0\0" /* 10 */ "\0\0\0\0\0" /* 15 */ "\0\0\0";

  /* check all arguments */
  if (!PyArg_ParseTupleAndKeywords(args, kwargs,
        "|bbbbbbbbbbbbbbbbOOO", (char**)keywords,
        INDEX_FLAGS(&flags))) {
    return NULL;
  }

  /* run alpm_trans_init() */
  {
    alpm_transflag_t flag_int = 0;
    int i, ret;
    for (i = 0; i < 18; i++) {
      if (flags[i]) flag_int |= 1U << i;
    }
    ret = alpm_trans_init(handle, flag_int);
    if (ret == -1) {
      RET_ERR("transaction could not be initialized", alpm_errno(handle), NULL);
    }
  }
  result = pyalpm_transaction_from_pmhandle(handle);
  return result;
}
Ejemplo n.º 2
0
int lalpm_trans_init ( lua_State *L )
{
    pmtransflag_t flags;
    int result;

    lua_getfield( L, -1, "flags" );
    if ( ! lua_istable( L, -1 )) {
        lua_pushstring( L, "No 'flags' field was provided to trans_init!" );
        lua_error( L );
    }
    flags = lualpm_totransflags( L );
    lua_pop( L, 1 ); /* Pop the flags table off the stack. */

    /* Registering a nil value with these is alright. In fact it is
       better than running old callbacks. */

    lua_getfield( L, -1, "eventscb" );
    cb_register( L, &transcb_key_event );
    lua_getfield( L, -1, "convcb" );
    cb_register( L, &transcb_key_conv );
    lua_getfield( L, -1, "progresscb" );
    cb_register( L, &transcb_key_progress );

    result = alpm_trans_init( flags,
                              transcb_cfunc_event,
                              transcb_cfunc_conv,
                              transcb_cfunc_progress );
    lua_pushnumber(L, result);
    return 1;
}
gboolean
pk_backend_transaction_initialize (PkBackend *self, alpm_transflag_t flags,
				   GError **error)
{
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (alpm != NULL, FALSE);
	g_return_val_if_fail (cancellable != NULL, FALSE);

	if (alpm_trans_init (alpm, flags) < 0) {
		alpm_errno_t errno = alpm_errno (alpm);
		g_set_error_literal (error, ALPM_ERROR, errno,
				     alpm_strerror (errno));
		return FALSE;
	}

	alpm_option_set_eventcb (alpm, pk_backend_transaction_event_cb);
	alpm_option_set_questioncb (alpm, pk_backend_transaction_conv_cb);
	alpm_option_set_progresscb (alpm, pk_backend_transaction_progress_cb);

	alpm_option_set_dlcb (alpm, pk_backend_transaction_dlcb);
	alpm_option_set_totaldlcb (alpm, pk_backend_transaction_totaldlcb);

	g_cancellable_connect (cancellable,
			       G_CALLBACK (transaction_cancelled_cb),
			       self, NULL);

	return TRUE;
}
Ejemplo n.º 4
0
int trans_init(alpm_transflag_t flags, int check_valid)
{
	int ret;

	check_syncdbs(0, check_valid);

	ret = alpm_trans_init(config->handle, flags);
	if(ret == -1) {
		trans_init_error();
		return -1;
	}
	return 0;
}
Ejemplo n.º 5
0
/*
 * Return: 0 for success.
 */
int ipacman_sync_packages(alpm_list_t *targets)
{
	int ret = 0;
	alpm_list_t *i;
	alpm_list_t *sync_dbs = alpm_get_syncdbs(handle);

	if(sync_dbs == NULL) {
		printf("no usable package repositories configured.\n");
		return 1;
	}

	/* ensure all known dbs are valid */
	for(i = sync_dbs; i; i = alpm_list_next(i)) {
		alpm_db_t *db = i->data;
		if(alpm_db_get_valid(db)) {
			printf("database '%s' is not valid (%s)\n",
					alpm_db_get_name(db), alpm_strerror(alpm_errno(handle)));
			ret = 1;
		}
	}
	if (ret)
		return ret;

	/* Step 1: create a new transaction... */
	ret = alpm_trans_init(handle, ALPM_TRANS_FLAG_FORCE);
	if(ret == -1) {
		trans_init_error(handle);
		return 1;
	}

	/* process targets */
	for(i = targets; i; i = alpm_list_next(i)) {
		const char *targ = i->data;
		if(process_target(targ, ret) == 1) {
			ret = 1;
		}
	}

	if(ret) {
		if(alpm_trans_release(handle) == -1) {
			printf("failed to release transaction (%s)\n", alpm_strerror(alpm_errno(handle)));
		}
		return ret;
	}

	return sync_prepare_execute();
}
Ejemplo n.º 6
0
gboolean pacman_transaction_start (guint32 flags, GError **error) {
	g_return_val_if_fail (pacman_manager != NULL, FALSE);
	
	if (pacman_manager_get_transaction (pacman_manager) != NULL) {
		PacmanError code = PACMAN_ERROR_TRANSACTION_ALREADY_INITIALIZED;
		g_set_error (error, PACMAN_ERROR, code, _("Could not initialize transaction: %s"), alpm_strerror (code));
		return FALSE;
	}
	
	if (alpm_trans_init (flags, pacman_transaction_event_cb, pacman_transaction_question_cb, pacman_transaction_progress_cb) < 0) {
		if (pm_errno == PACMAN_ERROR_ALREADY_RUNNING) {
			g_message (_("If you are certain no other package manager is running, you can remove %s\n"), alpm_option_get_lockfile ());
		}
		
		g_set_error (error, PACMAN_ERROR, pm_errno, _("Could not initialize transaction: %s"), alpm_strerrorlast ());
		return FALSE;
	}
	
	alpm_option_set_dlcb (pacman_transaction_download_cb);
	alpm_option_set_totaldlcb (pacman_transaction_total_download_cb);
	return TRUE;
}
Ejemplo n.º 7
0
/**
 * call-seq:
 *   transaction( [ flags ] ){|transaction|...} → an_object
 *
 * Puts libalpm into transaction mode, i.e. allows you to add
 * and remove packaages by means of a transaction. The block
 * gets called with an instance of the (otherwise uninstanciatable,
 * this is a libalpm restriction) Transaction class, which you can
 * freely modify for your operations. When you added all packages
 * you want to add/remove to/from the system, call Transaction#prepare
 * in order to have libalpm resolve dependencies and other stuff.
 * You can then call Transaction#commit to execute your transaction.
 *
 * === Parameters
 * [flags ({})]
 *   A hash with the following keys:
 *   [:nodeps]
 *     Ignore dependency checks.
 *   [:force]
 *     Ignore file conflicts and overwrite files.
 *   [:nosave]
 *     Delete files even if they are tagged as backup.
 *   [:nodepversion]
 *     Ignore version numbers when checking dependencies.
 *   [:cascade]
 *     Remove also any packages depending on a package being removed.
 *   [:recurse]
 *     Remove packages and their unneeded deps (not explicitely installed).
 *   [:dbonly]
 *     Modify database but do not commit changes to the filesystem.
 *   [:alldeps]
 *     Use ALPM_REASON_DEPEND when installing packages.
 *   [:downloadonly]
 *     Only download packages and do not actually install.
 *   [:noscriptlet]
 *     Do not execute install scriptlets after installing.
 *   [:noconflicts]
 *     Ignore dependency conflicts.
 *   [:needed]
 *     Do not install a package if it is already installed and up to date.
 *   [:allexplicit]
 *     Use ALPM_PKG_REASON_EXPLICIT when installing packages.
 *   [:unneeded]
 *     Do not remove a package if it is needed by another one.
 *   [:recurseall]
 *     Remove also explicitely installed unneeded deps (use with :recurse).
 *   [:nolock]
 *     Do not lock the database during the operation.
 *
 * === Return value
 * The result of the block’s last expression.
 *
 * === Remarks
 * Do not store the Transaction instance somewhere; this will give
 * you grief, because it is a transient object always referring to
 * the currently active transaction or bomb if there is none.
 */
static VALUE transaction(int argc, VALUE argv[], VALUE self)
{
  VALUE transaction;
  VALUE result;
  alpm_handle_t* p_alpm = NULL;
  alpm_transflag_t flags = 0;

  Data_Get_Struct(self, alpm_handle_t, p_alpm);

  if (argc == 1) {
    if (TYPE(argv[0]) != T_HASH)
      rb_raise(rb_eTypeError, "Argument is not a hash.");

    if (rb_hash_aref(flags, STR2SYM("nodeps")))
      flags |= ALPM_TRANS_FLAG_NODEPS;
    if (rb_hash_aref(flags, STR2SYM("force")))
      flags |= ALPM_TRANS_FLAG_FORCE;
    if (rb_hash_aref(flags, STR2SYM("nosave")))
      flags |= ALPM_TRANS_FLAG_NOSAVE;
    if (rb_hash_aref(flags, STR2SYM("nodepversion")))
      flags |= ALPM_TRANS_FLAG_NODEPVERSION;
    if (rb_hash_aref(flags, STR2SYM("cascade")))
      flags |= ALPM_TRANS_FLAG_CASCADE;
    if (rb_hash_aref(flags, STR2SYM("recurse")))
      flags |= ALPM_TRANS_FLAG_RECURSE;
    if (rb_hash_aref(flags, STR2SYM("dbonly")))
      flags |= ALPM_TRANS_FLAG_DBONLY;
    if (rb_hash_aref(flags, STR2SYM("alldeps")))
      flags |= ALPM_TRANS_FLAG_ALLDEPS;
    if (rb_hash_aref(flags, STR2SYM("downloadonly")))
      flags |= ALPM_TRANS_FLAG_DOWNLOADONLY;
    if (rb_hash_aref(flags, STR2SYM("noscriptlet")))
      flags |= ALPM_TRANS_FLAG_NOSCRIPTLET;
    if (rb_hash_aref(flags, STR2SYM("noconflicts")))
      flags |= ALPM_TRANS_FLAG_NOCONFLICTS;
    if (rb_hash_aref(flags, STR2SYM("needed")))
      flags |= ALPM_TRANS_FLAG_NEEDED;
    if (rb_hash_aref(flags, STR2SYM("allexplicit")))
      flags |= ALPM_TRANS_FLAG_ALLEXPLICIT;
    if (rb_hash_aref(flags, STR2SYM("unneeded")))
      flags |= ALPM_TRANS_FLAG_UNNEEDED;
    if (rb_hash_aref(flags, STR2SYM("recurseall")))
      flags |= ALPM_TRANS_FLAG_RECURSEALL;
    if (rb_hash_aref(flags, STR2SYM("nolock")))
      flags |= ALPM_TRANS_FLAG_NOLOCK;
  }
  else {
    rb_raise(rb_eArgError, "Wrong number of arguments, expected 0..1, got %d.", argc);
    return Qnil;
  }

  /* Create the transaction */
  if (alpm_trans_init(p_alpm, flags) < 0)
    return raise_last_alpm_error(p_alpm);

  /* Create an instance of Transaction. Note that alpm forces
   * you to only have *one* single Transaction instance, hence
   * there is no other way to instanciate this class apart from
   * this method. The user now modify and exute this sole
   * transaction. */
  transaction = rb_obj_alloc(rb_cAlpm_Transaction);
  rb_iv_set(transaction, "@alpm", self);
  result = rb_yield(transaction);

  /* When we get here we assume the user is done with
   * his stuff. Clean up. */
  if (alpm_trans_release(p_alpm) < 0)
    return raise_last_alpm_error(p_alpm);

  /* Return the last value from the block */
  return result;
}