mirror of
https://github.com/moparisthebest/pacman
synced 2024-08-13 17:03:46 -04:00
Improve database server API
Currently we have one call that has all sorts of crazy behavior and doesn't make a whole lot of sense. Go from one method to the normal four methods we have for all of our other lists we use in the library to make it a lot easier for a frontend to manipulate server lists. Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
3045f09ef4
commit
42ab639bf7
@ -174,7 +174,7 @@ const char *alpm_option_get_dbpath(void);
|
|||||||
/** Sets the path to the database directory. */
|
/** Sets the path to the database directory. */
|
||||||
int alpm_option_set_dbpath(const char *dbpath);
|
int alpm_option_set_dbpath(const char *dbpath);
|
||||||
|
|
||||||
/** @name Accessors to the list of package cache directories
|
/** @name Accessors to the list of package cache directories.
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
alpm_list_t *alpm_option_get_cachedirs(void);
|
alpm_list_t *alpm_option_get_cachedirs(void);
|
||||||
@ -317,13 +317,14 @@ const char *alpm_db_get_name(const pmdb_t *db);
|
|||||||
*/
|
*/
|
||||||
const char *alpm_db_get_url(const pmdb_t *db);
|
const char *alpm_db_get_url(const pmdb_t *db);
|
||||||
|
|
||||||
/** Add a new server for a database.
|
/** @name Accessors to the list of servers for a database.
|
||||||
* An empty string or NULL can be passed to empty the current server list.
|
* @{
|
||||||
* @param db database pointer
|
|
||||||
* @param url url of the server
|
|
||||||
* @return 0 on success, -1 on error (pm_errno is set accordingly)
|
|
||||||
*/
|
*/
|
||||||
int alpm_db_setserver(pmdb_t *db, const char *url);
|
alpm_list_t *alpm_db_get_servers(const pmdb_t *db);
|
||||||
|
int alpm_db_set_servers(pmdb_t *db, alpm_list_t *servers);
|
||||||
|
int alpm_db_add_server(pmdb_t *db, const char *url);
|
||||||
|
int alpm_db_remove_server(pmdb_t *db, const char *url);
|
||||||
|
/** @} */
|
||||||
|
|
||||||
int alpm_db_update(int level, pmdb_t *db);
|
int alpm_db_update(int level, pmdb_t *db);
|
||||||
|
|
||||||
|
100
lib/libalpm/db.c
100
lib/libalpm/db.c
@ -129,36 +129,100 @@ int SYMEXPORT alpm_db_unregister(pmdb_t *db)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Set the serverlist of a database. */
|
/** Get the serverlist of a database. */
|
||||||
int SYMEXPORT alpm_db_setserver(pmdb_t *db, const char *url)
|
alpm_list_t SYMEXPORT *alpm_db_get_servers(const pmdb_t *db)
|
||||||
{
|
{
|
||||||
char *newurl;
|
ALPM_LOG_FUNC;
|
||||||
size_t len = 0;
|
|
||||||
|
|
||||||
|
/* Sanity checks */
|
||||||
|
ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, NULL));
|
||||||
|
|
||||||
|
return(db->servers);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Set the serverlist of a database. */
|
||||||
|
int SYMEXPORT alpm_db_set_servers(pmdb_t *db, alpm_list_t *servers)
|
||||||
|
{
|
||||||
ALPM_LOG_FUNC;
|
ALPM_LOG_FUNC;
|
||||||
|
|
||||||
/* Sanity checks */
|
/* Sanity checks */
|
||||||
ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
|
ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
|
||||||
|
|
||||||
if(url) {
|
if(db->servers) FREELIST(db->servers);
|
||||||
len = strlen(url);
|
db->servers = servers;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static char *sanitize_url(const char *url)
|
||||||
|
{
|
||||||
|
char *newurl;
|
||||||
|
size_t len = strlen(url);
|
||||||
|
|
||||||
|
STRDUP(newurl, url, RET_ERR(PM_ERR_MEMORY, NULL));
|
||||||
|
/* strip the trailing slash if one exists */
|
||||||
|
if(newurl[len - 1] == '/') {
|
||||||
|
newurl[len - 1] = '\0';
|
||||||
}
|
}
|
||||||
if(len) {
|
return newurl;
|
||||||
newurl = strdup(url);
|
}
|
||||||
/* strip the trailing slash if one exists */
|
|
||||||
if(newurl[len - 1] == '/') {
|
/** Add a download server to a database.
|
||||||
newurl[len - 1] = '\0';
|
* @param db database pointer
|
||||||
}
|
* @param url url of the server
|
||||||
db->servers = alpm_list_add(db->servers, newurl);
|
* @return 0 on success, -1 on error (pm_errno is set accordingly)
|
||||||
_alpm_log(PM_LOG_DEBUG, "adding new server URL to database '%s': %s\n",
|
*/
|
||||||
db->treename, newurl);
|
int SYMEXPORT alpm_db_add_server(pmdb_t *db, const char *url)
|
||||||
} else {
|
{
|
||||||
FREELIST(db->servers);
|
char *newurl;
|
||||||
_alpm_log(PM_LOG_DEBUG, "serverlist flushed for '%s'\n", db->treename);
|
|
||||||
|
ALPM_LOG_FUNC;
|
||||||
|
|
||||||
|
/* Sanity checks */
|
||||||
|
ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
|
||||||
|
ASSERT(url != NULL && strlen(url) != 0, RET_ERR(PM_ERR_WRONG_ARGS, -1));
|
||||||
|
|
||||||
|
newurl = sanitize_url(url);
|
||||||
|
if(!newurl) {
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
db->servers = alpm_list_add(db->servers, newurl);
|
||||||
|
_alpm_log(PM_LOG_DEBUG, "adding new server URL to database '%s': %s\n",
|
||||||
|
db->treename, newurl);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Remove a download server from a database.
|
||||||
|
* @param db database pointer
|
||||||
|
* @param url url of the server
|
||||||
|
* @return 0 on success, 1 on server not present,
|
||||||
|
* -1 on error (pm_errno is set accordingly)
|
||||||
|
*/
|
||||||
|
int SYMEXPORT alpm_db_remove_server(pmdb_t *db, const char *url)
|
||||||
|
{
|
||||||
|
char *newurl, *vdata = NULL;
|
||||||
|
|
||||||
|
ALPM_LOG_FUNC;
|
||||||
|
|
||||||
|
/* Sanity checks */
|
||||||
|
ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
|
||||||
|
ASSERT(url != NULL && strlen(url) != 0, RET_ERR(PM_ERR_WRONG_ARGS, -1));
|
||||||
|
|
||||||
|
newurl = sanitize_url(url);
|
||||||
|
if(!newurl) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
db->servers = alpm_list_remove_str(db->servers, newurl, &vdata);
|
||||||
|
free(newurl);
|
||||||
|
if(vdata) {
|
||||||
|
_alpm_log(PM_LOG_DEBUG, "removed server URL from database '%s': %s\n",
|
||||||
|
db->treename, newurl);
|
||||||
|
free(vdata);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
/** Set the verify gpg signature option for a database.
|
/** Set the verify gpg signature option for a database.
|
||||||
* @param db database pointer
|
* @param db database pointer
|
||||||
* @param verify enum pgp_verify_t
|
* @param verify enum pgp_verify_t
|
||||||
|
@ -387,7 +387,7 @@ static int _add_mirror(pmdb_t *db, char *value)
|
|||||||
server = temp;
|
server = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(alpm_db_setserver(db, server) != 0) {
|
if(alpm_db_add_server(db, server) != 0) {
|
||||||
/* pm_errno is set by alpm_db_setserver */
|
/* pm_errno is set by alpm_db_setserver */
|
||||||
pm_printf(PM_LOG_ERROR, _("could not add server URL to database '%s': %s (%s)\n"),
|
pm_printf(PM_LOG_ERROR, _("could not add server URL to database '%s': %s (%s)\n"),
|
||||||
dbname, server, alpm_strerrorlast());
|
dbname, server, alpm_strerrorlast());
|
||||||
|
Loading…
Reference in New Issue
Block a user