Refactoring: Fix compiler warnings
authorTomas Mlcoch <tmlcoch@redhat.com>
Thu, 8 Oct 2015 09:23:57 +0000 (11:23 +0200)
committerTomas Mlcoch <tmlcoch@redhat.com>
Thu, 8 Oct 2015 09:23:57 +0000 (11:23 +0200)
1. Fix usage of "const" modifiers to prevent compiler warnings.
2. In cr_prestodelta_thread() use return value from g_slist_append()
   to be sure that we have correct start of the list stored in
   the hash table.
3. Add another comment to cr_dumper_thread() to explicitly
   tell that stuff we are doing there are modifing package
   strucutres and that it's intentional.

src/compression_wrapper.c
src/deltarpms.c
src/dumper_thread.c

index a08aaa6..db35929 100644 (file)
@@ -270,11 +270,11 @@ cr_compression_suffix(cr_CompressionType comtype)
 }
 
 
-static char *
+static const char *
 cr_gz_strerror(gzFile f)
 {
     int errnum;
-    char *msg = (char *) gzerror(f, &errnum);
+    const char *msg = gzerror(f, &errnum);
     if (errnum == Z_ERRNO)
         msg = g_strerror(errno);
     return msg;
index 4f518ff..845b1ea 100644 (file)
@@ -501,6 +501,8 @@ cr_deltarpms_parallel_deltas(GSList *targetpackages,
     g_list_free(targets);
     g_mutex_free(user_data.mutex);
     g_cond_free(user_data.cond_task_finished);
+
+    return TRUE;
 }
 
 
@@ -563,7 +565,6 @@ cr_deltarpms_scan_targetdir(const char *path,
                             GError **err)
 {
     GSList *targets = NULL;
-    GDir *dirp;
     GQueue *sub_dirs = g_queue_new();
     GStringChunk *sub_dirs_chunk = g_string_chunk_new(1024);
 
@@ -645,7 +646,7 @@ typedef struct {
     GMutex *mutex;
     GHashTable *ht;
     cr_ChecksumType checksum_type;
-    gchar *prefix_to_strip;
+    const gchar *prefix_to_strip;
     size_t prefix_len;
 } cr_PrestoDeltaUserData;
 
@@ -733,7 +734,6 @@ cr_prestodelta_thread(gpointer data, gpointer udata)
     cr_DeltaPackage *dpkg = NULL;
     struct stat st;
     gchar *xml_chunk = NULL, *key = NULL, *checksum = NULL;
-    gpointer val;
     GError *tmp_err = NULL;
 
     printf("%s\n", task->full_path);
@@ -787,11 +787,19 @@ cr_prestodelta_thread(gpointer data, gpointer udata)
     }
 
     // Put the XML into the shared hash table
+    gpointer pkey = NULL;
+    gpointer pval = NULL;
     key = cr_package_nevra(dpkg->package);
     g_mutex_lock(user_data->mutex);
-    if (g_hash_table_lookup_extended(user_data->ht, key, NULL, &val)) {
+    if (g_hash_table_lookup_extended(user_data->ht, key, &pkey, &pval)) {
         // Key exists in the table
-        g_slist_append( ((GSList *) val), xml_chunk);
+        // 1. Remove the key and value from the table without freeing them
+        g_hash_table_steal(user_data->ht, key);
+        // 2. Append to the list (the value from the hash table)
+        GSList *list = (GSList *) pval;
+        list = g_slist_append(pval, xml_chunk);
+        // 3. Insert the modified list again
+        g_hash_table_insert(user_data->ht, pkey, list);
     } else {
         // Key doesn't exist yet
         GSList *list = g_slist_prepend(NULL, xml_chunk);
@@ -807,8 +815,7 @@ exit:
 
 static gchar *
 gen_newpackage_xml_chunk(const char *strnevra,
-                         GSList *delta_chunks,
-                         GError **err)
+                         GSList *delta_chunks)
 {
     cr_NEVRA *nevra;
     GString *chunk;
@@ -908,7 +915,7 @@ cr_deltarpms_generate_prestodelta_file(const gchar *drpmsdir,
         gchar *chunk = NULL;
         gchar *nevra = key;
 
-        chunk = gen_newpackage_xml_chunk(nevra, (GSList *) value, NULL);
+        chunk = gen_newpackage_xml_chunk(nevra, (GSList *) value);
         cr_xmlfile_add_chunk(f, chunk, NULL);
         g_free(chunk);
     }
index dd167d7..31f884d 100644 (file)
@@ -366,7 +366,10 @@ cr_dumper_thread(gpointer data, gpointer user_data)
                 // WARNING! This two lines destructively modifies content of
                 // packages in old metadata.
                 md->location_href = location_href;
-                md->location_base = location_base;
+                md->location_base = (gchar *) location_base;
+                // ^^^ The location_base is not properly saved into pkg chunk
+                // this is intentional as after the metadata are written
+                // (dumped) none should use them again.
             }
         }
     }