1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-11-10 11:35:00 -05:00

db_write: only write non-empty fields to database

This commit is contained in:
Aurelien Foret 2006-02-11 07:53:36 +00:00
parent de000682e6
commit 3a82992b59

View File

@ -482,36 +482,54 @@ int db_write(pmdb_t *db, pmpkg_t *info, unsigned int inforeq)
retval = 1; retval = 1;
goto cleanup; goto cleanup;
} }
fputs("%NAME%\n", fp); fprintf(fp, "%%NAME%%\n%s\n\n"
fprintf(fp, "%s\n\n", info->name); "%%VERSION%%\n%s\n\n", info->name, info->version);
fputs("%VERSION%\n", fp); if(info->desc[0]) {
fprintf(fp, "%s\n\n", info->version); fprintf(fp, "%%DESC%%\n"
fputs("%DESC%\n", fp); "%s\n\n", info->desc);
fprintf(fp, "%s\n\n", info->desc); }
if(info->groups) {
fputs("%GROUPS%\n", fp); fputs("%GROUPS%\n", fp);
for(lp = info->groups; lp; lp = lp->next) { for(lp = info->groups; lp; lp = lp->next) {
fprintf(fp, "%s\n", (char *)lp->data); fprintf(fp, "%s\n", (char *)lp->data);
} }
fprintf(fp, "\n"); fprintf(fp, "\n");
fputs("%URL%\n", fp); }
fprintf(fp, "%s\n\n", info->url); if(info->url[0]) {
fprintf(fp, "%%URL%%\n"
"%s\n\n", info->url);
}
if(info->license) {
fputs("%LICENSE%\n", fp); fputs("%LICENSE%\n", fp);
for(lp = info->license; lp; lp = lp->next) { for(lp = info->license; lp; lp = lp->next) {
fprintf(fp, "%s\n", (char *)lp->data); fprintf(fp, "%s\n", (char *)lp->data);
} }
fprintf(fp, "\n"); fprintf(fp, "\n");
fputs("%ARCH%\n", fp); }
fprintf(fp, "%s\n\n", info->arch); if(info->arch[0]) {
fputs("%BUILDDATE%\n", fp); fprintf(fp, "%%ARCH%%\n"
fprintf(fp, "%s\n\n", info->builddate); "%s\n\n", info->arch);
fputs("%INSTALLDATE%\n", fp); }
fprintf(fp, "%s\n\n", info->installdate); if(info->builddate[0]) {
fputs("%PACKAGER%\n", fp); fprintf(fp, "%%BUILDDATE%%\n"
fprintf(fp, "%s\n\n", info->packager); "%s\n\n", info->builddate);
fputs("%SIZE%\n", fp); }
fprintf(fp, "%ld\n\n", info->size); if(info->installdate[0]) {
fputs("%REASON%\n", fp); fprintf(fp, "%%INSTALLDATE%%\n"
fprintf(fp, "%d\n\n", info->reason); "%s\n\n", info->installdate);
}
if(info->packager[0]) {
fprintf(fp, "%%PACKAGER%%\n"
"%s\n\n", info->packager);
}
if(info->size) {
fprintf(fp, "%%SIZE%%\n"
"%ld\n\n", info->size);
}
if(info->reason) {
fprintf(fp, "%%REASON%%\n"
"%d\n\n", info->reason);
}
fclose(fp); fclose(fp);
fp = NULL; fp = NULL;
} }
@ -524,16 +542,20 @@ int db_write(pmdb_t *db, pmpkg_t *info, unsigned int inforeq)
retval = -1; retval = -1;
goto cleanup; goto cleanup;
} }
fputs("%FILES%\n", fp); if(info->files) {
fprintf(fp, "%%FILES%%\n");
for(lp = info->files; lp; lp = lp->next) { for(lp = info->files; lp; lp = lp->next) {
fprintf(fp, "%s\n", (char *)lp->data); fprintf(fp, "%s\n", (char *)lp->data);
} }
fprintf(fp, "\n"); fprintf(fp, "\n");
fputs("%BACKUP%\n", fp); }
if(info->backup) {
fprintf(fp, "%%BACKUP%%\n");
for(lp = info->backup; lp; lp = lp->next) { for(lp = info->backup; lp; lp = lp->next) {
fprintf(fp, "%s\n", (char *)lp->data); fprintf(fp, "%s\n", (char *)lp->data);
} }
fprintf(fp, "\n"); fprintf(fp, "\n");
}
fclose(fp); fclose(fp);
fp = NULL; fp = NULL;
} }
@ -546,26 +568,34 @@ int db_write(pmdb_t *db, pmpkg_t *info, unsigned int inforeq)
retval = -1; retval = -1;
goto cleanup; goto cleanup;
} }
if(info->depends) {
fputs("%DEPENDS%\n", fp); fputs("%DEPENDS%\n", fp);
for(lp = info->depends; lp; lp = lp->next) { for(lp = info->depends; lp; lp = lp->next) {
fprintf(fp, "%s\n", (char *)lp->data); fprintf(fp, "%s\n", (char *)lp->data);
} }
fprintf(fp, "\n"); fprintf(fp, "\n");
}
if(info->requiredby) {
fputs("%REQUIREDBY%\n", fp); fputs("%REQUIREDBY%\n", fp);
for(lp = info->requiredby; lp; lp = lp->next) { for(lp = info->requiredby; lp; lp = lp->next) {
fprintf(fp, "%s\n", (char *)lp->data); fprintf(fp, "%s\n", (char *)lp->data);
} }
fprintf(fp, "\n"); fprintf(fp, "\n");
}
if(info->conflicts) {
fputs("%CONFLICTS%\n", fp); fputs("%CONFLICTS%\n", fp);
for(lp = info->conflicts; lp; lp = lp->next) { for(lp = info->conflicts; lp; lp = lp->next) {
fprintf(fp, "%s\n", (char *)lp->data); fprintf(fp, "%s\n", (char *)lp->data);
} }
fprintf(fp, "\n"); fprintf(fp, "\n");
}
if(info->provides) {
fputs("%PROVIDES%\n", fp); fputs("%PROVIDES%\n", fp);
for(lp = info->provides; lp; lp = lp->next) { for(lp = info->provides; lp; lp = lp->next) {
fprintf(fp, "%s\n", (char *)lp->data); fprintf(fp, "%s\n", (char *)lp->data);
} }
fprintf(fp, "\n"); fprintf(fp, "\n");
}
fclose(fp); fclose(fp);
fp = NULL; fp = NULL;
} }