コード例 #1
0
ファイル: types.c プロジェクト: Berticus/clyde
int
raise_last_pm_error(lua_State *L)
{
    if (pm_errno)
        luaL_error(L, "alpm error: %s", alpm_strerrorlast());
    return luaL_error(L, "[BUG] raising an alpm error without pm_errno being set");
}
コード例 #2
0
static gboolean
disabled_repos_configure (GHashTable *table, GError **error)
{
	const alpm_list_t *i;

	g_debug ("reading config from %s", PK_BACKEND_CONFIG_FILE);

	/* read configuration from pacman.conf file */
	if (!pk_backend_configure (PK_BACKEND_CONFIG_FILE, error)) {
		return FALSE;
	}

	/* disable disabled repos */
	for (i = alpm_option_get_syncdbs (); i != NULL;) {
		pmdb_t *db = (pmdb_t *) i->data;
		const gchar *repo = alpm_db_get_name (db);

		if (g_hash_table_lookup (table, repo) == NULL) {
			/* repo is not disabled */
			i = i->next;
			continue;
		}

		if (alpm_db_unregister (db) < 0) {
			g_set_error (error, ALPM_ERROR, pm_errno, "[%s]: %s",
				     repo, alpm_strerrorlast ());
			return FALSE;
		}

		/* start again because the list gets invalidated */
		i = alpm_option_get_syncdbs ();
	}

	return TRUE;
}
コード例 #3
0
ファイル: testpkg.c プロジェクト: LucaLanziani/alpm_ruby
int main(int argc, char **argv)
{
	int retval = 1; /* default = false */
	pmpkg_t *pkg = NULL;

	if(argc != 2) {
		fprintf(stderr, "usage: %s <package file>\n", BASENAME);
		return(1);
	}

	if(alpm_initialize() == -1) {
		fprintf(stderr, "cannot initialize alpm: %s\n", alpm_strerrorlast());
		return(1);
	}

	/* let us get log messages from libalpm */
	alpm_option_set_logcb(output_cb);

	if(alpm_pkg_load(argv[1], 1, &pkg) == -1 || pkg == NULL) {
		switch(pm_errno) {
			case PM_ERR_PKG_OPEN:
				printf("Cannot open the given file.\n");
				break;
			case PM_ERR_LIBARCHIVE:
			case PM_ERR_PKG_INVALID:
				printf("Package is invalid.\n");
				break;
			default:
				printf("libalpm error: %s\n", alpm_strerrorlast());
				break;
		}
		retval = 1;
	} else {
		alpm_pkg_free(pkg);
		printf("Package is valid.\n");
		retval = 0;
	}

	if(alpm_release() == -1) {
		fprintf(stderr, "error releasing alpm: %s\n", alpm_strerrorlast());
	}

	return(retval);
}
コード例 #4
0
/**
 * pacman_transaction_cancel:
 * @transaction: A #PacmanTransaction.
 * @error: A #GError, or %NULL.
 *
 * Cancels the commit operation of @transaction.
 *
 * Returns: %TRUE if @transaction could be cancelled, or %FALSE if @error is set.
 */
gboolean pacman_transaction_cancel (PacmanTransaction *transaction, GError **error) {
	g_return_val_if_fail (transaction != NULL, FALSE);
	
	if (alpm_trans_interrupt () < 0) {
		g_set_error (error, PACMAN_ERROR, pm_errno, _("Could not cancel transaction: %s"), alpm_strerrorlast ());
		return FALSE;
	}
	
	return TRUE;
}
コード例 #5
0
static gboolean pacman_transaction_real_commit (PacmanTransaction *transaction, GError **error) {
	g_return_val_if_fail (transaction != NULL, FALSE);
	
	if (alpm_trans_commit (NULL) < 0) {
		g_set_error (error, PACMAN_ERROR, pm_errno, _("Could not commit transaction: %s"), alpm_strerrorlast ());
		return FALSE;
	}
	
	return TRUE;
}
コード例 #6
0
/**
 * pacman_manager_set_root_path:
 * @manager: A #PacmanManager.
 * @path: A directory name.
 * @error: A #GError, or %NULL.
 *
 * Sets the RootDir to @path. See pacman_manager_get_root_path().
 *
 * Returns: %TRUE if the RootDir was set successfully, or %FALSE if @error is set.
 */
