summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/pacman/db.c67
-rw-r--r--src/pacman/db.h3
-rw-r--r--src/pacman/sync.c14
3 files changed, 75 insertions, 9 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;
diff --git a/src/pacman/db.h b/src/pacman/db.h
index 549fe03c..07713408 100644
--- a/src/pacman/db.h
+++ b/src/pacman/db.h
@@ -21,6 +21,9 @@
#ifndef _PM_DB_H
#define _PM_DB_H
+int db_getlastupdate(PM_DB *db, char *ts);
+int db_setlastupdate(PM_DB *db, char *ts);
+
int db_search(PM_DB *db, const char *treename, list_t *needles);
#endif /* _PM_DB_H */
diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index 495a2274..f927a471 100644
--- a/src/pacman/sync.c
+++ b/src/pacman/sync.c
@@ -161,12 +161,12 @@ static int sync_synctree(int level, list_t *syncs)
for(i = syncs; i; i = i->next) {
list_t *files = NULL;
char newmtime[16] = "";
- char *lastupdate = NULL;
+ char lastupdate[16] = "";
sync_t *sync = (sync_t *)i->data;
if(level < 2) {
/* get the lastupdate time */
- lastupdate = alpm_db_getinfo(sync->db, PM_DB_LASTUPDATE);
+ db_getlastupdate(sync->db, lastupdate);
if(strlen(lastupdate) == 0) {
vprint("failed to get lastupdate time for %s (no big deal)\n", sync->treename);
}
@@ -188,15 +188,11 @@ static int sync_synctree(int level, list_t *syncs)
} else {
if(strlen(newmtime)) {
vprint("sync: new mtime for %s: %s\n", sync->treename, newmtime);
+ db_setlastupdate(sync->db, newmtime);
}
snprintf(path, PATH_MAX, "%s%s/%s" PM_EXT_DB, root, dbpath, sync->treename);
- if(alpm_db_update(sync->db, path, newmtime) == -1) {
- if(pm_errno != PM_ERR_DB_UPTODATE) {
- ERR(NL, "failed to update %s (%s)\n", sync->treename, alpm_strerror(pm_errno));
- success--;
- } else if(!strlen(newmtime)){
- MSG(NL, ":: %s is up to date\n", sync->treename);
- }
+ if(alpm_db_update(sync->db, path) == -1) {
+ ERR(NL, "failed to update %s (%s)\n", sync->treename, alpm_strerror(pm_errno));
}
/* remove the .tar.gz */
unlink(path);