summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAurelien Foret <aurelien@archlinux.org>2005-03-20 09:22:03 +0000
committerAurelien Foret <aurelien@archlinux.org>2005-03-20 09:22:03 +0000
commit72c24395762c985e404f65f7ec1064efed1d44b5 (patch)
treec2841990bcb4d09359a215d9c48035b9e74506d3 /lib
parent18db4c168bca90d3d44ccd9b4b4d076d2426516d (diff)
downloadpacman-72c24395762c985e404f65f7ec1064efed1d44b5.tar.xz
Added support for .lastupdate files (from pacman 2.9.1)
Diffstat (limited to 'lib')
-rw-r--r--lib/libalpm/alpm.c26
-rw-r--r--lib/libalpm/alpm.h3
-rw-r--r--lib/libalpm/db.c78
-rw-r--r--lib/libalpm/db.h4
4 files changed, 93 insertions, 18 deletions
diff --git a/lib/libalpm/alpm.c b/lib/libalpm/alpm.c
index 94c8d2dc..93ac2fad 100644
--- a/lib/libalpm/alpm.c
+++ b/lib/libalpm/alpm.c
@@ -205,17 +205,31 @@ int alpm_db_unregister(PM_DB *db)
return(0);
}
-int alpm_db_update(char *treename, char *archive)
+int alpm_db_getlastupdate(PM_DB *db, char *ts)
{
/* Sanity checks */
- ASSERT(handle != NULL, return(-1));
- ASSERT(treename != NULL && strlen(treename) != 0, RET_ERR(PM_ERR_WRONG_ARGS, -1));
+ ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
+ ASSERT(db != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
+
+ return(db_getlastupdate(db, handle->root, handle->dbpath, 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));
+
+ /* ORE
+ Does it make sense to update the 'local' database, or should we prevent it? */
+
+ /* ORE
+ check if the database is registered: if not, return an error */
/* ORE
- Does it make sense to update the 'local' database, or should we prevent it?
- stat(archive); */
+ stat() the archive to check it exists */
- return(db_update(handle->root, handle->dbpath, treename, archive));
+ return(db_update(db, handle->root, handle->dbpath, archive, ts));
}
PM_PKG *alpm_db_readpkg(PM_DB *db, char *name)
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 8eb1ece0..6b69b3b0 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -98,7 +98,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);
+int alpm_db_getlastupdate(PM_DB *db, char *ts);
+int alpm_db_update(PM_DB *db, char *archive, char *ts);
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 c555f256..7768b8a5 100644
--- a/lib/libalpm/db.c
+++ b/lib/libalpm/db.c
@@ -97,34 +97,92 @@ int db_create(char *root, char *dbpath, char *treename)
return(0);
}
-int db_update(char *root, char *dbpath, char *treename, char *archive)
+/* reads dbpath/.lastupdate and populates *ts with the contents.
+ * *ts should be malloc'ed and should be at least 15 bytes.
+ *
+ * Returns 0 on success, 1 on error
+ *
+ */
+int db_getlastupdate(pmdb_t *db, char *root, char *dbpath, char *ts)
+{
+ FILE *fp;
+ char path[PATH_MAX];
+
+ if(db == NULL) {
+ return(-1);
+ }
+
+ /* get the last update time, if it's there */
+ snprintf(path, PATH_MAX, "%s%s/%s/.lastupdate", root, dbpath, db->treename);
+ if((fp = fopen(path, "r")) == NULL) {
+ return(-1);
+ } else {
+ char line[256];
+ if(fgets(line, sizeof(line), fp)) {
+ strncpy(ts, line, 15); /* YYYYMMDDHHMMSS */
+ ts[14] = '\0';
+ } else {
+ fclose(fp);
+ return(-1);
+ }
+ }
+ fclose(fp);
+ return(0);
+}
+
+int db_update(pmdb_t *db, char *root, char *dbpath, char *archive, char *ts)
{
- char ldir[PATH_MAX];
+ 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);
+ }
+ }*/
- 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);*/
+ _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(ldir);
+ _alpm_rmrf(path);
/* make the new dir */
- if(db_create(root, dbpath, treename) != 0) {
+ if(db_create(root, dbpath, db->treename) != 0) {
return(-1);
}
/* uncompress the sync database */
/* ORE
_alpm_log(PM_LOG_FLOW2, "Unpacking %s...\n", archive);*/
- if(_alpm_unpack(archive, ldir, NULL)) {
+ if(_alpm_unpack(archive, path, 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? */
+ /* 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);
+ }
+ fclose(fp);
+ }
return(0);
}
diff --git a/lib/libalpm/db.h b/lib/libalpm/db.h
index 07fa1ef2..e2cd8aa9 100644
--- a/lib/libalpm/db.h
+++ b/lib/libalpm/db.h
@@ -48,7 +48,9 @@ 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);
+
+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);
void db_rewind(pmdb_t *db);
pmpkg_t *db_scan(pmdb_t *db, char *target, unsigned int inforeq);