libalpm error cleanup, step 1

Remove unused error codes, begin refactoring some of the others.

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2008-04-06 20:09:27 -05:00
parent 4004bf9caf
commit e4a4cf7ce5
6 changed files with 22 additions and 29 deletions

View File

@ -695,7 +695,7 @@ static int commit_single_pkg(pmpkg_t *newpkg, int pkg_current, int pkg_count,
_alpm_log(PM_LOG_DEBUG, "extracting files\n");
if ((archive = archive_read_new()) == NULL) {
RET_ERR(PM_ERR_LIBARCHIVE_ERROR, -1);
RET_ERR(PM_ERR_LIBARCHIVE, -1);
}
archive_read_support_compression_all(archive);

View File

@ -433,12 +433,6 @@ enum _pmerrno_t {
PM_ERR_DB_REMOVE,
/* Servers */
PM_ERR_SERVER_BAD_URL,
/* Configuration */
PM_ERR_OPT_LOGFILE,
PM_ERR_OPT_DBPATH,
PM_ERR_OPT_LOCALDB,
PM_ERR_OPT_SYNCDB,
PM_ERR_OPT_USESYSLOG,
/* Transactions */
PM_ERR_TRANS_NOT_NULL,
PM_ERR_TRANS_NULL,
@ -470,14 +464,16 @@ enum _pmerrno_t {
/* Misc */
PM_ERR_USER_ABORT,
PM_ERR_INTERNAL_ERROR,
PM_ERR_LIBARCHIVE_ERROR,
PM_ERR_DB_SYNC,
PM_ERR_RETRIEVE,
PM_ERR_PKG_HOLD,
PM_ERR_INVALID_REGEX,
/* Downloading */
PM_ERR_CONNECT_FAILED,
PM_ERR_FORK_FAILED
PM_ERR_FORK_FAILED,
/* External library errors */
PM_ERR_LIBARCHIVE,
PM_ERR_LIBDOWNLOAD
};
extern enum _pmerrno_t pm_errno;

View File

@ -1,10 +1,7 @@
/*
* error.c
*
* Copyright (c) 2002-2007 by Judd Vinet <jvinet@zeroflux.org>
* Copyright (c) 2005 by Aurelien Foret <orelien@chez.com>
* Copyright (c) 2005 by Christian Hamar <krics@linuxforum.hu>
* Copyright (c) 2006 by Miklos Vajna <vmiklos@frugalware.org>
* Copyright (c) 2002-2008 by Judd Vinet <jvinet@zeroflux.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -22,12 +19,13 @@
#include "config.h"
#include <download.h> /* downloadLastErrString */
/* libalpm */
#include "error.h"
#include "util.h"
#include "alpm.h"
/* TODO does this really need a file all on its own? */
const char SYMEXPORT *alpm_strerrorlast(void)
{
return alpm_strerror(pm_errno);
@ -74,13 +72,6 @@ const char SYMEXPORT *alpm_strerror(int err)
/* Servers */
case PM_ERR_SERVER_BAD_URL:
return _("invalid url for server");
/* Configuration */
case PM_ERR_OPT_LOGFILE:
case PM_ERR_OPT_DBPATH:
case PM_ERR_OPT_LOCALDB:
case PM_ERR_OPT_SYNCDB:
case PM_ERR_OPT_USESYSLOG:
return _("could not set parameter");
/* Transactions */
case PM_ERR_TRANS_NOT_NULL:
return _("transaction already initialized");
@ -137,8 +128,6 @@ const char SYMEXPORT *alpm_strerror(int err)
return _("user aborted the operation");
case PM_ERR_INTERNAL_ERROR:
return _("internal error");
case PM_ERR_LIBARCHIVE_ERROR:
return _("libarchive error");
case PM_ERR_PKG_HOLD:
/* TODO wow this is not descriptive at all... what does this mean? */
return _("not confirmed");
@ -147,6 +136,14 @@ const char SYMEXPORT *alpm_strerror(int err)
/* Downloading */
case PM_ERR_CONNECT_FAILED:
return _("connection to remote host failed");
/* Errors from external libraries- our own wrapper error */
case PM_ERR_LIBARCHIVE:
/* it would be nice to use archive_error_string() here, but that
* requires the archive struct, so we can't. Just use a generic
* error string instead. */
return _("libarchive error");
case PM_ERR_LIBDOWNLOAD:
return downloadLastErrString;
/* Unknown error! */
default:
return _("unexpected error");

View File

@ -509,7 +509,7 @@ void SYMEXPORT *alpm_pkg_changelog_open(pmpkg_t *pkg)
int ret = ARCHIVE_OK;
if((archive = archive_read_new()) == NULL) {
RET_ERR(PM_ERR_LIBARCHIVE_ERROR, NULL);
RET_ERR(PM_ERR_LIBARCHIVE, NULL);
}
archive_read_support_compression_all(archive);
@ -995,7 +995,7 @@ pmpkg_t *_alpm_pkg_load(const char *pkgfile, unsigned short full)
}
if((archive = archive_read_new()) == NULL) {
RET_ERR(PM_ERR_LIBARCHIVE_ERROR, NULL);
RET_ERR(PM_ERR_LIBARCHIVE, NULL);
}
archive_read_support_compression_all(archive);
@ -1052,7 +1052,7 @@ pmpkg_t *_alpm_pkg_load(const char *pkgfile, unsigned short full)
if(archive_read_data_skip(archive)) {
_alpm_log(PM_LOG_ERROR, _("error while reading package %s: %s\n"),
pkgfile, archive_error_string(archive));
pm_errno = PM_ERR_LIBARCHIVE_ERROR;
pm_errno = PM_ERR_LIBARCHIVE;
goto error;
}
@ -1065,7 +1065,7 @@ pmpkg_t *_alpm_pkg_load(const char *pkgfile, unsigned short full)
if(ret != ARCHIVE_EOF && ret != ARCHIVE_OK) { /* An error occured */
_alpm_log(PM_LOG_ERROR, _("error while reading package %s: %s\n"),
pkgfile, archive_error_string(archive));
pm_errno = PM_ERR_LIBARCHIVE_ERROR;
pm_errno = PM_ERR_LIBARCHIVE;
goto error;
}

View File

@ -382,7 +382,7 @@ int _alpm_unpack(const char *archive, const char *prefix, const char *fn)
ALPM_LOG_FUNC;
if((_archive = archive_read_new()) == NULL)
RET_ERR(PM_ERR_LIBARCHIVE_ERROR, -1);
RET_ERR(PM_ERR_LIBARCHIVE, -1);
archive_read_support_compression_all(_archive);
archive_read_support_format_all(_archive);

View File

@ -63,7 +63,7 @@ int main(int argc, char **argv)
case PM_ERR_PKG_OPEN:
printf("Cannot open the given file.\n");
break;
case PM_ERR_LIBARCHIVE_ERROR:
case PM_ERR_LIBARCHIVE:
case PM_ERR_PKG_INVALID:
printf("Package is invalid.\n");
break;