gboolean pacman_manager_set_root_path (PacmanManager *manager, const gchar *path, GError **error) {
	g_return_val_if_fail (manager != NULL, FALSE);
	g_return_val_if_fail (path != NULL, FALSE);
	
	if (alpm_option_set_root (path) < 0) {
		g_set_error (error, PACMAN_ERROR, pm_errno, _("Could not set root directory: %s"), alpm_strerrorlast ());
		return FALSE;
	}
	
	return TRUE;
}
コード例 #7
0
static gboolean
pk_backend_update_databases (PkBackend *self, gint force, GError **error) {
	alpm_cb_download dlcb;
	alpm_cb_totaldl totaldlcb;
	const alpm_list_t *i;

	g_return_val_if_fail (self != NULL, FALSE);

	if (!pk_backend_transaction_initialize (self, 0, error)) {
		return FALSE;
	}

	alpm_logaction ("synchronizing package lists\n");

	dlcb = alpm_option_get_dlcb ();
	totaldlcb = alpm_option_get_totaldlcb ();

	/* set total size to minus the number of databases */
	i = alpm_option_get_syncdbs ();
	totaldlcb (-alpm_list_count (i));

	for (; i != NULL; i = i->next) {
		gint result;

		if (pk_backend_cancelled (self)) {
			/* pretend to be finished */
			i = NULL;
			break;
		}

		result = alpm_db_update (force, i->data);

		if (result > 0) {
			/* fake the download when already up to date */
			dlcb ("", 1, 1);
		} else if (result < 0) {
			g_set_error (error, ALPM_ERROR, pm_errno, "[%s]: %s",
				     alpm_db_get_name (i->data),
				     alpm_strerrorlast ());
			break;
		}
	}

	totaldlcb (0);

	if (i == NULL) {
		return pk_backend_transaction_end (self, error);
	} else {
		pk_backend_transaction_end (self, NULL);
		return FALSE;
	}
}
コード例 #8
0
/**
 * pacman_manager_get:
 * @error: A #GError, or %NULL
 *
 * Gets a reference to the global #PacmanManager object.
 *
 * Returns: A #PacmanManager, or %NULL if @error is set. Free with g_object_unref().
 */
PacmanManager *pacman_manager_get (GError **error) {
	if (pacman_manager == NULL) {
		if (alpm_initialize () < 0) {
			g_set_error (error, PACMAN_ERROR, pm_errno, _("Failed to initialize alpm: %s"), alpm_strerrorlast ());
			return NULL;
		}
		
		alpm_option_set_logcb (pacman_manager_log_cb);
		alpm_option_set_root (PACMAN_ROOT_PATH);
		alpm_option_set_dbpath (PACMAN_DATABASE_PATH);
		alpm_option_set_logfile (PACMAN_LOG_FILE);
		
		pacman_set_user_agent ();
		pacman_manager = pacman_manager_new ();
	} else {
		g_object_ref (pacman_manager);
	}
	
	return pacman_manager;
}
コード例 #9
0
static void
pk_backend_repo_disable_thread (PkBackendJob *job, GVariant *params, gpointer user_data)
{
	const alpm_list_t *i;
	const gchar *repo;

	GError *error = NULL;

	repo = pk_backend_get_string (self, "repo_id");

	for (i = alpm_option_get_syncdbs (); i != NULL; i = i->next) {
		pmdb_t *db = (pmdb_t *) i->data;
		const gchar *name = alpm_db_get_name (db);

		if (g_strcmp0 (repo, name) == 0) {
			if (alpm_db_unregister (db) < 0) {
				g_set_error (&error, ALPM_ERROR, pm_errno,
					     "[%s]: %s", repo,
					     alpm_strerrorlast ());
			} else {
				g_hash_table_insert (disabled, g_strdup (repo),
						     GINT_TO_POINTER (1));
			}
			break;
		}
	}

	if (i == NULL) {
		int code = PM_ERR_DB_NULL;
		g_set_error (&error, ALPM_ERROR, code, "[%s]: %s", repo,
			     alpm_strerror (code));
	}

	if (error != NULL) {
		pk_backend_error (self, error);
		g_error_free (error);
	}

	pk_backend_job_finished (self);
}
コード例 #10
0
ファイル: remove.c プロジェクト: LucaLanziani/alpm_ruby
/**
 * @brief Remove a specified list of packages.
 *
 * @param targets a list of packages (as strings) to remove from the system
 *
 * @return 0 on success, 1 on failure
 */
