summaryrefslogtreecommitdiff
path: root/lib/libalpm
diff options
context:
space:
mode:
authorAurelien Foret <aurelien@archlinux.org>2006-01-27 19:12:15 +0000
committerAurelien Foret <aurelien@archlinux.org>2006-01-27 19:12:15 +0000
commitc3ffe4367a1e23ec25a15f21e82b0a256685818c (patch)
treecc062c535b183d1714da4fb5fa73ead16b33f022 /lib/libalpm
parent299d708b0d6c172e0fcb5620246866f5900e7e6a (diff)
downloadpacman-c3ffe4367a1e23ec25a15f21e82b0a256685818c.tar.xz
cleaned up db_write error cases handling
Diffstat (limited to 'lib/libalpm')
-rw-r--r--lib/libalpm/db.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c
index c40e6a7e..1eb1ecf1 100644
--- a/lib/libalpm/db.c
+++ b/lib/libalpm/db.c
@@ -462,6 +462,7 @@ int db_write(pmdb_t *db, pmpkg_t *info, unsigned int inforeq)
char path[PATH_MAX];
mode_t oldmask;
PMList *lp = NULL;
+ int retval = 0;
if(db == NULL || info == NULL) {
return(-1);
@@ -478,7 +479,8 @@ int db_write(pmdb_t *db, pmpkg_t *info, unsigned int inforeq)
snprintf(path, PATH_MAX, "%s/desc", topdir);
if((fp = fopen(path, "w")) == NULL) {
_alpm_log(PM_LOG_ERROR, "db_write: could not open file %s/desc", db->treename);
- goto error;
+ retval = 1;
+ goto cleanup;
}
fputs("%NAME%\n", fp);
fprintf(fp, "%s\n\n", info->name);
@@ -511,6 +513,7 @@ int db_write(pmdb_t *db, pmpkg_t *info, unsigned int inforeq)
fputs("%REASON%\n", fp);
fprintf(fp, "%d\n\n", info->reason);
fclose(fp);
+ fp = NULL;
}
/* FILES */
@@ -518,7 +521,8 @@ int db_write(pmdb_t *db, pmpkg_t *info, unsigned int inforeq)
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);
- goto error;
+ retval = -1;
+ goto cleanup;
}
fputs("%FILES%\n", fp);
for(lp = info->files; lp; lp = lp->next) {
@@ -531,6 +535,7 @@ int db_write(pmdb_t *db, pmpkg_t *info, unsigned int inforeq)
}
fprintf(fp, "\n");
fclose(fp);
+ fp = NULL;
}
/* DEPENDS */
@@ -538,7 +543,8 @@ int db_write(pmdb_t *db, pmpkg_t *info, unsigned int inforeq)
snprintf(path, PATH_MAX, "%s/depends", topdir);
if((fp = fopen(path, "w")) == NULL) {
_alpm_log(PM_LOG_ERROR, "db_write: could not open file %s/depends", db->treename);
- goto error;
+ retval = -1;
+ goto cleanup;
}
fputs("%DEPENDS%\n", fp);
for(lp = info->depends; lp; lp = lp->next) {
@@ -561,18 +567,20 @@ int db_write(pmdb_t *db, pmpkg_t *info, unsigned int inforeq)
}
fprintf(fp, "\n");
fclose(fp);
+ fp = NULL;
}
/* INSTALL */
/* nothing needed here (script is automatically extracted) */
+cleanup:
umask(oldmask);
- return(0);
+ if(fp) {
+ fclose(fp);
+ }
-error:
- umask(oldmask);
- return(-1);
+ return(retval);
}
int db_remove(pmdb_t *db, pmpkg_t *info)