diff options
author | Aurelien Foret <aurelien@archlinux.org> | 2006-02-16 21:02:39 +0000 |
---|---|---|
committer | Aurelien Foret <aurelien@archlinux.org> | 2006-02-16 21:02:39 +0000 |
commit | 58a7e85534f260a49a324dd5b3f408ce1e21cd18 (patch) | |
tree | f0b60c1c8a26a58400522ceee54fb908866a64a0 /lib | |
parent | dc0bacf18cfe2481516778905051879bd008f517 (diff) | |
download | pacman-58a7e85534f260a49a324dd5b3f408ce1e21cd18.tar.xz |
- db_write: add support to write both local and sync entries
- code cleanup
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libalpm/alpm.c | 12 | ||||
-rw-r--r-- | lib/libalpm/db.c | 109 | ||||
-rw-r--r-- | lib/libalpm/db.h | 3 | ||||
-rw-r--r-- | lib/libalpm/list.c | 6 | ||||
-rw-r--r-- | lib/libalpm/list.h | 2 | ||||
-rw-r--r-- | lib/libalpm/log.c | 6 | ||||
-rw-r--r-- | lib/libalpm/package.c | 2 | ||||
-rw-r--r-- | lib/libalpm/sync.c | 21 |
8 files changed, 103 insertions, 58 deletions
diff --git a/lib/libalpm/alpm.c b/lib/libalpm/alpm.c index 58474eb8..7ac7ada2 100644 --- a/lib/libalpm/alpm.c +++ b/lib/libalpm/alpm.c @@ -161,6 +161,8 @@ int alpm_get_option(unsigned char parm, long *data) */ pmdb_t *alpm_db_register(char *treename) { + char path[PATH_MAX]; + struct stat buf; pmdb_t *db; int found = 0; @@ -187,7 +189,15 @@ pmdb_t *alpm_db_register(char *treename) RET_ERR(PM_ERR_DB_NOT_NULL, NULL); } - db = db_open(handle->root, handle->dbpath, treename, DB_O_CREATE); + /* make sure the database directory exists */ + snprintf(path, PATH_MAX, "%s%s", handle->root, handle->dbpath); + if(stat(path, &buf) != 0 || !S_ISDIR(buf.st_mode)) { + if(_alpm_makepath(path) != 0) { + RET_ERR(PM_ERR_SYSTEM, NULL); + } + } + + db = db_open(path, treename, DB_O_CREATE); if(db == NULL) { RET_ERR(PM_ERR_DB_OPEN, NULL); } diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c index 5951e32b..c60ab353 100644 --- a/lib/libalpm/db.c +++ b/lib/libalpm/db.c @@ -38,11 +38,11 @@ #include "alpm.h" /* Open a database and return a pmdb_t handle */ -pmdb_t *db_open(char *root, char *dbpath, char *treename, int mode) +pmdb_t *db_open(char *dbpath, char *treename, int mode) { pmdb_t *db; - if(root == NULL || dbpath == NULL || treename == NULL) { + if(dbpath == NULL || treename == NULL) { return(NULL); } @@ -50,14 +50,14 @@ pmdb_t *db_open(char *root, char *dbpath, char *treename, int mode) MALLOC(db, sizeof(pmdb_t)); - MALLOC(db->path, strlen(root)+strlen(dbpath)+strlen(treename)+2); - sprintf(db->path, "%s%s/%s", root, dbpath, treename); + MALLOC(db->path, strlen(dbpath)+strlen(treename)+2); + sprintf(db->path, "%s/%s", dbpath, treename); db->dir = opendir(db->path); if(db->dir == NULL) { if(mode & DB_O_CREATE) { _alpm_log(PM_LOG_WARNING, "could not open database '%s' -- try creating it", treename); - if(_alpm_makepath(db->path) == 0) { + if(mkdir(db->path, 0755) == 0) { db->dir = opendir(db->path); } } @@ -394,6 +394,7 @@ int db_write(pmdb_t *db, pmpkg_t *info, unsigned int inforeq) mode_t oldmask; PMList *lp = NULL; int retval = 0; + int local = 0; if(db == NULL || info == NULL) { return(-1); @@ -405,6 +406,10 @@ int db_write(pmdb_t *db, pmpkg_t *info, unsigned int inforeq) /* make sure we have a sane umask */ umask(0022); + if(strcmp(db->treename, "local") == 0) { + local = 1; + } + /* DESC */ if(inforeq & INFRQ_DESC) { snprintf(path, PATH_MAX, "%s/desc", topdir); @@ -426,47 +431,58 @@ int db_write(pmdb_t *db, pmpkg_t *info, unsigned int inforeq) } fprintf(fp, "\n"); } - if(info->url[0]) { - fprintf(fp, "%%URL%%\n" - "%s\n\n", info->url); - } - if(info->license) { - fputs("%LICENSE%\n", fp); - for(lp = info->license; lp; lp = lp->next) { - fprintf(fp, "%s\n", (char *)lp->data); + if(local) { + if(info->url[0]) { + fprintf(fp, "%%URL%%\n" + "%s\n\n", info->url); + } + if(info->license) { + fputs("%LICENSE%\n", fp); + for(lp = info->license; lp; lp = lp->next) { + fprintf(fp, "%s\n", (char *)lp->data); + } + fprintf(fp, "\n"); + } + if(info->arch[0]) { + fprintf(fp, "%%ARCH%%\n" + "%s\n\n", info->arch); + } + if(info->builddate[0]) { + fprintf(fp, "%%BUILDDATE%%\n" + "%s\n\n", info->builddate); + } + if(info->installdate[0]) { + fprintf(fp, "%%INSTALLDATE%%\n" + "%s\n\n", info->installdate); + } + if(info->packager[0]) { + fprintf(fp, "%%PACKAGER%%\n" + "%s\n\n", info->packager); + } + if(info->size) { + fprintf(fp, "%%SIZE%%\n" + "%ld\n\n", info->size); + } + if(info->reason) { + fprintf(fp, "%%REASON%%\n" + "%d\n\n", info->reason); + } + } else { + if(info->size) { + fprintf(fp, "%%CSIZE%%\n" + "%ld\n\n", info->size); + } + if(info->reason) { + fprintf(fp, "%%MD5SUM%%\n" + "%s\n\n", info->md5sum); } - fprintf(fp, "\n"); - } - if(info->arch[0]) { - fprintf(fp, "%%ARCH%%\n" - "%s\n\n", info->arch); - } - if(info->builddate[0]) { - fprintf(fp, "%%BUILDDATE%%\n" - "%s\n\n", info->builddate); - } - if(info->installdate[0]) { - fprintf(fp, "%%INSTALLDATE%%\n" - "%s\n\n", info->installdate); - } - if(info->packager[0]) { - fprintf(fp, "%%PACKAGER%%\n" - "%s\n\n", info->packager); - } - if(info->size) { - fprintf(fp, "%%SIZE%%\n" - "%ld\n\n", info->size); - } - if(info->reason) { - fprintf(fp, "%%REASON%%\n" - "%d\n\n", info->reason); } fclose(fp); fp = NULL; } /* FILES */ - if(inforeq & INFRQ_FILES) { + if(local && inforeq & INFRQ_FILES) { snprintf(path, PATH_MAX, "%s/files", topdir); if((fp = fopen(path, "w")) == NULL) { _alpm_log(PM_LOG_ERROR, "db_write: could not open file %s/files", db->treename); @@ -506,7 +522,7 @@ int db_write(pmdb_t *db, pmpkg_t *info, unsigned int inforeq) } fprintf(fp, "\n"); } - if(info->requiredby) { + if(local && info->requiredby) { fputs("%REQUIREDBY%\n", fp); for(lp = info->requiredby; lp; lp = lp->next) { fprintf(fp, "%s\n", (char *)lp->data); @@ -527,6 +543,19 @@ int db_write(pmdb_t *db, pmpkg_t *info, unsigned int inforeq) } fprintf(fp, "\n"); } + if(!local) { + if(info->replaces) { + fputs("%REPLACES%\n", fp); + for(lp = info->replaces; lp; lp = lp->next) { + fprintf(fp, "%s\n", (char *)lp->data); + } + fprintf(fp, "\n"); + } + if(info->force) { + fprintf(fp, "%%FORCE%%\n" + "\n"); + } + } fclose(fp); fp = NULL; } diff --git a/lib/libalpm/db.h b/lib/libalpm/db.h index cd53d01c..a07ed52f 100644 --- a/lib/libalpm/db.h +++ b/lib/libalpm/db.h @@ -47,9 +47,8 @@ typedef struct __pmdb_t { PMList *grpcache; } pmdb_t; -pmdb_t *db_open(char *root, char *dbpath, char *treename, int mode); +pmdb_t *db_open(char *path, char *treename, int mode); void db_close(pmdb_t *db); - void db_rewind(pmdb_t *db); pmpkg_t *db_scan(pmdb_t *db, char *target, unsigned int inforeq); int db_read(pmdb_t *db, char *name, unsigned int inforeq, pmpkg_t *info); diff --git a/lib/libalpm/list.c b/lib/libalpm/list.c index f06102f5..e1113f5c 100644 --- a/lib/libalpm/list.c +++ b/lib/libalpm/list.c @@ -208,16 +208,16 @@ int pm_list_is_in(void *needle, PMList *haystack) /* Test for existence of a string in a PMList */ -PMList *pm_list_is_strin(char *needle, PMList *haystack) +int pm_list_is_strin(char *needle, PMList *haystack) { PMList *lp; for(lp = haystack; lp; lp = lp->next) { if(lp->data && !strcmp(lp->data, needle)) { - return(lp); + return(1); } } - return(NULL); + return(0); } PMList *_alpm_list_last(PMList *list) diff --git a/lib/libalpm/list.h b/lib/libalpm/list.h index 706e61b8..55375314 100644 --- a/lib/libalpm/list.h +++ b/lib/libalpm/list.h @@ -50,7 +50,7 @@ PMList *pm_list_add_sorted(PMList *list, void *data, pm_fn_cmp fn); PMList *_alpm_list_remove(PMList *haystack, void *needle, pm_fn_cmp fn, void **data); int _alpm_list_count(PMList *list); int pm_list_is_in(void *needle, PMList *haystack); -PMList *pm_list_is_strin(char *needle, PMList *haystack); +int pm_list_is_strin(char *needle, PMList *haystack); PMList *_alpm_list_last(PMList *list); PMList *_alpm_list_remove_dupes(PMList *list); PMList *_alpm_list_reverse(PMList *list); diff --git a/lib/libalpm/log.c b/lib/libalpm/log.c index 8e24c495..f0dd2b18 100644 --- a/lib/libalpm/log.c +++ b/lib/libalpm/log.c @@ -33,14 +33,14 @@ unsigned char pm_logmask = 0; void _alpm_log(unsigned char flag, char *fmt, ...) { - char str[LOG_STR_LEN]; - va_list args; - if(pm_logcb == NULL) { return; } if(flag & pm_logmask) { + char str[LOG_STR_LEN]; + va_list args; + va_start(args, fmt); vsnprintf(str, LOG_STR_LEN, fmt, args); va_end(args); diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c index bf5585d2..91b57b0e 100644 --- a/lib/libalpm/package.c +++ b/lib/libalpm/package.c @@ -149,7 +149,7 @@ void pkg_free(pmpkg_t *pkg) static int parse_descfile(char *descfile, pmpkg_t *info, int output) { FILE* fp = NULL; - char line[PATH_MAX+1]; + char line[PATH_MAX]; char* ptr = NULL; char* key = NULL; int linenum = 0; diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c index a1afcd27..b17f9d24 100644 --- a/lib/libalpm/sync.c +++ b/lib/libalpm/sync.c @@ -299,8 +299,7 @@ int sync_addtarget(pmtrans_t *trans, pmdb_t *db_local, PMList *dbs_sync, char *n } _alpm_log(PM_LOG_DEBUG, "found '%s' as a provision for '%s'", p->data, targ); spkg = db_get_pkgfromcache(dbs, p->data); - p->data = NULL; - FREELIST(p); + FREELISTPTR(p); } } } @@ -319,8 +318,7 @@ int sync_addtarget(pmtrans_t *trans, pmdb_t *db_local, PMList *dbs_sync, char *n if(p) { _alpm_log(PM_LOG_DEBUG, "found '%s' as a provision for '%s'", p->data, targ); spkg = db_get_pkgfromcache(dbs, p->data); - p->data = NULL; - FREELIST(p); + FREELISTPTR(p); } } } @@ -416,6 +414,9 @@ int sync_prepare(pmtrans_t *trans, pmdb_t *db_local, PMList *dbs_sync, PMList ** pmpkg_t *spkg = i->data; if(!find_pkginsync(spkg->name, trans->packages)) { pmsyncpkg_t *sync = sync_new(PM_SYNC_TYPE_DEPEND, spkg, NULL); + if(sync == NULL) { + goto error; + } trans->packages = pm_list_add(trans->packages, sync); _alpm_log(PM_LOG_FLOW2, "adding package %s-%s to the transaction targets", spkg->name, spkg->version); @@ -484,7 +485,7 @@ int sync_prepare(pmtrans_t *trans, pmdb_t *db_local, PMList *dbs_sync, PMList ** * (not the same behavior as in pacman 2.x) */ } else { char *rmpkg = NULL; - char *target, *depend; + int target, depend; /* hmmm, depend.name isn't installed, so it must be conflicting * with another package in our final list. For example: * @@ -498,8 +499,8 @@ int sync_prepare(pmtrans_t *trans, pmdb_t *db_local, PMList *dbs_sync, PMList ** /* figure out which one was requested in targets. If they both were, * then it's still an unresolvable conflict. */ - target = pm_list_is_strin(miss->target, trans->targets) ? miss->target : NULL; - depend = pm_list_is_strin(miss->depend.name, trans->targets) ? miss->depend.name : NULL; + target = pm_list_is_strin(miss->target, trans->targets); + depend = pm_list_is_strin(miss->depend.name, trans->targets); if(depend && !target) { _alpm_log(PM_LOG_DEBUG, "'%s' is in the target list -- keeping it", miss->depend.name); @@ -535,6 +536,12 @@ int sync_prepare(pmtrans_t *trans, pmdb_t *db_local, PMList *dbs_sync, PMList ** if(doremove) { pmsyncpkg_t *rsync = find_pkginsync(miss->depend.name, trans->packages); pmpkg_t *q = pkg_new(miss->depend.name, NULL); + if(q == NULL) { + if(data) { + FREELIST(*data); + } + goto error; + } q->requiredby = _alpm_list_strdup(local->requiredby); if(sync->type != PM_SYNC_TYPE_REPLACE) { /* switch this sync type to REPLACE */ |