Git-Url: 
http://git.frugalware.org/gitweb/gitweb.cgi?p=pacman-g2.git;a=commitdiff;h=7bd7ba6ebb3dc37a132c0773f20bfc7efb5bb618

commit 7bd7ba6ebb3dc37a132c0773f20bfc7efb5bb618
Author: Michel Hermier <herm...@frugalware.org>
Date:   Sat Nov 9 11:09:42 2013 +0100

libpacman: Move _pacman_localdb_write to localdb.c file.

diff --git a/lib/libpacman/be_files.c b/lib/libpacman/be_files.c
index 261244e..5bccb99 100644
--- a/lib/libpacman/be_files.c
+++ b/lib/libpacman/be_files.c
@@ -560,132 +560,6 @@ error:
return(-1);
}

-static
-void _pacman_db_write_bool(const char *entry, int value, FILE *stream)
-{
-       if(value != 0) {
-               fprintf(stream, "%%%s%%\n\n", entry);
-       }
-}
-
-static
-void _pacman_db_write_string(const char *entry, const char *value, FILE 
*stream)
-{
-       if(!_pacman_strempty(value)) {
-               fprintf(stream, "%%%s%%\n%s\n\n", entry, value);
-       }
-}
-
-static
-void _pacman_db_write_stringlist(const char *entry, const pmlist_t *values, 
FILE *stream)
-{
-       const pmlist_t *lp;
-
-       if(values != NULL) {
-               fprintf(stream, "%%%s%%\n", entry);
-               for(lp = values; lp; lp = lp->next) {
-                       fprintf(stream, "%s\n", (char *)lp->data);
-               }
-               fputc('\n', stream);
-       }
-}
-
-static
-int _pacman_localdb_write(pmdb_t *db, pmpkg_t *info, unsigned int inforeq)
-{
-       FILE *fp = NULL;
-       char path[PATH_MAX];
-       mode_t oldmask;
-       int retval = 0;
-
-       ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
-       if(info == NULL) {
-               return(-1);
-       }
-
-       snprintf(path, PATH_MAX, "%s/%s-%s", db->path, info->name, 
info->version);
-       oldmask = umask(0000);
-       mkdir(path, 0755);
-       /* make sure we have a sane umask */
-       umask(0022);
-
-       /* DESC */
-       if(inforeq & INFRQ_DESC) {
-               snprintf(path, PATH_MAX, "%s/%s-%s/desc", db->path, info->name, 
info->version);
-               if((fp = fopen(path, "w")) == NULL) {
-                       _pacman_log(PM_LOG_ERROR, _("db_write: could not open 
file %s/desc"), db->treename);
-                       retval = 1;
-                       goto cleanup;
-               }
-               _pacman_db_write_string("NAME", info->name, fp);
-               _pacman_db_write_string("VERSION", info->version, fp);
-               if(info->desc[0]) {
-                       _pacman_db_write_stringlist("DESC", 
info->desc_localized, fp);
-               }
-               _pacman_db_write_stringlist("GROUPS", info->groups, fp);
-               _pacman_db_write_string("URL", info->url, fp);
-               _pacman_db_write_stringlist("LICENSE", info->license, fp);
-               _pacman_db_write_string("ARCH", info->arch, fp);
-               _pacman_db_write_string("BUILDDATE", info->builddate, fp);
-               _pacman_db_write_string("BUILDTYPE", info->buildtype, fp);
-               _pacman_db_write_string("INSTALLDATE", info->installdate, fp);
-               _pacman_db_write_string("PACKAGER", info->packager, fp);
-               if(info->size) {
-                       fprintf(fp, "%%SIZE%%\n"
-                               "%ld\n\n", info->size);
-               }
-               if(info->reason) {
-                       fprintf(fp, "%%REASON%%\n"
-                               "%d\n\n", info->reason);
-               }
-               _pacman_db_write_stringlist("TRIGGERS", info->triggers, fp);
-               fclose(fp);
-               fp = NULL;
-       }
-
-       /* FILES */
-       if(inforeq & INFRQ_FILES) {
-               snprintf(path, PATH_MAX, "%s/%s-%s/files", db->path, 
info->name, info->version);
-               if((fp = fopen(path, "w")) == NULL) {
-                       _pacman_log(PM_LOG_ERROR, _("db_write: could not open 
file %s/files"), db->treename);
-                       retval = -1;
-                       goto cleanup;
-               }
-               _pacman_db_write_stringlist("FILES", info->files, fp);
-               _pacman_db_write_stringlist("BACKUP", info->backup, fp);
-               fclose(fp);
-               fp = NULL;
-       }
-
-       /* DEPENDS */
-       if(inforeq & INFRQ_DEPENDS) {
-               snprintf(path, PATH_MAX, "%s/%s-%s/depends", db->path, 
info->name, info->version);
-               if((fp = fopen(path, "w")) == NULL) {
-                       _pacman_log(PM_LOG_ERROR, _("db_write: could not open 
file %s/depends"), db->treename);
-                       retval = -1;
-                       goto cleanup;
-               }
-               _pacman_db_write_stringlist("DEPENDS", info->depends, fp);
-               _pacman_db_write_stringlist("REQUIREDBY", info->requiredby, fp);
-               _pacman_db_write_stringlist("CONFLICTS", info->conflicts, fp);
-               _pacman_db_write_stringlist("PROVIDES", info->provides, fp);
-               fclose(fp);
-               fp = NULL;
-       }
-
-       /* INSTALL */
-       /* nothing needed here (script is automatically extracted) */
-
-cleanup:
-       umask(oldmask);
-
-       if(fp) {
-               fclose(fp);
-       }
-
-       return(retval);
-}
-
int _pacman_db_write(pmdb_t *db, pmpkg_t *info, unsigned int inforeq)
{
ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
diff --git a/lib/libpacman/db/localdb.c b/lib/libpacman/db/localdb.c
index 8552308..855a26c 100644
--- a/lib/libpacman/db/localdb.c
+++ b/lib/libpacman/db/localdb.c
@@ -112,4 +112,129 @@ int _pacman_localdb_rewind(pmdb_t *db)
return 0;
}

+static
+void _pacman_db_write_bool(const char *entry, int value, FILE *stream)
+{
+       if(value != 0) {
+               fprintf(stream, "%%%s%%\n\n", entry);
+       }
+}
+
+static
+void _pacman_db_write_string(const char *entry, const char *value, FILE 
*stream)
+{
+       if(!_pacman_strempty(value)) {
+               fprintf(stream, "%%%s%%\n%s\n\n", entry, value);
+       }
+}
+
+static
+void _pacman_db_write_stringlist(const char *entry, const pmlist_t *values, 
FILE *stream)
+{
+       const pmlist_t *lp;
+
+       if(values != NULL) {
+               fprintf(stream, "%%%s%%\n", entry);
+               for(lp = values; lp; lp = lp->next) {
+                       fprintf(stream, "%s\n", (char *)lp->data);
+               }
+               fputc('\n', stream);
+       }
+}
+
+int _pacman_localdb_write(pmdb_t *db, pmpkg_t *info, unsigned int inforeq)
+{
+       FILE *fp = NULL;
+       char path[PATH_MAX];
+       mode_t oldmask;
+       int retval = 0;
+
+       ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
+       if(info == NULL) {
+               return(-1);
+       }
+
+       snprintf(path, PATH_MAX, "%s/%s-%s", db->path, info->name, 
info->version);
+       oldmask = umask(0000);
+       mkdir(path, 0755);
+       /* make sure we have a sane umask */
+       umask(0022);
+
+       /* DESC */
+       if(inforeq & INFRQ_DESC) {
+               snprintf(path, PATH_MAX, "%s/%s-%s/desc", db->path, info->name, 
info->version);
+               if((fp = fopen(path, "w")) == NULL) {
+                       _pacman_log(PM_LOG_ERROR, _("db_write: could not open 
file %s/desc"), db->treename);
+                       retval = 1;
+                       goto cleanup;
+               }
+               _pacman_db_write_string("NAME", info->name, fp);
+               _pacman_db_write_string("VERSION", info->version, fp);
+               if(info->desc[0]) {
+                       _pacman_db_write_stringlist("DESC", 
info->desc_localized, fp);
+               }
+               _pacman_db_write_stringlist("GROUPS", info->groups, fp);
+               _pacman_db_write_string("URL", info->url, fp);
+               _pacman_db_write_stringlist("LICENSE", info->license, fp);
+               _pacman_db_write_string("ARCH", info->arch, fp);
+               _pacman_db_write_string("BUILDDATE", info->builddate, fp);
+               _pacman_db_write_string("BUILDTYPE", info->buildtype, fp);
+               _pacman_db_write_string("INSTALLDATE", info->installdate, fp);
+               _pacman_db_write_string("PACKAGER", info->packager, fp);
+               if(info->size) {
+                       fprintf(fp, "%%SIZE%%\n"
+                               "%ld\n\n", info->size);
+               }
+               if(info->reason) {
+                       fprintf(fp, "%%REASON%%\n"
+                               "%d\n\n", info->reason);
+               }
+               _pacman_db_write_stringlist("TRIGGERS", info->triggers, fp);
+               fclose(fp);
+               fp = NULL;
+       }
+
+       /* FILES */
+       if(inforeq & INFRQ_FILES) {
+               snprintf(path, PATH_MAX, "%s/%s-%s/files", db->path, 
info->name, info->version);
+               if((fp = fopen(path, "w")) == NULL) {
+                       _pacman_log(PM_LOG_ERROR, _("db_write: could not open 
file %s/files"), db->treename);
+                       retval = -1;
+                       goto cleanup;
+               }
+               _pacman_db_write_stringlist("FILES", info->files, fp);
+               _pacman_db_write_stringlist("BACKUP", info->backup, fp);
+               fclose(fp);
+               fp = NULL;
+       }
+
+       /* DEPENDS */
+       if(inforeq & INFRQ_DEPENDS) {
+               snprintf(path, PATH_MAX, "%s/%s-%s/depends", db->path, 
info->name, info->version);
+               if((fp = fopen(path, "w")) == NULL) {
+                       _pacman_log(PM_LOG_ERROR, _("db_write: could not open 
file %s/depends"), db->treename);
+                       retval = -1;
+                       goto cleanup;
+               }
+               _pacman_db_write_stringlist("DEPENDS", info->depends, fp);
+               _pacman_db_write_stringlist("REQUIREDBY", info->requiredby, fp);
+               _pacman_db_write_stringlist("CONFLICTS", info->conflicts, fp);
+               _pacman_db_write_stringlist("PROVIDES", info->provides, fp);
+               fclose(fp);
+               fp = NULL;
+       }
+
+       /* INSTALL */
+       /* nothing needed here (script is automatically extracted) */
+
+cleanup:
+       umask(oldmask);
+
+       if(fp) {
+               fclose(fp);
+       }
+
+       return(retval);
+}
+
/* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libpacman/db/localdb.h b/lib/libpacman/db/localdb.h
index e8f9d6b..aa73036 100644
--- a/lib/libpacman/db/localdb.h
+++ b/lib/libpacman/db/localdb.h
@@ -27,6 +27,7 @@ pmlist_t *_pacman_localdb_test(pmdb_t *db);
int _pacman_localdb_open(pmdb_t *db);
int _pacman_localdb_close(pmdb_t *db);
int _pacman_localdb_rewind(pmdb_t *db);
+int _pacman_localdb_write(pmdb_t *db, pmpkg_t *info, unsigned int inforeq);

#endif /* _PACMAN_LOCALDB_H */
_______________________________________________
Frugalware-git mailing list
Frugalware-git@frugalware.org
http://frugalware.org/mailman/listinfo/frugalware-git

Reply via email to