mirror of
https://github.com/moparisthebest/pacman
synced 2025-01-10 13:28:12 -05:00
moved the .lastupdate support from libalpm to pacman
This commit is contained in:
parent
6e76fd8af3
commit
a6bececa06
@ -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;
|
||||
|
@ -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 */
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user