Git-Url: 
http://git.frugalware.org/gitweb/gitweb.cgi?p=fwife.git;a=commitdiff;h=37513d02436fef1e27c652396ce9a6d8f66cc3c8

commit 37513d02436fef1e27c652396ce9a6d8f66cc3c8
Author: Elentir <elen...@mailoo.org>
Date:   Thu Jan 21 23:53:56 2010 +0100

simplify prepare_pkgdb() function

diff --git a/src/plugins/select.c b/src/plugins/select.c
index 02354d9..278a3a1 100644
--- a/src/plugins/select.c
+++ b/src/plugins/select.c
@@ -270,59 +270,28 @@ GList *getcat(PM_DB *db, GList *syncs)
return catlist;
}

-int prepare_pkgdb(char *repo, GList **config, GList **syncs)
+int prepare_pkgdb()
{
-       char *pkgdb;
-       struct stat sbuf;
+       char *ptr;
int ret;
-       //PM_DB *i;
-
-       pkgdb = g_strdup_printf("%s/var/lib/pacman-g2/%s", TARGETDIR, repo);
-
-       // prepare pkgdb if necessary
-       if(stat(pkgdb, &sbuf) || S_ISDIR(sbuf.st_mode))
-       {
-               // pacman can't lock & log without these
-               makepath(g_strdup_printf("%s/tmp", TARGETDIR));
-               makepath(g_strdup_printf("%s/var/log", TARGETDIR));
-               LOG("parsing the pacman-g2 configuration file");
-               if (pacman_parse_config("/etc/pacman-g2.conf", cb_db_register, 
"") == -1) {
-                       LOG("Failed to parse pacman-g2 configuration file 
(%s)", pacman_strerror(pm_errno));
-                       return(-1);
-               }
-
-               LOG("getting the database");
-               if (mydatabase == NULL)
-               {
-                       LOG("Could not register '%s' database (%s)", PACCONF, 
pacman_strerror(pm_errno));
-                       return(-1);
-               }
-               else
-               {
-                       LOG("updating the database");
-                       ret = pacman_db_update(1, mydatabase);
-                       if(ret == 0) {
-                               LOG("database update done");
-                       }
-                       if (ret == -1) {
-                               LOG("database update failed");
-                               if(pm_errno == PM_ERR_DB_SYNC) {
-                                       LOG("Failed to synchronize %s", 
PACCONF);
-                                       return(-1);
-                               } else {
-                                       LOG("Failed to update %s (%s)", 
PACCONF, pacman_strerror(pm_errno));
-                                       return(-1);
-                               }
-                       }
-               }
-
-               LOG("cleaning up the database");
-               pacman_db_unregister(mydatabase);
-               mydatabase = NULL;
+       PM_DB *db;
+
+       // pacman can't lock & log without these
+       ptr = g_strdup_printf("%s/tmp", TARGETDIR);
+       makepath(ptr);
+       free(ptr);
+       ptr = g_strdup_printf("%s/var/log", TARGETDIR);
+       makepath(ptr);
+       free(ptr);
+
+       if (pacman_parse_config("/etc/pacman-g2.conf", NULL, "") == -1) {
+               LOG("Failed to parse pacman-g2 configuration file (%s)", 
pacman_strerror(pm_errno));
+               return(-1);
}
+
// register the database
-       PM_DB *i = pacman_db_register(PACCONF);
-       if(i==NULL)
+       db = pacman_db_register(PACCONF);
+       if(db == NULL)
{
fprintf(stderr, "could not register '%s' database (%s)\n",
PACCONF, pacman_strerror(pm_errno));
@@ -330,7 +299,22 @@ int prepare_pkgdb(char *repo, GList **config, GList 
**syncs)
}
else
{
-               *syncs = g_list_append(*syncs, i);
+               LOG("updating the database");
+               ret = pacman_db_update(1, db);
+               if(ret == 0) {
+                       LOG("database update done");
+               }
+               if (ret == -1) {
+                       LOG("database update failed");
+                       if(pm_errno == PM_ERR_DB_SYNC) {
+                               LOG("Failed to synchronize %s", PACCONF);
+                               return(-1);
+                       } else {
+                               LOG("Failed to update %s (%s)", PACCONF, 
pacman_strerror(pm_errno));
+                               return(-1);
+                       }
+               }
+               syncs = g_list_append(syncs, db);
}
return(0);
}
@@ -1199,7 +1183,7 @@ int prerun(GList **config)
while (gtk_events_pending())
gtk_main_iteration ();

-       if(prepare_pkgdb(PACCONF, config, &syncs) == -1)
+       if(prepare_pkgdb() == -1)
{
return(-1);
}
_______________________________________________
Frugalware-git mailing list
Frugalware-git@frugalware.org
http://frugalware.org/mailman/listinfo/frugalware-git

Reply via email to