summaryrefslogtreecommitdiffstats
path: root/src/pacman/db.c
diff options
context:
space:
mode:
authorAurelien Foret <aurelien@archlinux.org>2006-02-15 23:53:18 +0100
committerAurelien Foret <aurelien@archlinux.org>2006-02-15 23:53:18 +0100
commita6bececa06f376f86335d1c0175a7f35ca71760a (patch)
treefebd0776acd5daf5d2ccdf0d67fa599a909b1160 /src/pacman/db.c
parent6e76fd8af3113a28280077ba3da016c01a760ba2 (diff)
downloadpacman-a6bececa06f376f86335d1c0175a7f35ca71760a.tar.gz
pacman-a6bececa06f376f86335d1c0175a7f35ca71760a.tar.xz
moved the .lastupdate support from libalpm to pacman
Diffstat (limited to 'src/pacman/db.c')
-rw-r--r--src/pacman/db.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/pacman/db.c b/src/pacman/db.c
index e16bd901..42b93d05 100644
--- a/src/pacman/db.c
+++ b/src/pacman/db.c
@@ -34,6 +34,73 @@
#include "sync.h"
#include "db.h"
+/* 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(PM_DB *db, char *ts)
+{
+ FILE *fp;
+ char *root, *dbpath, *treename;
+ char file[PATH_MAX];
+
+ if(db == NULL || ts == NULL) {
+ return(-1);
+ }
+
+ alpm_get_option(PM_OPT_ROOT, (long *)&root);
+ alpm_get_option(PM_OPT_DBPATH, (long *)&dbpath);
+ treename = alpm_db_getinfo(db, PM_DB_TREENAME);
+ snprintf(file, PATH_MAX, "%s%s/%s/.lastupdate", root, dbpath, treename);
+
+ /* get the last update time, if it's there */
+ if((fp = fopen(file, "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);
+}
+
+/* writes the dbpath/.lastupdate with the contents of *ts
+ */
+int db_setlastupdate(PM_DB *db, char *ts)
+{
+ FILE *fp;
+ char *root, *dbpath, *treename;
+ char file[PATH_MAX];
+
+ if(db == NULL || ts == NULL || strlen(ts) == 0) {
+ return(-1);
+ }
+
+ alpm_get_option(PM_OPT_ROOT, (long *)&root);
+ alpm_get_option(PM_OPT_DBPATH, (long *)&dbpath);
+ treename = alpm_db_getinfo(db, PM_DB_TREENAME);
+ snprintf(file, PATH_MAX, "%s%s/%s/.lastupdate", root, dbpath, treename);
+
+ if((fp = fopen(file, "w")) == NULL) {
+ return(-1);
+ }
+ if(fputs(ts, fp) <= 0) {
+ fclose(fp);
+ return(-1);
+ }
+ fclose(fp);
+
+ return(0);
+}
+
int db_search(PM_DB *db, const char *treename, list_t *needles)
{
list_t *i;