improved logs (use _alpm_log instead of fprintf)

This commit is contained in:
Aurelien Foret 2005-03-28 08:21:17 +00:00
parent 9c17eb88f0
commit 56917dc304
7 changed files with 34 additions and 34 deletions

View file

@ -245,7 +245,7 @@ int alpm_db_update(PM_DB *db, char *archive, char *ts)
db_free_pkgcache(db); db_free_pkgcache(db);
/* remove the old dir */ /* 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 /* ORE
We should db_remove each db entry, and not rmrf the top directory */ We should db_remove each db entry, and not rmrf the top directory */
_alpm_rmrf(db->path); _alpm_rmrf(db->path);
@ -259,7 +259,7 @@ int alpm_db_update(PM_DB *db, char *archive, char *ts)
/* ORE /* ORE
we should not simply unpack the archive, but better parse it and we should not simply unpack the archive, but better parse it and
db_write each entry */ 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)) { if(_alpm_unpack(archive, db->path, NULL)) {
RET_ERR(PM_ERR_XXX, -1); RET_ERR(PM_ERR_XXX, -1);
} }

View file

@ -27,10 +27,12 @@
#include <string.h> #include <string.h>
#include <sys/stat.h> #include <sys/stat.h>
/* pacman */ /* pacman */
#include "log.h"
#include "util.h" #include "util.h"
#include "group.h" #include "group.h"
#include "cache.h" #include "cache.h"
#include "db.h" #include "db.h"
#include "alpm.h"
/* Open a database and return a pmdb_t handle */ /* Open a database and return a pmdb_t handle */
pmdb_t *db_open(char *root, char *dbpath, char *treename) 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); snprintf(path, PATH_MAX, "%s/%s/desc", db->path, name);
fp = fopen(path, "r"); fp = fopen(path, "r");
if(fp == NULL) { if(fp == NULL) {
fprintf(stderr, "error: %s: %s\n", path, strerror(errno)); _alpm_log(PM_LOG_ERROR, "%s (%s)", path, strerror(errno));
return(-1); return(-1);
} }
while(!feof(fp)) { 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); snprintf(path, PATH_MAX, "%s/%s/files", db->path, name);
fp = fopen(path, "r"); fp = fopen(path, "r");
if(fp == NULL) { if(fp == NULL) {
fprintf(stderr, "error: %s: %s\n", path, strerror(errno)); _alpm_log(PM_LOG_ERROR, "%s (%s)", path, strerror(errno));
return(-1); return(-1);
} }
while(fgets(line, 256, fp)) { 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); snprintf(path, PATH_MAX, "%s/%s/depends", db->path, name);
fp = fopen(path, "r"); fp = fopen(path, "r");
if(fp == NULL) { if(fp == NULL) {
fprintf(stderr, "error: %s: %s\n", path, strerror(errno)); _alpm_log(PM_LOG_ERROR, "%s (%s)", path, strerror(errno));
return(-1); return(-1);
} }
while(!feof(fp)) { while(!feof(fp)) {
@ -444,8 +446,7 @@ int db_write(pmdb_t *db, pmpkg_t *info, unsigned int inforeq)
return(-1); return(-1);
} }
snprintf(topdir, PATH_MAX, "%s/%s-%s", db->path, snprintf(topdir, PATH_MAX, "%s/%s-%s", db->path, info->name, info->version);
info->name, info->version);
oldmask = umask(0000); oldmask = umask(0000);
mkdir(topdir, 0755); mkdir(topdir, 0755);
/* make sure we have a sane umask */ /* 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) { if(inforeq & INFRQ_DESC) {
snprintf(path, PATH_MAX, "%s/desc", topdir); snprintf(path, PATH_MAX, "%s/desc", topdir);
if((fp = fopen(path, "w")) == NULL) { if((fp = fopen(path, "w")) == NULL) {
perror("db_write"); /* ORE
umask(oldmask); perror("db_write");*/
return(-1); goto error;
} }
fputs("%NAME%\n", fp); fputs("%NAME%\n", fp);
fprintf(fp, "%s\n\n", info->name); 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) { if(inforeq & INFRQ_FILES) {
snprintf(path, PATH_MAX, "%s/files", topdir); snprintf(path, PATH_MAX, "%s/files", topdir);
if((fp = fopen(path, "w")) == NULL) { if((fp = fopen(path, "w")) == NULL) {
perror("db_write"); /* ORE
umask(oldmask); perror("db_write"); */
return(-1); goto error;
} }
fputs("%FILES%\n", fp); fputs("%FILES%\n", fp);
for(lp = info->files; lp; lp = lp->next) { 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) { if(inforeq & INFRQ_DEPENDS) {
snprintf(path, PATH_MAX, "%s/depends", topdir); snprintf(path, PATH_MAX, "%s/depends", topdir);
if((fp = fopen(path, "w")) == NULL) { if((fp = fopen(path, "w")) == NULL) {
perror("db_write"); /* ORE
umask(oldmask); perror("db_write"); */
return(-1); goto error;
} }
fputs("%DEPENDS%\n", fp); fputs("%DEPENDS%\n", fp);
for(lp = info->depends; lp; lp = lp->next) { 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); umask(oldmask);
return(0); return(0);
error:
umask(oldmask);
return(-1);
} }
int db_remove(pmdb_t *db, pmpkg_t *info) int db_remove(pmdb_t *db, pmpkg_t *info)
@ -572,6 +577,7 @@ int db_remove(pmdb_t *db, pmpkg_t *info)
/* INSTALL */ /* INSTALL */
snprintf(file, PATH_MAX, "%s/install", topdir); snprintf(file, PATH_MAX, "%s/install", topdir);
unlink(file); unlink(file);
/* Package directory */ /* Package directory */
if(rmdir(topdir) == -1) { if(rmdir(topdir) == -1) {
return(-1); return(-1);

View file

@ -67,7 +67,7 @@ PMList *sortbydeps(PMList *targets, int mode)
while(change) { while(change) {
change = 0; change = 0;
if(numscans > numtargs) { 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; change = 0;
continue; 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); pmpkg_t *p = db_scan(db, ((pmpkg_t *)k->data)->name, INFRQ_DESC);
if(p == NULL) { if(p == NULL) {
/* wtf */ /* 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); ((pmpkg_t *)k->data)->name, depend.name);
for(lp = k; lp; lp = lp->next) { for(lp = k; lp; lp = lp->next) {
lp->data = NULL; lp->data = NULL;
@ -525,8 +525,7 @@ PMList* removedeps(pmdb_t *db, PMList *targs)
} }
/* see if it was explicitly installed */ /* see if it was explicitly installed */
if(dep->reason == PM_PKG_REASON_EXPLICIT) { if(dep->reason == PM_PKG_REASON_EXPLICIT) {
/* ORE _alpm_log(PM_LOG_FLOW2, "excluding %s -- explicitly installed", dep->name);
vprint("excluding %s -- explicitly installed\n", dep->name);*/
needed = 1; needed = 1;
} }
/* see if other packages need it */ /* 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 */ /* XXX: conflicts are now treated specially in the _add and _sync functions */
/*if(miss->type == CONFLICT) { /*if(miss->type == CONFLICT) {
fprintf(stderr, "error: cannot resolve dependencies for \"%s\":\n", miss->target); _alpm_log(PM_LOG_ERROR, "cannot resolve dependencies for \"%s\" (it conflict with %s)", miss->target, miss->depend.name);
fprintf(stderr, " %s conflicts with %s\n", miss->target, miss->depend.name);
return(1); return(1);
} else*/ } else*/

View file

@ -21,8 +21,6 @@
#ifndef _ALPM_ERROR_H #ifndef _ALPM_ERROR_H
#define _ALPM_ERROR_H #define _ALPM_ERROR_H
#include "alpm.h"
#define RET_ERR(err, ret) do { pm_errno = (err); return(ret); } while(0) #define RET_ERR(err, ret) do { pm_errno = (err); return(ret); } while(0)
#endif /* _ALPM_ERROR_H */ #endif /* _ALPM_ERROR_H */

View file

@ -33,6 +33,7 @@
#include "error.h" #include "error.h"
#include "list.h" #include "list.h"
#include "package.h" #include "package.h"
#include "alpm.h"
pmpkg_t *pkg_new() pmpkg_t *pkg_new()
{ {
@ -118,12 +119,12 @@ static int parse_descfile(char *descfile, pmpkg_t *info, int output)
continue; continue;
} }
if(output) { if(output) {
printf("%s\n", line); _alpm_log(PM_LOG_DEBUG, "%s", line);
} }
ptr = line; ptr = line;
key = strsep(&ptr, "="); key = strsep(&ptr, "=");
if(key == NULL || ptr == NULL) { 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); info->name[0] != '\0' ? info->name : "error", linenum);
} else { } else {
_alpm_strtrim(key); _alpm_strtrim(key);
@ -164,7 +165,7 @@ static int parse_descfile(char *descfile, pmpkg_t *info, int output)
} else if(!strcmp(key, "BACKUP")) { } else if(!strcmp(key, "BACKUP")) {
info->backup = pm_list_add(info->backup, strdup(ptr)); info->backup = pm_list_add(info->backup, strdup(ptr));
} else { } 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); info->name[0] != '\0' ? info->name : "error", linenum);
} }
} }
@ -257,7 +258,7 @@ pmpkg_t *pkg_load(char *pkgfile)
FREE(str); FREE(str);
fclose(fp); fclose(fp);
if(unlink(fn)) { 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); FREE(fn);
filelist = 1; filelist = 1;

View file

@ -26,7 +26,6 @@
#include "cache.h" #include "cache.h"
#include "list.h" #include "list.h"
#include "db.h" #include "db.h"
#include "alpm.h"
/* return a PMList of packages in "db" that provide "package" /* return a PMList of packages in "db" that provide "package"
*/ */

View file

@ -240,9 +240,7 @@ int _alpm_unpack(char *archive, const char *prefix, const char *fn)
while(!th_read(tar)) { while(!th_read(tar)) {
if(fn && strcmp(fn, th_get_pathname(tar))) { if(fn && strcmp(fn, th_get_pathname(tar))) {
if(TH_ISREG(tar) && tar_skip_regfile(tar)) { if(TH_ISREG(tar) && tar_skip_regfile(tar)) {
char errorstr[255]; _alpm_log(PM_LOG_ERROR, "bad tar archive: %s", archive);
snprintf(errorstr, 255, "bad tar archive: %s", archive);
perror(errorstr);
tar_close(tar); tar_close(tar);
return(1); 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)); snprintf(expath, PATH_MAX, "%s/%s", prefix, th_get_pathname(tar));
if(tar_extract_file(tar, expath)) { 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; if(fn) break;
} }