From 56917dc30493680219e0eceddbf178242522f11d Mon Sep 17 00:00:00 2001 From: Aurelien Foret Date: Mon, 28 Mar 2005 08:21:17 +0000 Subject: improved logs (use _alpm_log instead of fprintf) --- lib/libalpm/alpm.c | 4 ++-- lib/libalpm/db.c | 34 ++++++++++++++++++++-------------- lib/libalpm/deps.c | 12 +++++------- lib/libalpm/error.h | 2 -- lib/libalpm/package.c | 9 +++++---- lib/libalpm/provide.c | 1 - lib/libalpm/util.c | 6 ++---- 7 files changed, 34 insertions(+), 34 deletions(-) diff --git a/lib/libalpm/alpm.c b/lib/libalpm/alpm.c index a0544ec3..b7987e9d 100644 --- a/lib/libalpm/alpm.c +++ b/lib/libalpm/alpm.c @@ -245,7 +245,7 @@ int alpm_db_update(PM_DB *db, char *archive, char *ts) db_free_pkgcache(db); /* remove the old dir */ - _alpm_log(PM_LOG_FLOW2, "removing database %s/%s\n", handle->dbpath, db->treename); + _alpm_log(PM_LOG_FLOW2, "removing database %s/%s", handle->dbpath, db->treename); /* ORE We should db_remove each db entry, and not rmrf the top directory */ _alpm_rmrf(db->path); @@ -259,7 +259,7 @@ int alpm_db_update(PM_DB *db, char *archive, char *ts) /* ORE we should not simply unpack the archive, but better parse it and db_write each entry */ - _alpm_log(PM_LOG_FLOW2, "unpacking %s...\n", archive); + _alpm_log(PM_LOG_FLOW2, "unpacking %s", archive); if(_alpm_unpack(archive, db->path, NULL)) { RET_ERR(PM_ERR_XXX, -1); } diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c index 51354d6b..b29e1f5c 100644 --- a/lib/libalpm/db.c +++ b/lib/libalpm/db.c @@ -27,10 +27,12 @@ #include #include /* pacman */ +#include "log.h" #include "util.h" #include "group.h" #include "cache.h" #include "db.h" +#include "alpm.h" /* Open a database and return a pmdb_t handle */ pmdb_t *db_open(char *root, char *dbpath, char *treename) @@ -258,7 +260,7 @@ int db_read(pmdb_t *db, char *name, unsigned int inforeq, pmpkg_t *info) snprintf(path, PATH_MAX, "%s/%s/desc", db->path, name); fp = fopen(path, "r"); if(fp == NULL) { - fprintf(stderr, "error: %s: %s\n", path, strerror(errno)); + _alpm_log(PM_LOG_ERROR, "%s (%s)", path, strerror(errno)); return(-1); } while(!feof(fp)) { @@ -368,7 +370,7 @@ int db_read(pmdb_t *db, char *name, unsigned int inforeq, pmpkg_t *info) snprintf(path, PATH_MAX, "%s/%s/files", db->path, name); fp = fopen(path, "r"); if(fp == NULL) { - fprintf(stderr, "error: %s: %s\n", path, strerror(errno)); + _alpm_log(PM_LOG_ERROR, "%s (%s)", path, strerror(errno)); return(-1); } while(fgets(line, 256, fp)) { @@ -391,7 +393,7 @@ int db_read(pmdb_t *db, char *name, unsigned int inforeq, pmpkg_t *info) snprintf(path, PATH_MAX, "%s/%s/depends", db->path, name); fp = fopen(path, "r"); if(fp == NULL) { - fprintf(stderr, "error: %s: %s\n", path, strerror(errno)); + _alpm_log(PM_LOG_ERROR, "%s (%s)", path, strerror(errno)); return(-1); } while(!feof(fp)) { @@ -444,8 +446,7 @@ int db_write(pmdb_t *db, pmpkg_t *info, unsigned int inforeq) return(-1); } - snprintf(topdir, PATH_MAX, "%s/%s-%s", db->path, - info->name, info->version); + snprintf(topdir, PATH_MAX, "%s/%s-%s", db->path, info->name, info->version); oldmask = umask(0000); mkdir(topdir, 0755); /* make sure we have a sane umask */ @@ -455,9 +456,9 @@ int db_write(pmdb_t *db, pmpkg_t *info, unsigned int inforeq) if(inforeq & INFRQ_DESC) { snprintf(path, PATH_MAX, "%s/desc", topdir); if((fp = fopen(path, "w")) == NULL) { - perror("db_write"); - umask(oldmask); - return(-1); + /* ORE + perror("db_write");*/ + goto error; } fputs("%NAME%\n", fp); fprintf(fp, "%s\n\n", info->name); @@ -493,9 +494,9 @@ int db_write(pmdb_t *db, pmpkg_t *info, unsigned int inforeq) if(inforeq & INFRQ_FILES) { snprintf(path, PATH_MAX, "%s/files", topdir); if((fp = fopen(path, "w")) == NULL) { - perror("db_write"); - umask(oldmask); - return(-1); + /* ORE + perror("db_write"); */ + goto error; } fputs("%FILES%\n", fp); for(lp = info->files; lp; lp = lp->next) { @@ -514,9 +515,9 @@ int db_write(pmdb_t *db, pmpkg_t *info, unsigned int inforeq) if(inforeq & INFRQ_DEPENDS) { snprintf(path, PATH_MAX, "%s/depends", topdir); if((fp = fopen(path, "w")) == NULL) { - perror("db_write"); - umask(oldmask); - return(-1); + /* ORE + perror("db_write"); */ + goto error; } fputs("%DEPENDS%\n", fp); for(lp = info->depends; lp; lp = lp->next) { @@ -547,6 +548,10 @@ int db_write(pmdb_t *db, pmpkg_t *info, unsigned int inforeq) umask(oldmask); return(0); + +error: + umask(oldmask); + return(-1); } int db_remove(pmdb_t *db, pmpkg_t *info) @@ -572,6 +577,7 @@ int db_remove(pmdb_t *db, pmpkg_t *info) /* INSTALL */ snprintf(file, PATH_MAX, "%s/install", topdir); unlink(file); + /* Package directory */ if(rmdir(topdir) == -1) { return(-1); diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c index 9839014a..eee5bcc5 100644 --- a/lib/libalpm/deps.c +++ b/lib/libalpm/deps.c @@ -67,7 +67,7 @@ PMList *sortbydeps(PMList *targets, int mode) while(change) { change = 0; if(numscans > numtargs) { - _alpm_log(PM_LOG_FLOW2, "warning: possible dependency cycle detected\n"); + _alpm_log(PM_LOG_WARNING, "possible dependency cycle detected"); change = 0; continue; } @@ -378,7 +378,7 @@ PMList *checkdeps(pmdb_t *db, unsigned short op, PMList *packages) pmpkg_t *p = db_scan(db, ((pmpkg_t *)k->data)->name, INFRQ_DESC); if(p == NULL) { /* wtf */ - fprintf(stderr, "data error: %s supposedly provides %s, but it was not found in db\n", + _alpm_log(PM_LOG_ERROR, "%s supposedly provides %s, but it was not found in db", ((pmpkg_t *)k->data)->name, depend.name); for(lp = k; lp; lp = lp->next) { lp->data = NULL; @@ -525,8 +525,7 @@ PMList* removedeps(pmdb_t *db, PMList *targs) } /* see if it was explicitly installed */ if(dep->reason == PM_PKG_REASON_EXPLICIT) { - /* ORE - vprint("excluding %s -- explicitly installed\n", dep->name);*/ + _alpm_log(PM_LOG_FLOW2, "excluding %s -- explicitly installed", dep->name); needed = 1; } /* see if other packages need it */ @@ -576,8 +575,7 @@ int resolvedeps(pmdb_t *local, PMList *databases, pmsync_t *sync, PMList *list, /* XXX: conflicts are now treated specially in the _add and _sync functions */ /*if(miss->type == CONFLICT) { - fprintf(stderr, "error: cannot resolve dependencies for \"%s\":\n", miss->target); - fprintf(stderr, " %s conflicts with %s\n", miss->target, miss->depend.name); + _alpm_log(PM_LOG_ERROR, "cannot resolve dependencies for \"%s\" (it conflict with %s)", miss->target, miss->depend.name); return(1); } else*/ @@ -671,7 +669,7 @@ int resolvedeps(pmdb_t *local, PMList *databases, pmsync_t *sync, PMList *list, /* check pmo_ignorepkg and pmo_s_ignore to make sure we haven't pulled in * something we're not supposed to. */ - int usedep = 1; + int usedep = 1; found = 0; /* ORE for(j = pmo_ignorepkg; j && !found; j = j->next) { diff --git a/lib/libalpm/error.h b/lib/libalpm/error.h index b3f0d850..03fd8f9e 100644 --- a/lib/libalpm/error.h +++ b/lib/libalpm/error.h @@ -21,8 +21,6 @@ #ifndef _ALPM_ERROR_H #define _ALPM_ERROR_H -#include "alpm.h" - #define RET_ERR(err, ret) do { pm_errno = (err); return(ret); } while(0) #endif /* _ALPM_ERROR_H */ diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c index 4e56b763..418fefb1 100644 --- a/lib/libalpm/package.c +++ b/lib/libalpm/package.c @@ -33,6 +33,7 @@ #include "error.h" #include "list.h" #include "package.h" +#include "alpm.h" pmpkg_t *pkg_new() { @@ -118,12 +119,12 @@ static int parse_descfile(char *descfile, pmpkg_t *info, int output) continue; } if(output) { - printf("%s\n", line); + _alpm_log(PM_LOG_DEBUG, "%s", line); } ptr = line; key = strsep(&ptr, "="); if(key == NULL || ptr == NULL) { - fprintf(stderr, "%s: syntax error in description file line %d\n", + _alpm_log(PM_LOG_ERROR, "%s: syntax error in description file line %d", info->name[0] != '\0' ? info->name : "error", linenum); } else { _alpm_strtrim(key); @@ -164,7 +165,7 @@ static int parse_descfile(char *descfile, pmpkg_t *info, int output) } else if(!strcmp(key, "BACKUP")) { info->backup = pm_list_add(info->backup, strdup(ptr)); } else { - fprintf(stderr, "%s: syntax error in description file line %d\n", + _alpm_log(PM_LOG_ERROR, "%s: syntax error in description file line %d", info->name[0] != '\0' ? info->name : "error", linenum); } } @@ -257,7 +258,7 @@ pmpkg_t *pkg_load(char *pkgfile) FREE(str); fclose(fp); if(unlink(fn)) { - _alpm_log(PM_LOG_WARNING, "could not remove tempfile %s\n", fn); + _alpm_log(PM_LOG_WARNING, "could not remove tempfile %s", fn); } FREE(fn); filelist = 1; diff --git a/lib/libalpm/provide.c b/lib/libalpm/provide.c index a472c7af..c7e6c69e 100644 --- a/lib/libalpm/provide.c +++ b/lib/libalpm/provide.c @@ -26,7 +26,6 @@ #include "cache.h" #include "list.h" #include "db.h" -#include "alpm.h" /* return a PMList of packages in "db" that provide "package" */ diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c index 174c3a66..9e689685 100644 --- a/lib/libalpm/util.c +++ b/lib/libalpm/util.c @@ -240,9 +240,7 @@ int _alpm_unpack(char *archive, const char *prefix, const char *fn) while(!th_read(tar)) { if(fn && strcmp(fn, th_get_pathname(tar))) { if(TH_ISREG(tar) && tar_skip_regfile(tar)) { - char errorstr[255]; - snprintf(errorstr, 255, "bad tar archive: %s", archive); - perror(errorstr); + _alpm_log(PM_LOG_ERROR, "bad tar archive: %s", archive); tar_close(tar); return(1); } @@ -250,7 +248,7 @@ int _alpm_unpack(char *archive, const char *prefix, const char *fn) } snprintf(expath, PATH_MAX, "%s/%s", prefix, th_get_pathname(tar)); if(tar_extract_file(tar, expath)) { - fprintf(stderr, "could not extract %s: %s\n", th_get_pathname(tar), strerror(errno)); + _alpm_log(PM_LOG_ERROR, "could not extract %s (%s)", th_get_pathname(tar), strerror(errno)); } if(fn) break; } -- cgit v1.2.3-70-g09d2