diff options
author | Aurelien Foret <aurelien@archlinux.org> | 2005-03-16 19:31:20 +0000 |
---|---|---|
committer | Aurelien Foret <aurelien@archlinux.org> | 2005-03-16 19:31:20 +0000 |
commit | 606c70fdc9a0ee295fe81ec7e6efbbbe142d01be (patch) | |
tree | 81a14a4b7111a8f18399aeaf7db820f52bc27dad /lib/libalpm | |
parent | 5faecdb523a8a6d1bff082f55d35d4ada6b9a257 (diff) |
Added a db_update() function to manage sync databases updates.
The API provides a wrapper alpm_db_update().
Diffstat (limited to 'lib/libalpm')
-rw-r--r-- | lib/libalpm/alpm.c | 12 | ||||
-rw-r--r-- | lib/libalpm/alpm.h | 2 | ||||
-rw-r--r-- | lib/libalpm/db.c | 32 | ||||
-rw-r--r-- | lib/libalpm/db.h | 1 |
4 files changed, 47 insertions, 0 deletions
diff --git a/lib/libalpm/alpm.c b/lib/libalpm/alpm.c index 6b79d4c8..145996fe 100644 --- a/lib/libalpm/alpm.c +++ b/lib/libalpm/alpm.c @@ -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 */ diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index 4551b3f9..dbc42275 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -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); diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c index 3fad4bb6..ddf06a89 100644 --- a/lib/libalpm/db.c +++ b/lib/libalpm/db.c @@ -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) { diff --git a/lib/libalpm/db.h b/lib/libalpm/db.h index b4161871..fc56f410 100644 --- a/lib/libalpm/db.h +++ b/lib/libalpm/db.h @@ -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); |