commit c90a32fd8dc260dea38c82142df4a6d012b22fa3
Author: Hector Martin <hec...@marcansoft.com>
Date:   Tue Oct 20 04:03:05 2009 +0200

    Always rebuild Locations.itdb
    
    The device will generate some BS SQLite files given just an iTunesCDB,
    but they have old/wrong schemas and lack proper contents. Locations.itdb
    is critical and therefore needs this treatment.

 src/itdb_sqlite.c |   32 +++++++++++++-------------------
 1 files changed, 13 insertions(+), 19 deletions(-)
---
diff --git a/src/itdb_sqlite.c b/src/itdb_sqlite.c
index 2d7f172..24240b1 100644
--- a/src/itdb_sqlite.c
+++ b/src/itdb_sqlite.c
@@ -1020,23 +1020,19 @@ leave:
 
 static void mk_Locations(Itdb_iTunesDB *itdb, const char *outpath, const char 
*uuid)
 {
-    int rebuild = 0;
     gchar *dbf = NULL;
     sqlite3 *db = NULL;
     sqlite3_stmt *stmt = NULL;
     const char *sqltail = NULL;
     char *errmsg = NULL;
-    struct stat fst;
     int idx = 0;
    
     dbf = g_build_filename(outpath, "Locations.itdb", NULL);
     printf("[%s] Processing '%s'\n", __func__, dbf);
-    if (stat(dbf, &fst) != 0) {
-       if (errno == ENOENT) {
-           /* file is not present. so we will create it */
-           rebuild = 1;
-       } else {
-           fprintf(stderr, "[%s] Error: stat: %s\n", __func__, 
strerror(errno));
+    /* file is present. delete it, we'll re-create it. */
+    if (g_unlink(dbf) != 0) {
+       if (errno != ENOENT) {
+           fprintf(stderr, "[%s] could not delete '%s': %s\n", __func__, dbf, 
strerror(errno));
            goto leave;
        }
     }
@@ -1046,18 +1042,16 @@ static void mk_Locations(Itdb_iTunesDB *itdb, const 
char *outpath, const char *u
        goto leave;
     }
 
-    if (rebuild) {
-       fprintf(stderr, "[%s] re-building table structure\n", __func__);
-       /* db structure needs to be created. */
-       if (SQLITE_OK != sqlite3_exec(db, Locations_create, NULL, NULL, 
&errmsg)) {
-           fprintf(stderr, "[%s] sqlite3_exec error: %s\n", __func__, 
sqlite3_errmsg(db));
-           if (errmsg) {
-               fprintf(stderr, "[%s] additional error information: %s\n", 
__func__, errmsg);
-               sqlite3_free(errmsg);
-               errmsg = NULL;
-           }
-           goto leave;
+    fprintf(stderr, "[%s] re-building table structure\n", __func__);
+    /* db structure needs to be created. */
+    if (SQLITE_OK != sqlite3_exec(db, Locations_create, NULL, NULL, &errmsg)) {
+       fprintf(stderr, "[%s] sqlite3_exec error: %s\n", __func__, 
sqlite3_errmsg(db));
+       if (errmsg) {
+           fprintf(stderr, "[%s] additional error information: %s\n", 
__func__, errmsg);
+           sqlite3_free(errmsg);
+           errmsg = NULL;
        }
+       goto leave;
     }
 
     /* kill all entries in 'location' as they will be re-inserted */

------------------------------------------------------------------------------
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev
_______________________________________________
gtkpod-cvs2 mailing list
gtkpod-cvs2@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gtkpod-cvs2

Reply via email to