int pacman_remove(alpm_list_t *targets)
{
    int retval = 0;
    alpm_list_t *i, *data = NULL;

    if(targets == NULL) {
        pm_printf(PM_LOG_ERROR, _("no targets specified (use -h for help)\n"));
        return(1);
    }

    /* Step 0: create a new transaction */
    if(trans_init(PM_TRANS_TYPE_REMOVE, config->flags) == -1) {
        return(1);
    }

    /* Step 1: add targets to the created transaction */
    for(i = targets; i; i = alpm_list_next(i)) {
        char *targ = alpm_list_getdata(i);
        if(alpm_trans_addtarget(targ) == -1) {
            if(pm_errno == PM_ERR_PKG_NOT_FOUND) {
                printf(_("%s not found, searching for group...\n"), targ);
                pmgrp_t *grp = alpm_db_readgrp(db_local, targ);
                if(grp == NULL) {
                    pm_fprintf(stderr, PM_LOG_ERROR, _("'%s': not found in local db\n"), targ);
                    retval = 1;
                    goto cleanup;
                } else {
                    alpm_list_t *p, *pkgnames = NULL;
                    /* convert packages to package names */
                    for(p = alpm_grp_get_pkgs(grp); p; p = alpm_list_next(p)) {
                        pmpkg_t *pkg = alpm_list_getdata(p);
                        pkgnames = alpm_list_add(pkgnames, (void *)alpm_pkg_get_name(pkg));
                    }
                    printf(_(":: group %s:\n"), targ);
                    list_display("   ", pkgnames);
                    int all = yesno(1, _("    Remove whole content?"));
                    for(p = pkgnames; p; p = alpm_list_next(p)) {
                        char *pkgn = alpm_list_getdata(p);
                        if(all || yesno(1, _(":: Remove %s from group %s?"), pkgn, targ)) {
                            if(alpm_trans_addtarget(pkgn) == -1) {
                                pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", targ,
                                           alpm_strerrorlast());
                                retval = 1;
                                alpm_list_free(pkgnames);
                                goto cleanup;
                            }
                        }
                    }
                    alpm_list_free(pkgnames);
                }
            } else {
                pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", targ, alpm_strerrorlast());
                retval = 1;
                goto cleanup;
            }
        }
    }

    /* Step 2: prepare the transaction based on its type, targets and flags */
    if(alpm_trans_prepare(&data) == -1) {
        pm_fprintf(stderr, PM_LOG_ERROR, _("failed to prepare transaction (%s)\n"),
                   alpm_strerrorlast());
        switch(pm_errno) {
        case PM_ERR_UNSATISFIED_DEPS:
            for(i = data; i; i = alpm_list_next(i)) {
                pmdepmissing_t *miss = alpm_list_getdata(i);
                pmdepend_t *dep = alpm_miss_get_dep(miss);
                char *depstring = alpm_dep_get_string(dep);
                printf(_(":: %s: requires %s\n"), alpm_miss_get_target(miss),
                       depstring);
                free(depstring);
            }
            FREELIST(data);
            break;
        default:
            break;
        }
        retval = 1;
        goto cleanup;
    }

    /* Warn user in case of dangerous operation */
    if(config->flags & PM_TRANS_FLAG_RECURSE ||
            config->flags & PM_TRANS_FLAG_CASCADE) {
        /* list transaction targets */
        alpm_list_t *pkglist = alpm_trans_get_pkgs();

        display_targets(pkglist, 0);
        printf("\n");

        /* get confirmation */
        if(yesno(1, _("Do you want to remove these packages?")) == 0) {
            retval = 1;
            goto cleanup;
        }
    }

    /* Step 3: actually perform the removal */
    if(alpm_trans_commit(NULL) == -1) {
        pm_fprintf(stderr, PM_LOG_ERROR, _("failed to commit transaction (%s)\n"),
                   alpm_strerrorlast());
        retval = 1;
    }

    /* Step 4: release transaction resources */
cleanup:
    if(trans_release() == -1) {
        retval = 1;
    }
    return(retval);
}
コード例 #11
0
/**
 * pacman_manager_unregister_all_databases:
 * @manager: A #PacmanManager.
 * @error: A #GError, or %NULL.
 *
 * Unregisters and frees every #PacmanDatabase object known to pacman.
 *
 * Returns: %TRUE if all databases were unregistered, or %FALSE if @error is set.
 */
gboolean pacman_manager_unregister_all_databases (PacmanManager *manager, GError **error) {
	g_return_val_if_fail (manager != NULL, FALSE);
	
	if (alpm_db_unregister_all () < 0) {
		g_set_error (error, PACMAN_ERROR, pm_errno, _("Could not unregister all databases: %s"), alpm_strerrorlast ());
		return FALSE;
	}
	
	return TRUE;
}
コード例 #12
0
/**
 * pacman_manager_register_sync_database:
 * @manager: A #PacmanManager.
 * @name: The name of the a sync database.
 * @error: A #GError, or %NULL.
 *
 * Searches for a sync database named @name, and registers a new one if none were found.
 *
 * Returns: A #PacmanDatabase, or %NULL if @error is set.
 */
