Linux Archive

Linux Archive (http://www.linux-archive.org/)
-   ArchLinux Pacman Development (http://www.linux-archive.org/archlinux-pacman-development/)
-   -   Extract a write_deps function from local database writing (http://www.linux-archive.org/archlinux-pacman-development/642787-extract-write_deps-function-local-database-writing.html)

Dan McGee 03-09-2012 07:11 PM

Extract a write_deps function from local database writing
 
This reduces a lot of code duplication in the write function, which
cleans it up a bit.

Signed-off-by: Dan McGee <dan@archlinux.org>
---
lib/libalpm/be_local.c | 67 ++++++++++++++++--------------------------------
1 file changed, 22 insertions(+), 45 deletions(-)

diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c
index 16c794e..7cce022 100644
--- a/lib/libalpm/be_local.c
+++ b/lib/libalpm/be_local.c
@@ -749,6 +749,22 @@ int _alpm_local_db_prepare(alpm_db_t *db, alpm_pkg_t *info)
return retval;
}

+void write_deps(FILE *fp, const char *header, alpm_list_t *deplist)
+{
+ alpm_list_t *lp;
+ if(!deplist) {
+ return;
+ }
+ fputs(header, fp);
+ fputc('
', fp);
+ for(lp = deplist; lp; lp = lp->next) {
+ char *depstring = alpm_dep_compute_string(lp->data);
+ fprintf(fp, "%s
", depstring);
+ free(depstring);
+ }
+ fputc('
', fp);
+}
+
int _alpm_local_db_write(alpm_db_t *db, alpm_pkg_t *info, alpm_dbinfrq_t inforeq)
{
FILE *fp = NULL;
@@ -790,15 +806,6 @@ int _alpm_local_db_write(alpm_db_t *db, alpm_pkg_t *info, alpm_dbinfrq_t inforeq
}
fprintf(fp, "
");
}
- if(info->replaces) {
- fputs("%REPLACES%
", fp);
- for(lp = info->replaces; lp; lp = lp->next) {
- char *depstring = alpm_dep_compute_string(lp->data);
- fprintf(fp, "%s
", depstring);
- free(depstring);
- }
- fprintf(fp, "
");
- }
if(info->url) {
fprintf(fp, "%%URL%%
"
"%s

", info->url);
@@ -851,42 +858,12 @@ int _alpm_local_db_write(alpm_db_t *db, alpm_pkg_t *info, alpm_dbinfrq_t inforeq
}
fprintf(fp, "
");
}
- if(info->depends) {
- fputs("%DEPENDS%
", fp);
- for(lp = info->depends; lp; lp = lp->next) {
- char *depstring = alpm_dep_compute_string(lp->data);
- fprintf(fp, "%s
", depstring);
- free(depstring);
- }
- fprintf(fp, "
");
- }
- if(info->optdepends) {
- fputs("%OPTDEPENDS%
", fp);
- for(lp = info->optdepends; lp; lp = lp->next) {
- char *optstring = alpm_dep_compute_string(lp->data);
- fprintf(fp, "%s
", optstring);
- free(optstring);
- }
- fprintf(fp, "
");
- }
- if(info->conflicts) {
- fputs("%CONFLICTS%
", fp);
- for(lp = info->conflicts; lp; lp = lp->next) {
- char *depstring = alpm_dep_compute_string(lp->data);
- fprintf(fp, "%s
", depstring);
- free(depstring);
- }
- fprintf(fp, "
");
- }
- if(info->provides) {
- fputs("%PROVIDES%
", fp);
- for(lp = info->provides; lp; lp = lp->next) {
- char *depstring = alpm_dep_compute_string(lp->data);
- fprintf(fp, "%s
", depstring);
- free(depstring);
- }
- fprintf(fp, "
");
- }
+
+ write_deps(fp, "%REPLACES%", info->replaces);
+ write_deps(fp, "%DEPENDS%", info->depends);
+ write_deps(fp, "%OPTDEPENDS%", info->optdepends);
+ write_deps(fp, "%CONFLICTS%", info->conflicts);
+ write_deps(fp, "%PROVIDES%", info->provides);

fclose(fp);
fp = NULL;
--
1.7.9.3


All times are GMT. The time now is 12:48 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.