]> code.citadel.org Git - citadel.git/blobdiff - citadel/utils/ctdl3264.c
Remediated an unrecoverable problem in CDB_USETABLE.
[citadel.git] / citadel / utils / ctdl3264.c
index b9c5fde33bb9f15dc6d7f090338a76529c909761..7ad960a69a77ae19e7a4a7451d438dcda979602d 100644 (file)
@@ -328,7 +328,7 @@ void convert_visits(int which_cdb, DBT *in_key, DBT *in_data, DBT *out_key, DBT
        strcpy(visit64->v_answered,                     visit32->v_answered);
        visit64->v_view                 = (int)         visit32->v_view;
 
-       // printf("\033[32m\033[1mVisit: room %ld, gen %ld, user %ld\033[0m\n", visit64->v_roomnum, visit64->v_roomgen, visit64->v_usernum);
+       // printf("\033[32m\033[1mVisit: room %10ld, gen %10ld, user %10ld\033[0m\n", visit64->v_roomnum, visit64->v_roomgen, visit64->v_usernum);
 
        // create the key (which is based on the data, so there is no need to convert the old key)
        out_key->size = sizeof(struct visit_index);
@@ -365,7 +365,7 @@ void convert_dir(int which_cdb, DBT *in_key, DBT *in_data, DBT *out_key, DBT *ou
 // convert function for a use table record
 void convert_usetable(int which_cdb, DBT *in_key, DBT *in_data, DBT *out_key, DBT *out_data) {
 
-       // the key is a string
+       // the key is an int, which is the same size (32 bits) on both 32 and 64 bit systems
        out_key->size = in_key->size;
        out_key->data = realloc(out_key->data, out_key->size);
        memcpy(out_key->data, in_key->data, in_key->size);
@@ -378,8 +378,10 @@ void convert_usetable(int which_cdb, DBT *in_key, DBT *in_data, DBT *out_key, DB
        struct UseTable *use64 = (struct UseTable *)out_data->data;
 
        //  the data
-       strcpy(use64->ut_msgid,                         use32->ut_msgid);
-       use64->ut_timestamp             = (time_t)      use32->ut_timestamp;
+       use64->hash                     =               use32->hash;
+       use64->timestamp                = (time_t)      use32->timestamp;
+
+       printf("\033[32m\033[1muse table: %d , %s\033[0m\n", use64->hash, asctime(localtime(&use64->timestamp)));
 }
 
 
@@ -397,6 +399,10 @@ void convert_bigmsgs(int which_cdb, DBT *in_key, DBT *in_data, DBT *out_key, DBT
                abort();
        }
 
+       out_key->size = sizeof(long);
+       out_key->data = realloc(out_key->data, out_key->size);
+       memcpy(out_key->data, &out_msgnum, sizeof(long));
+
        // the data is binary-ish but has no packed integers
        out_data->size = in_data->size;
        out_data->data = realloc(out_data->data, out_data->size);
@@ -627,14 +633,15 @@ void convert_table(int which_cdb, DB_ENV *src_dbenv, DB_ENV *dst_dbenv) {
 
        // Walk through the database, calling convert functions as we go and clearing buffers before each call.
        while (out_key.size = 0, out_data.size = 0, (ret = src_dbcp->get(src_dbcp, &in_key, &in_data, DB_NEXT)) == 0) {
-
-
-               if (in_key.size == 0) {
-                       printf("\033[31mzero length key, skipping\033[0m\n");
-               }
-
-               else if (in_data.size == 0) {
-                       printf("\033[31mzero length data, skipping\033[0m\n");
+       
+               // Knowing the total number of rows isn't critical to the program.  It's just for the user to know.
+               ++num_rows;
+               printf("   \033[32m%d\033[0m\r", num_rows);
+               fflush(stdout);
+
+               // If either the key or data are zero length, skip this record
+               if ((in_key.size == 0) || (in_data.size == 0)) {
+                       printf("\033[31minput keylen=%d , datalen=%d , skipping record\033[0m\n", in_key.size, in_data.size);
                }
 
                else {  // Both key and data are >0 length so we're good to go
@@ -698,11 +705,9 @@ void convert_table(int which_cdb, DB_ENV *src_dbenv, DB_ENV *dst_dbenv) {
                                        printf("db: cdb_put(%d): %s", which_cdb, db_strerror(ret));
                                        exit(CTDLEXIT_DB);
                                }
-       
-                               // Knowing the total number of rows isn't critical to the program.  It's just for the user to know.
-                               ++num_rows;
-                               printf("   \033[32m%d\033[0m\r", num_rows);
-                               fflush(stdout);
+                       }
+                       else {
+                               printf("\033[31moutput keylen=%d , skipping record\033[0m\n", out_key.size);
                        }
                }
        }
@@ -796,9 +801,10 @@ int main(int argc, char **argv) {
 
        src_dbenv = open_dbenv(src_dir);
        dst_dbenv = open_dbenv(dst_dir);
-       for (int i = 0; i < MAXCDB; ++i) {
-               convert_table(i, src_dbenv, dst_dbenv);
-       }
+       //for (int i = 0; i < MAXCDB; ++i) {
+               //convert_table(i, src_dbenv, dst_dbenv);
+       //}
+       convert_table(7, src_dbenv, dst_dbenv);
        close_dbenv(src_dbenv);
        close_dbenv(dst_dbenv);