PacmanDatabase *pacman_manager_register_sync_database (PacmanManager *manager, const gchar *name, GError **error) {
	PacmanDatabase *database;
	
	g_return_val_if_fail (manager != NULL, NULL);
	g_return_val_if_fail (name != NULL, NULL);
	
	database = alpm_db_register_sync (name);
	if (database == NULL) {
		g_set_error (error, PACMAN_ERROR, pm_errno, _("Could not register database [%s]: %s"), name, alpm_strerrorlast ());
		return NULL;
	}
	
	return database;
}
コード例 #13
0
/**
 * pacman_manager_register_local_database:
 * @manager: A #PacmanManager.
 * @error: A #GError, or %NULL.
 *
 * Gets the local database, or registers one if it was not found.
 *
 * Returns: A #PacmanDatabase, or %NULL if @error is set.
 */
PacmanDatabase *pacman_manager_register_local_database (PacmanManager *manager, GError **error) {
	PacmanDatabase *database;
	
	g_return_val_if_fail (manager != NULL, NULL);
	
	database = pacman_manager_get_local_database (manager);
	if (database == NULL) {
		database = alpm_db_register_local ();
		
		if (database == NULL) {
			g_set_error (error, PACMAN_ERROR, pm_errno, _("Could not register database [%s]: %s"), "local", alpm_strerrorlast ());
			return NULL;
		}
	}
	
	return database;
}
コード例 #14
0
static gboolean pacman_install_prepare (PacmanTransaction *transaction, const PacmanList *targets, GError **error) {
	const PacmanList *i;
	PacmanList *data = NULL;
	
	g_return_val_if_fail (transaction != NULL, FALSE);
	g_return_val_if_fail (targets != NULL, FALSE);
	
	if (pacman_transaction_get_installs (transaction) != NULL) {
		/* reinitialize so transaction can be prepared multiple times */
		if (!pacman_transaction_restart (transaction, error)) {
			return FALSE;
		}
	}
	
	for (i = targets; i != NULL; i = pacman_list_next (i)) {
		int result;
		gchar *target = (gchar *) pacman_list_get (i);
		
		if (strstr (target, "://") != NULL) {
			target = alpm_fetch_pkgurl (target);
			if (target == NULL) {
				g_set_error (error, PACMAN_ERROR, pm_errno, _("Could not download package with url '%s': %s"), (gchar *) pacman_list_get (i), alpm_strerrorlast ());
				return FALSE;
			}
			
			result = alpm_add_target (target);
			free (target);
		} else {
			result = alpm_add_target (target);
		}
		
		if (result < 0) {
			g_set_error (error, PACMAN_ERROR, pm_errno, _("Could not mark the file '%s' for installation: %s"), target, alpm_strerrorlast ());
			return FALSE;
		}
	}
	
	if (alpm_trans_prepare (&data) < 0) {
		if (pm_errno == PACMAN_ERROR_PACKAGE_WRONG_ARCHITECTURE) {
			gchar *packages = pacman_package_make_list (data);
			pacman_transaction_set_marked_packages (transaction, data);
			
			g_set_error (error, PACMAN_ERROR, pm_errno, _("The following packages have the wrong architecture: %s"), packages);
			g_free (packages);
			return FALSE;
		} else if (pm_errno == PACMAN_ERROR_DEPENDENCY_UNSATISFIED) {
			gchar *missing = pacman_missing_dependency_make_list (data);
			pacman_transaction_set_missing_dependencies (transaction, data);
			
			g_set_error (error, PACMAN_ERROR, pm_errno, _("Could not prepare transaction: %s"), missing);
			g_free (missing);
			return FALSE;
		} else if (pm_errno == PACMAN_ERROR_CONFLICT) {
			gchar *conflict = pacman_conflict_make_list (data);
			pacman_transaction_set_conflicts (transaction, data);
			
			g_set_error (error, PACMAN_ERROR, pm_errno, _("Could not prepare transaction: %s"), conflict);
			g_free (conflict);
			return FALSE;
		} else if (pm_errno == PACMAN_ERROR_FILE_CONFLICT) {
			gchar *conflict = pacman_file_conflict_make_list (data);
			pacman_transaction_set_file_conflicts (transaction, data);
			
			g_set_error (error, PACMAN_ERROR, pm_errno, _("Could not prepare transaction: %s"), conflict);
			g_free (conflict);
			return FALSE;
		} else if (data != NULL) {
			g_debug ("Possible memory leak for install error: %s\n", alpm_strerrorlast ());
		}
		
		g_set_error (error, PACMAN_ERROR, pm_errno, _("Could not prepare transaction: %s"), alpm_strerrorlast ());
		return FALSE;
	}
	
	return TRUE;
}
コード例 #15
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;
}
コード例 #16
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;
}