summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAaron Griffin <aaron@archlinux.org>2007-01-24 08:51:50 +0000
committerAaron Griffin <aaron@archlinux.org>2007-01-24 08:51:50 +0000
commit170d63190a3cfb0c12ee9ddfe07b21f20825bd6f (patch)
treec1cad21e75daf695f61f83ca1072d0a52343a673 /lib
parent1b61cc8c69025ddd394401a506b21f16df5d4e6d (diff)
downloadpacman-170d63190a3cfb0c12ee9ddfe07b21f20825bd6f.tar.xz
* Shuffled some of the alpm_list free funtions - still not perfect, but better
* Added alpm_list_remove_node for single list node removal * Proper error checking/output for failed db_read/db_write (missing files) * Invalid packages (missing files) are now removed from the package cache * -Qs and -Ss output now look the same * config.rpath causes errors on one machine I had, so I added it to CVS * Fixed a "clobbered memory" issue when installing groups - only the outer list should be free'd, not the contained data
Diffstat (limited to 'lib')
-rw-r--r--lib/libalpm/alpm_list.c55
-rw-r--r--lib/libalpm/alpm_list.h13
-rw-r--r--lib/libalpm/be_files.c23
-rw-r--r--lib/libalpm/cache.c9
-rw-r--r--lib/libalpm/package.c3
5 files changed, 68 insertions, 35 deletions
diff --git a/lib/libalpm/alpm_list.c b/lib/libalpm/alpm_list.c
index 26fcb3dc..edb2e8e5 100644
--- a/lib/libalpm/alpm_list.c
+++ b/lib/libalpm/alpm_list.c
@@ -49,33 +49,37 @@ alpm_list_t *alpm_list_new()
return(list);
}
-/** Free a list structure and possibly the internal data as well
+/** Free a list, but not the contained data
* @param list the list to free
- * @param fn a free function for the internal data, or NULL for none
*/
-void alpm_list_free(alpm_list_t *list, alpm_list_fn_free fn)
+void alpm_list_free(alpm_list_t *list)
{
alpm_list_t *it = list;
while(it) {
- alpm_list_t *ptr = it->next;
- if(fn && it->data) {
- fn(it->data);
- }
- FREE(it);
- it = ptr;
+ alpm_list_t *tmp = it->next;
+ free(it);
+ it = tmp;
}
}
-/** Free the outer list, but not the contained data
- * A minor simplification of alpm_list_free
+/** Free the internal data of a list structure
* @param list the list to free
+ * @param fn a free function for the internal data
*/
-void alpm_list_free_outer(alpm_list_t *list)
+void alpm_list_free_inner(alpm_list_t *list, alpm_list_fn_free fn)
{
- alpm_list_free(list, NULL);
+ alpm_list_t *it = list;
+
+ while(it) {
+ if(fn && it->data) {
+ fn(it->data);
+ }
+ it = it->next;
+ }
}
+
/* Mutators */
/** Add a new item to the list
@@ -271,6 +275,31 @@ alpm_list_t *alpm_list_remove(alpm_list_t *haystack, void *needle, alpm_list_fn_
return(haystack);
}
+/** Remove the passed in node from the list that it is a part of
+ * @note this DOES NOT free the node
+ * @param node the list node we're removing
+ * @return the node which took the place of this one
+ */
+alpm_list_t *alpm_list_remove_node(alpm_list_t *node)
+{
+ if(!node) return(NULL);
+
+ alpm_list_t *ret = NULL;
+
+ if(node->prev) {
+ node->prev->next = node->next;
+ ret = node->prev;
+ node->prev = NULL;
+ }
+ if(node->next) {
+ node->next->prev = node->prev;
+ ret = node->next;
+ node->next = NULL;
+ }
+
+ return(ret);
+}
+
/** Create a new list without any duplicates
* @note DOES NOT copy data members
* @param list the list to copy
diff --git a/lib/libalpm/alpm_list.h b/lib/libalpm/alpm_list.h
index df19c9e9..5bad4dc2 100644
--- a/lib/libalpm/alpm_list.h
+++ b/lib/libalpm/alpm_list.h
@@ -30,18 +30,18 @@ struct __alpm_list_t {
struct __alpm_list_t *next;
};
-/* TODO we should do away with these... they're messy */
-#define _FREELIST(p, f) do { if(p) { alpm_list_free(p, f); p = NULL; } } while(0)
-#define FREELIST(p) _FREELIST(p, free)
-#define FREELISTPTR(p) _FREELIST(p, NULL)
+/* TODO we should do away with these... they're messy*/
+#define _FREELIST(p, f) do { alpm_list_free_inner(p, f); alpm_list_free(p); p = NULL; } while(0)
+#define FREELIST(p) _FREELIST(p, free)
+#define FREELISTPTR(p) do { alpm_list_free(p); p = NULL; } while(0)
typedef void (*alpm_list_fn_free)(void *); /* item deallocation callback */
typedef int (*alpm_list_fn_cmp)(const void *, const void *); /* item comparison callback */
/* allocation */
alpm_list_t *alpm_list_new(void);
-void alpm_list_free(alpm_list_t *list, alpm_list_fn_free fn);
-void alpm_list_free_outer(alpm_list_t *list);
+void alpm_list_free(alpm_list_t *list);
+void alpm_list_free_inner(alpm_list_t *list, alpm_list_fn_free fn);
/* item mutators */
alpm_list_t *alpm_list_add(alpm_list_t *list, void *data);
@@ -49,6 +49,7 @@ alpm_list_t *alpm_list_add_sorted(alpm_list_t *list, void *data, alpm_list_fn_cm
alpm_list_t* alpm_list_mmerge(alpm_list_t *left, alpm_list_t *right, alpm_list_fn_cmp fn);
alpm_list_t* alpm_list_msort(alpm_list_t *list, int n, alpm_list_fn_cmp fn);
alpm_list_t *alpm_list_remove(alpm_list_t *haystack, void *needle, alpm_list_fn_cmp fn, void **data);
+alpm_list_t *alpm_list_remove_node(alpm_list_t *node);
alpm_list_t *alpm_list_remove_dupes(alpm_list_t *list);
alpm_list_t *alpm_list_strdup(alpm_list_t *list);
alpm_list_t *alpm_list_reverse(alpm_list_t *list);
diff --git a/lib/libalpm/be_files.c b/lib/libalpm/be_files.c
index 19e2bf1f..65a5fc71 100644
--- a/lib/libalpm/be_files.c
+++ b/lib/libalpm/be_files.c
@@ -217,9 +217,8 @@ int _alpm_db_read(pmdb_t *db, unsigned int inforeq, pmpkg_t *info)
/* DESC */
if(inforeq & INFRQ_DESC) {
snprintf(path, PATH_MAX, "%s/%s-%s/desc", db->path, info->name, info->version);
- fp = fopen(path, "r");
- if(fp == NULL) {
- _alpm_log(PM_LOG_DEBUG, "%s (%s)", path, strerror(errno));
+ if((fp = fopen(path, "r")) == NULL) {
+ _alpm_log(PM_LOG_ERROR, _("could not open file %s: %s"), path, strerror(errno));
goto error;
}
while(!feof(fp)) {
@@ -362,9 +361,8 @@ int _alpm_db_read(pmdb_t *db, unsigned int inforeq, pmpkg_t *info)
/* FILES */
if(inforeq & INFRQ_FILES) {
snprintf(path, PATH_MAX, "%s/%s-%s/files", db->path, info->name, info->version);
- fp = fopen(path, "r");
- if(fp == NULL) {
- _alpm_log(PM_LOG_WARNING, "%s (%s)", path, strerror(errno));
+ if((fp = fopen(path, "r")) == NULL) {
+ _alpm_log(PM_LOG_ERROR, _("could not open file %s: %s"), path, strerror(errno));
goto error;
}
while(fgets(line, 256, fp)) {
@@ -386,9 +384,8 @@ int _alpm_db_read(pmdb_t *db, unsigned int inforeq, pmpkg_t *info)
/* DEPENDS */
if(inforeq & INFRQ_DEPENDS) {
snprintf(path, PATH_MAX, "%s/%s-%s/depends", db->path, info->name, info->version);
- fp = fopen(path, "r");
- if(fp == NULL) {
- _alpm_log(PM_LOG_WARNING, "%s (%s)", path, strerror(errno));
+ if((fp = fopen(path, "r")) == NULL) {
+ _alpm_log(PM_LOG_ERROR, _("could not open file %s: %s"), path, strerror(errno));
goto error;
}
while(!feof(fp)) {
@@ -474,8 +471,8 @@ int _alpm_db_write(pmdb_t *db, pmpkg_t *info, unsigned int inforeq)
_alpm_log(PM_LOG_DEBUG, _("writing %s-%s DESC information back to db"), info->name, info->version);
snprintf(path, PATH_MAX, "%s/%s-%s/desc", db->path, info->name, info->version);
if((fp = fopen(path, "w")) == NULL) {
- _alpm_log(PM_LOG_ERROR, _("db_write: could not open file %s/desc"), db->treename);
- retval = 1;
+ _alpm_log(PM_LOG_ERROR, _("could not open file %s: %s"), path, strerror(errno));
+ retval = -1;
goto cleanup;
}
fprintf(fp, "%%NAME%%\n%s\n\n"
@@ -560,7 +557,7 @@ int _alpm_db_write(pmdb_t *db, pmpkg_t *info, unsigned int inforeq)
_alpm_log(PM_LOG_DEBUG, _("writing %s-%s FILES information back to db"), info->name, info->version);
snprintf(path, PATH_MAX, "%s/%s-%s/files", db->path, info->name, info->version);
if((fp = fopen(path, "w")) == NULL) {
- _alpm_log(PM_LOG_ERROR, _("db_write: could not open file %s/files"), db->treename);
+ _alpm_log(PM_LOG_ERROR, _("could not open file %s: %s"), path, strerror(errno));
retval = -1;
goto cleanup;
}
@@ -587,7 +584,7 @@ int _alpm_db_write(pmdb_t *db, pmpkg_t *info, unsigned int inforeq)
_alpm_log(PM_LOG_DEBUG, _("writing %s-%s DEPENDS information back to db"), info->name, info->version);
snprintf(path, PATH_MAX, "%s/%s-%s/depends", db->path, info->name, info->version);
if((fp = fopen(path, "w")) == NULL) {
- _alpm_log(PM_LOG_ERROR, _("db_write: could not open file %s/depends"), db->treename);
+ _alpm_log(PM_LOG_ERROR, _("could not open file %s: %s"), path, strerror(errno));
retval = -1;
goto cleanup;
}
diff --git a/lib/libalpm/cache.c b/lib/libalpm/cache.c
index d03cf203..81737d3c 100644
--- a/lib/libalpm/cache.c
+++ b/lib/libalpm/cache.c
@@ -112,8 +112,13 @@ int _alpm_db_ensure_pkgcache(pmdb_t *db, pmdbinfrq_t infolevel)
for(p = db->pkgcache; p; p = p->next) {
pmpkg_t *pkg = (pmpkg_t *)p->data;
if(infolevel != INFRQ_NONE && !(pkg->infolevel & infolevel)) {
- _alpm_db_read(db, infolevel, pkg);
- reloaded = 1;
+ if(_alpm_db_read(db, infolevel, pkg) == -1) {
+ _alpm_log(PM_LOG_ERROR, _("failed to read package '%s-%s', removing from package cache"),
+ pkg->name, pkg->version);
+ p = alpm_list_remove_node(p);
+ } else {
+ reloaded = 1;
+ }
}
}
if(reloaded) {
diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
index f35797be..beda20a4 100644
--- a/lib/libalpm/package.c
+++ b/lib/libalpm/package.c
@@ -29,6 +29,7 @@
#include <string.h>
#include <libintl.h>
#include <locale.h>
+#include <errno.h>
/* pacman */
#include "log.h"
#include "util.h"
@@ -136,7 +137,7 @@ static int parse_descfile(char *descfile, pmpkg_t *info, int output)
int linenum = 0;
if((fp = fopen(descfile, "r")) == NULL) {
- _alpm_log(PM_LOG_ERROR, _("could not open file %s"), descfile);
+ _alpm_log(PM_LOG_ERROR, _("could not open file %s: %s"), descfile, strerror(errno));
return(-1);
}