summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAurelien Foret <aurelien@archlinux.org>2005-03-22 20:14:49 +0000
committerAurelien Foret <aurelien@archlinux.org>2005-03-22 20:14:49 +0000
commit8179f7cbaa62d4dccf85683b78206d9751d513d7 (patch)
treed438461b9c396d06e1d4f9abb34fb37dc2664d28
parent621e241279c37f00775f5e06f15f6928b969cdc7 (diff)
downloadpacman-8179f7cbaa62d4dccf85683b78206d9751d513d7.tar.xz
- added db_setlastupdate to db.c
- moved db_update from db.c to alpm.c
-rw-r--r--lib/libalpm/alpm.c72
-rw-r--r--lib/libalpm/alpm.h4
-rw-r--r--lib/libalpm/db.c62
-rw-r--r--lib/libalpm/db.h4
-rw-r--r--src/pacman/sync.c4
5 files changed, 67 insertions, 79 deletions
diff --git a/lib/libalpm/alpm.c b/lib/libalpm/alpm.c
index 93ac2fad..d661698a 100644
--- a/lib/libalpm/alpm.c
+++ b/lib/libalpm/alpm.c
@@ -209,27 +209,67 @@ int alpm_db_getlastupdate(PM_DB *db, char *ts)
{
/* Sanity checks */
ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
- ASSERT(db != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
+ ASSERT(db != NULL && db != handle->db_local, RET_ERR(PM_ERR_WRONG_ARGS, -1));
+ ASSERT(ts != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
- return(db_getlastupdate(db, handle->root, handle->dbpath, ts));
+ if(!pm_list_is_ptrin(handle->dbs_sync, db)) {
+ printf("dn not in dbs_sync 1\n");
+ RET_ERR(PM_ERR_DB_NOT_FOUND, -1);
+ }
+
+ return(db_getlastupdate(db, ts));
}
int alpm_db_update(PM_DB *db, char *archive, char *ts)
{
/* Sanity checks */
ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
- ASSERT(db != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
+ ASSERT(db != NULL && db != handle->db_local, RET_ERR(PM_ERR_WRONG_ARGS, -1));
+
+ if(!pm_list_is_ptrin(handle->dbs_sync, db)) {
+ printf("db not in dbs_sync 2\n");
+ RET_ERR(PM_ERR_DB_NOT_FOUND, -1);
+ }
+
+ if(ts && strlen(ts) != 0) {
+ char lastupdate[15];
+ if(db_getlastupdate(db, lastupdate) != -1) {
+ if(strcmp(ts, lastupdate) == 0) {
+ RET_ERR(PM_ERR_DB_UPTODATE, -1);
+ }
+ }
+ }
/* ORE
- Does it make sense to update the 'local' database, or should we prevent it? */
+ stat() the archive to check it exists */
+ /* remove the old dir */
+ _alpm_log(PM_LOG_FLOW2, "removing %s (if it exists)\n", db->path);
/* ORE
- check if the database is registered: if not, return an error */
+ We should db_remove each db entry, and not rmrf the top directory */
+ _alpm_rmrf(db->path);
+ /* make the new dir */
+ if(db_create(handle->root, handle->dbpath, db->treename) != 0) {
+ RET_ERR(PM_ERR_DB_CREATE, -1);
+ }
+
+ /* uncompress the sync database */
/* ORE
- stat() the archive to check it exists */
+ we should not simply unpack the archive, but better parse it and
+ db_write each entry */
+ _alpm_log(PM_LOG_FLOW2, "Unpacking %s...\n", archive);
+ if(_alpm_unpack(archive, db->path, NULL)) {
+ RET_ERR(PM_ERR_XXX, -1);
+ }
- return(db_update(db, handle->root, handle->dbpath, archive, ts));
+ if(ts && strlen(ts) != 0) {
+ if(db_setlastupdate(db, ts) == -1) {
+ RET_ERR(PM_ERR_XXX, -1);
+ }
+ }
+
+ return(0);
}
PM_PKG *alpm_db_readpkg(PM_DB *db, char *name)
@@ -270,24 +310,6 @@ PM_LIST *alpm_db_getgrpcache(PM_DB *db)
return(db_get_grpcache(db));
}
-PM_LIST *alpm_db_nextgrp(PM_LIST *cache)
-{
- /* Sanity checks */
- ASSERT(handle != NULL, return(NULL));
- ASSERT(cache != NULL, return(NULL));
-
- return(cache->next);
-}
-
-PM_GRP *alpm_db_getgrp(PM_LIST *cache)
-{
- /* Sanity checks */
- ASSERT(handle != NULL, return(NULL));
- ASSERT(cache != NULL, return(NULL));
-
- return(cache->data);
-}
-
/*
* Packages
*/
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 6b69b3b0..41a36a0d 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -296,6 +296,7 @@ extern enum __pmerrno_t {
PM_ERR_DB_NOT_FOUND,
PM_ERR_DB_NOT_NULL,
PM_ERR_DB_WRITE,
+ PM_ERR_DB_UPTODATE,
/* Cache */
PM_ERR_CACHE_NULL,
/* Configuration */
@@ -329,7 +330,8 @@ extern enum __pmerrno_t {
PM_ERR_FILE_CONFLICTS,
/* Misc */
PM_ERR_USER_ABORT,
- PM_ERR_INTERNAL_ERROR
+ PM_ERR_INTERNAL_ERROR,
+ PM_ERR_XXX
} pm_errno;
char *alpm_strerror(int err);
diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c
index 68a83b0d..f98706b9 100644
--- a/lib/libalpm/db.c
+++ b/lib/libalpm/db.c
@@ -103,17 +103,17 @@ int db_create(char *root, char *dbpath, char *treename)
* Returns 0 on success, 1 on error
*
*/
-int db_getlastupdate(pmdb_t *db, char *root, char *dbpath, char *ts)
+int db_getlastupdate(pmdb_t *db, char *ts)
{
FILE *fp;
char path[PATH_MAX];
- if(db == NULL) {
+ if(db == NULL || ts == NULL) {
return(-1);
}
/* get the last update time, if it's there */
- snprintf(path, PATH_MAX, "%s%s/%s/.lastupdate", root, dbpath, db->treename);
+ snprintf(path, PATH_MAX, "%s/.lastupdate", db->path);
if((fp = fopen(path, "r")) == NULL) {
return(-1);
} else {
@@ -130,60 +130,26 @@ int db_getlastupdate(pmdb_t *db, char *root, char *dbpath, char *ts)
return(0);
}
-int db_update(pmdb_t *db, char *root, char *dbpath, char *archive, char *ts)
+/* writes the dbpath/.lastupdate with the contents of *ts
+ */
+int db_setlastupdate(pmdb_t *db, char *ts)
{
- char path[PATH_MAX];
-
- if(db == NULL) {
- return(-1);
- }
-
- snprintf(path, PATH_MAX, "%s%s/%s", root, dbpath, db->treename);
-
- /* ORE
- if(ts && strlen(ts)) {
- Should we refuse to update the db if it is already uptodate?
- if(ts != db_getlastupdate(db)) {
- RET_ERR(PM_ERR_DB_UPTODATE, -1);
- }
- }*/
-
- /* 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", path);*/
- /* 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(path);
+ FILE *fp;
+ char file[PATH_MAX];
- /* make the new dir */
- if(db_create(root, dbpath, db->treename) != 0) {
+ if(db == NULL || ts == NULL || strlen(ts) == 0) {
return(-1);
}
- /* uncompress the sync database */
- /* ORE
- _alpm_log(PM_LOG_FLOW2, "Unpacking %s...\n", archive);*/
- if(_alpm_unpack(archive, path, NULL)) {
+ snprintf(file, PATH_MAX, "%s/.lastupdate", db->path);
+ if((fp = fopen(file, "w")) == NULL) {
return(-1);
}
-
- /* writes the db->path/.lastupdate with the contents of *ts */
- if(ts && strlen(ts)) {
- FILE *fp;
- char file[PATH_MAX];
-
- snprintf(file, PATH_MAX, "%s/.lastupdate", path);
- if((fp = fopen(file, "w")) == NULL) {
- return(-1);
- }
- if(fputs(ts, fp) <= 0) {
- fclose(fp);
- return(-1);
- }
+ if(fputs(ts, fp) <= 0) {
fclose(fp);
+ return(-1);
}
-
+ fclose(fp);
return(0);
}
diff --git a/lib/libalpm/db.h b/lib/libalpm/db.h
index e2cd8aa9..2f0ec279 100644
--- a/lib/libalpm/db.h
+++ b/lib/libalpm/db.h
@@ -49,8 +49,8 @@ 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_getlastupdate(pmdb_t *db, char *root, char *dbpath, char *ts);
-int db_update(pmdb_t *db, char *root, char *dbpath, char *archive, char *ts);
+int db_getlastupdate(pmdb_t *db, char *ts);
+int db_setlastupdate(pmdb_t *db, char *ts);
void db_rewind(pmdb_t *db);
pmpkg_t *db_scan(pmdb_t *db, char *target, unsigned int inforeq);
diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index e7aeb06e..6931cf4c 100644
--- a/src/pacman/sync.c
+++ b/src/pacman/sync.c
@@ -174,7 +174,6 @@ static int sync_synctree(list_t *syncs)
sync_t *sync = (sync_t *)i->data;
/* get the lastupdate time */
- snprintf(path, PATH_MAX, "%s/%s", path, sync->treename);
if(alpm_db_getlastupdate(sync->db, lastupdate) == -1) {
vprint("failed to get lastupdate time for %s (no big deal)\n", sync->treename);
}
@@ -197,13 +196,12 @@ static int sync_synctree(list_t *syncs)
} else {
snprintf(path, PATH_MAX, "%s%s/%s"PM_EXT_DB, root, dbpath, sync->treename);
if(alpm_db_update(sync->db, path, newmtime) == -1) {
- fprintf(stderr, "error: failed to set database timestamp (%s)\n", alpm_strerror(pm_errno));
+ fprintf(stderr, "error: failed to synchronize %s (%s)\n", sync->treename, alpm_strerror(pm_errno));
success--;
}
/* remove the .tar.gz */
unlink(path);
}
-
}
return(success);