1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-12-21 23:38:49 -05:00

Added a db_update() function to manage sync databases updates.

The API provides a wrapper alpm_db_update().
This commit is contained in:
Aurelien Foret 2005-03-16 19:31:20 +00:00
parent 5faecdb523
commit 606c70fdc9
4 changed files with 47 additions and 0 deletions

View File

@ -202,6 +202,18 @@ int alpm_db_unregister(PM_DB *db)
return(0);
}
int alpm_db_update(char *treename, char *archive)
{
/* Sanity checks */
ASSERT(handle != NULL, return(-1));
ASSERT(treename != NULL && strlen(treename) != 0, PM_RET_ERR(PM_ERR_WRONG_ARGS, -1));
/* ORE
stat(archive); */
return(db_update(handle->root, handle->dbpath, treename, archive));
}
PM_PKG *alpm_db_readpkg(PM_DB *db, char *name)
{
/* Sanity checks */

View File

@ -92,6 +92,8 @@ int alpm_get_option(unsigned char parm, long *data);
int alpm_db_register(char *treename, PM_DB **db);
int alpm_db_unregister(PM_DB *db);
int alpm_db_update(char *treename, char *archive);
PM_PKG *alpm_db_readpkg(PM_DB *db, char *name);
PM_LIST *alpm_db_getpkgcache(PM_DB *db);

View File

@ -97,6 +97,38 @@ int db_create(char *root, char *dbpath, char *treename)
return(0);
}
int db_update(char *root, char *dbpath, char *treename, char *archive)
{
char ldir[PATH_MAX];
snprintf(ldir, PATH_MAX, "%s%s/%s", root, dbpath, treename);
/* remove the old dir */
/* ORE - do we want to include alpm.h and use the log mechanism from db.c?
_alpm_log(PM_LOG_FLOW2, "removing %s (if it exists)\n", ldir);*/
/* ORE
We should only rmrf the database content, and not the top directory, in case
a (DIR *) structure is associated with it (i.e a call to db_open). */
_alpm_rmrf(ldir);
/* make the new dir */
if(db_create(root, dbpath, treename) != 0) {
return(-1);
}
/* uncompress the sync database */
/* ORE
_alpm_log(PM_LOG_FLOW2, "Unpacking %s...\n", archive);*/
if(_alpm_unpack(archive, ldir, NULL)) {
return(-1);
}
/* ORE
Should we let the the library manage updates only if needed?
Create a .lastupdate file in ldir? Ask for a timestamp as db_update argument? */
return(0);
}
void db_rewind(pmdb_t *db)
{
if(db == NULL || db->dir == NULL) {

View File

@ -46,6 +46,7 @@ typedef struct __pmdb_t {
pmdb_t *db_open(char *root, char *dbpath, char *treename);
void db_close(pmdb_t *db);
int db_create(char *root, char *dbpath, char *treename);
int db_update(char *root, char *dbpath, char *treename, char *archive)
void db_rewind(pmdb_t *db);
pmpkg_t *db_scan(pmdb_t *db, char *target, unsigned int inforeq);