Esempio n. 1
0
/* int alpm_trans_release(void); */
int lalpm_trans_release(lua_State *L)
{
    const int result = alpm_trans_release();
    lua_pushnumber(L, result);

    return 1;
}
Esempio n. 2
0
/** Catches thrown signals. Performs necessary cleanup to ensure database is
 * in a consistent state.
 * @param signum the thrown signal
 */
static void handler(int signum)
{
	int out = fileno(stdout);
	int err = fileno(stderr);
	const char *msg;
	if(signum == SIGSEGV) {
		msg = "\nerror: segmentation fault\n"
			"Please submit a full bug report with --debug if appropriate.\n";
		xwrite(err, msg, strlen(msg));
		exit(signum);
	} else if(signum == SIGINT || signum == SIGHUP) {
		if(signum == SIGINT) {
			msg = "\nInterrupt signal received\n";
		} else {
			msg = "\nHangup signal received\n";
		}
		xwrite(err, msg, strlen(msg));
		if(alpm_trans_interrupt(config->handle) == 0) {
			/* a transaction is being interrupted, don't exit pacman yet. */
			return;
		}
	} else if(signum == SIGWINCH) {
		columns_cache_reset();
		return;
	}
	/* SIGINT/SIGHUP: no committing transaction, release it now and then exit pacman
	 * SIGTERM: release no matter what */
	alpm_trans_release(config->handle);
	/* output a newline to be sure we clear any line we may be on */
	xwrite(out, "\n", 1);
	cleanup(128 + signum);
}
gboolean
pk_backend_transaction_end (PkBackend *self, GError **error)
{
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (alpm != NULL, FALSE);

	alpm_option_set_eventcb (alpm, NULL);
	alpm_option_set_questioncb (alpm, NULL);
	alpm_option_set_progresscb (alpm, NULL);

	alpm_option_set_dlcb (alpm, NULL);
	alpm_option_set_totaldlcb (alpm, NULL);

	if (dpkg != NULL) {
		pk_backend_transaction_download_end (self);
	}
	if (tpkg != NULL) {
		pk_backend_output_end (self);
	}

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

	return TRUE;
}
Esempio n. 4
0
static int trans_release(alpm_handle_t *handle)
{
	if(alpm_trans_release(handle) == -1) {
		printf("failed to release transaction (%s)\n", alpm_strerror(alpm_errno(handle)));
		return -1;
	}
	return 0;
}
Esempio n. 5
0
int trans_release(void)
{
	if(alpm_trans_release(config->handle) == -1) {
		pm_printf(ALPM_LOG_ERROR, _("failed to release transaction (%s)\n"),
				alpm_strerror(alpm_errno(config->handle)));
		return -1;
	}
	return 0;
}
gboolean pacman_transaction_end (GError **error) {
	alpm_option_set_dlcb (NULL);
	alpm_option_set_totaldlcb (NULL);
	
	if (alpm_trans_release () < 0) {
		g_set_error (error, PACMAN_ERROR, pm_errno, _("Could not release transaction: %s"), alpm_strerrorlast ());
		return FALSE;
	}
	
	return TRUE;
}
Esempio n. 7
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();
}
Esempio n. 8
0
void
pk_backend_destroy (PkBackend *backend)
{
	PkBackendAlpmPrivate *priv = pk_backend_get_user_data (backend);
	pk_alpm_groups_destroy (backend);
	pk_alpm_destroy_databases (backend);

	if (priv->alpm != NULL) {
		if (alpm_trans_get_flags (priv->alpm) < 0)
			alpm_trans_release (priv->alpm);
		alpm_release (priv->alpm);
	}

	FREELIST (priv->syncfirsts);
	FREELIST (priv->holdpkgs);
	g_free (priv);
}
Esempio n. 9
0
static void
pk_backend_destroy_alpm (PkBackend *self)
{
	g_return_if_fail (self != NULL);

	if (alpm != NULL) {
		if (alpm_trans_get_flags (alpm) < 0) {
			alpm_trans_release (alpm);
		}
		alpm_release (alpm);

		alpm = NULL;
		backend = NULL;
	}

	FREELIST (syncfirsts);
	FREELIST (holdpkgs);
	g_free (xfercmd);
	xfercmd = NULL;
}
Esempio n. 10
0
PyObject* pyalpm_trans_release(PyObject *self, PyObject *args) {
  alpm_handle_t *handle = ALPM_HANDLE(self);
  int ret = alpm_trans_release(handle);
  if (ret == -1) RET_ERR("unable to release transaction", alpm_errno(handle), NULL);
  Py_RETURN_NONE;
}
Esempio n. 11
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;
}