repomd module refactoring.
authorTomas Mlcoch <tmlcoch@redhat.com>
Mon, 25 Feb 2013 12:50:08 +0000 (13:50 +0100)
committerTomas Mlcoch <tmlcoch@redhat.com>
Mon, 25 Feb 2013 13:52:24 +0000 (14:52 +0100)
src/createrepo_c.c
src/mergerepo_c.c
src/repomd.c
src/repomd.h

index 5ebbdcb..e18e87d 100644 (file)
@@ -1006,11 +1006,11 @@ main(int argc, char **argv)
 
     g_debug("Generating repomd.xml");
 
-    cr_Repomd repomd_obj = cr_new_repomd();
+    cr_Repomd repomd_obj = cr_repomd_new();
 
-    cr_RepomdRecord pri_xml_rec = cr_new_repomdrecord(pri_xml_filename);
-    cr_RepomdRecord fil_xml_rec = cr_new_repomdrecord(fil_xml_filename);
-    cr_RepomdRecord oth_xml_rec = cr_new_repomdrecord(oth_xml_filename);
+    cr_RepomdRecord pri_xml_rec = cr_repomd_record_new(pri_xml_filename);
+    cr_RepomdRecord fil_xml_rec = cr_repomd_record_new(fil_xml_filename);
+    cr_RepomdRecord oth_xml_rec = cr_repomd_record_new(oth_xml_filename);
     cr_RepomdRecord pri_db_rec               = NULL;
     cr_RepomdRecord fil_db_rec               = NULL;
     cr_RepomdRecord oth_db_rec               = NULL;
@@ -1021,17 +1021,17 @@ main(int argc, char **argv)
 
     // XML
 
-    cr_fill_repomdrecord(pri_xml_rec, cmd_options->checksum_type);
-    cr_fill_repomdrecord(fil_xml_rec, cmd_options->checksum_type);
-    cr_fill_repomdrecord(oth_xml_rec, cmd_options->checksum_type);
+    cr_repomd_record_fill(pri_xml_rec, cmd_options->checksum_type);
+    cr_repomd_record_fill(fil_xml_rec, cmd_options->checksum_type);
+    cr_repomd_record_fill(oth_xml_rec, cmd_options->checksum_type);
 
 
     // Groupfile
 
     if (groupfile) {
-        groupfile_rec = cr_new_repomdrecord(groupfile);
-        compressed_groupfile_rec = cr_new_repomdrecord(groupfile);
-        cr_process_groupfile_repomdrecord(groupfile_rec,
+        groupfile_rec = cr_repomd_record_new(groupfile);
+        compressed_groupfile_rec = cr_repomd_record_new(groupfile);
+        cr_repomd_record_groupfile(groupfile_rec,
                                           compressed_groupfile_rec,
                                           cmd_options->checksum_type,
                                           groupfile_compression);
@@ -1041,8 +1041,8 @@ main(int argc, char **argv)
     // Updateinfo
 
     if (updateinfo) {
-        updateinfo_rec = cr_new_repomdrecord(updateinfo);
-        cr_fill_repomdrecord(updateinfo_rec, cmd_options->checksum_type);
+        updateinfo_rec = cr_repomd_record_new(updateinfo);
+        cr_repomd_record_fill(updateinfo_rec, cmd_options->checksum_type);
     }
 
 
@@ -1083,13 +1083,13 @@ main(int argc, char **argv)
 
         // Prepare repomd records
 
-        pri_db_rec = cr_new_repomdrecord(pri_db_name);
-        fil_db_rec = cr_new_repomdrecord(fil_db_name);
-        oth_db_rec = cr_new_repomdrecord(oth_db_name);
+        pri_db_rec = cr_repomd_record_new(pri_db_name);
+        fil_db_rec = cr_repomd_record_new(fil_db_name);
+        oth_db_rec = cr_repomd_record_new(oth_db_name);
 
-        cr_fill_repomdrecord(pri_db_rec, cmd_options->checksum_type);
-        cr_fill_repomdrecord(fil_db_rec, cmd_options->checksum_type);
-        cr_fill_repomdrecord(oth_db_rec, cmd_options->checksum_type);
+        cr_repomd_record_fill(pri_db_rec, cmd_options->checksum_type);
+        cr_repomd_record_fill(fil_db_rec, cmd_options->checksum_type);
+        cr_repomd_record_fill(oth_db_rec, cmd_options->checksum_type);
 
         g_free(pri_db_name);
         g_free(fil_db_name);
@@ -1100,15 +1100,15 @@ main(int argc, char **argv)
     // Add checksums into files names
 
     if (cmd_options->unique_md_filenames) {
-        cr_rename_repomdrecord_file(pri_xml_rec);
-        cr_rename_repomdrecord_file(fil_xml_rec);
-        cr_rename_repomdrecord_file(oth_xml_rec);
-        cr_rename_repomdrecord_file(pri_db_rec);
-        cr_rename_repomdrecord_file(fil_db_rec);
-        cr_rename_repomdrecord_file(oth_db_rec);
-        cr_rename_repomdrecord_file(groupfile_rec);
-        cr_rename_repomdrecord_file(compressed_groupfile_rec);
-        cr_rename_repomdrecord_file(updateinfo_rec);
+        cr_repomd_record_rename_file(pri_xml_rec);
+        cr_repomd_record_rename_file(fil_xml_rec);
+        cr_repomd_record_rename_file(oth_xml_rec);
+        cr_repomd_record_rename_file(pri_db_rec);
+        cr_repomd_record_rename_file(fil_db_rec);
+        cr_repomd_record_rename_file(oth_db_rec);
+        cr_repomd_record_rename_file(groupfile_rec);
+        cr_repomd_record_rename_file(compressed_groupfile_rec);
+        cr_repomd_record_rename_file(updateinfo_rec);
     }
 
 
@@ -1145,9 +1145,9 @@ main(int argc, char **argv)
     if (cmd_options->revision)
         cr_repomd_set_revision(repomd_obj, cmd_options->revision);
 
-    char *repomd_xml = cr_generate_repomd_xml(repomd_obj);
+    char *repomd_xml = cr_repomd_xml_dump(repomd_obj);
 
-    cr_free_repomd(repomd_obj);
+    cr_repomd_free(repomd_obj);
 
 
     // Write repomd.xml
index adaf85f..f6d55e2 100644 (file)
@@ -1122,9 +1122,9 @@ dump_merged_metadata(GHashTable *merged_hashtable,
 
     // Prepare repomd records
 
-    cr_RepomdRecord pri_xml_rec = cr_new_repomdrecord(pri_xml_filename);
-    cr_RepomdRecord fil_xml_rec = cr_new_repomdrecord(fil_xml_filename);
-    cr_RepomdRecord oth_xml_rec = cr_new_repomdrecord(oth_xml_filename);
+    cr_RepomdRecord pri_xml_rec = cr_repomd_record_new(pri_xml_filename);
+    cr_RepomdRecord fil_xml_rec = cr_repomd_record_new(fil_xml_filename);
+    cr_RepomdRecord oth_xml_rec = cr_repomd_record_new(oth_xml_filename);
     cr_RepomdRecord pri_db_rec               = NULL;
     cr_RepomdRecord fil_db_rec               = NULL;
     cr_RepomdRecord oth_db_rec               = NULL;
@@ -1136,17 +1136,17 @@ dump_merged_metadata(GHashTable *merged_hashtable,
 
     // XML
 
-    cr_fill_repomdrecord(pri_xml_rec, CR_CHECKSUM_SHA256);
-    cr_fill_repomdrecord(fil_xml_rec, CR_CHECKSUM_SHA256);
-    cr_fill_repomdrecord(oth_xml_rec, CR_CHECKSUM_SHA256);
+    cr_repomd_record_fill(pri_xml_rec, CR_CHECKSUM_SHA256);
+    cr_repomd_record_fill(fil_xml_rec, CR_CHECKSUM_SHA256);
+    cr_repomd_record_fill(oth_xml_rec, CR_CHECKSUM_SHA256);
 
 
     // Groupfile
 
     if (groupfile) {
-        groupfile_rec = cr_new_repomdrecord(groupfile);
-        compressed_groupfile_rec = cr_new_repomdrecord(groupfile);
-        cr_process_groupfile_repomdrecord(groupfile_rec,
+        groupfile_rec = cr_repomd_record_new(groupfile);
+        compressed_groupfile_rec = cr_repomd_record_new(groupfile);
+        cr_repomd_record_groupfile(groupfile_rec,
                                           compressed_groupfile_rec,
                                           CR_CHECKSUM_SHA256,
                                           cmd_options->groupfile_compression_type);
@@ -1156,8 +1156,8 @@ dump_merged_metadata(GHashTable *merged_hashtable,
     // Update info
 
     if (!cmd_options->noupdateinfo) {
-        update_info_rec = cr_new_repomdrecord(update_info_filename);
-        cr_fill_repomdrecord(update_info_rec, CR_CHECKSUM_SHA256);
+        update_info_rec = cr_repomd_record_new(update_info_filename);
+        cr_repomd_record_fill(update_info_rec, CR_CHECKSUM_SHA256);
     }
 
 
@@ -1165,8 +1165,8 @@ dump_merged_metadata(GHashTable *merged_hashtable,
 
     if (cmd_options->koji) {
         gchar *pkgorigins_path = g_strconcat(cmd_options->tmp_out_repo, "pkgorigins.gz", NULL);
-        pkgorigins_rec = cr_new_repomdrecord(pkgorigins_path);
-        cr_fill_repomdrecord(pkgorigins_rec, CR_CHECKSUM_SHA256);
+        pkgorigins_rec = cr_repomd_record_new(pkgorigins_path);
+        cr_repomd_record_fill(pkgorigins_rec, CR_CHECKSUM_SHA256);
         g_free(pkgorigins_path);
     }
 
@@ -1208,9 +1208,9 @@ dump_merged_metadata(GHashTable *merged_hashtable,
         remove(oth_db_filename);
 
         // Prepare repomd records
-        pri_db_rec = cr_new_repomdrecord(pri_db_c_filename);
-        fil_db_rec = cr_new_repomdrecord(fil_db_c_filename);
-        oth_db_rec = cr_new_repomdrecord(oth_db_c_filename);
+        pri_db_rec = cr_repomd_record_new(pri_db_c_filename);
+        fil_db_rec = cr_repomd_record_new(fil_db_c_filename);
+        oth_db_rec = cr_repomd_record_new(oth_db_c_filename);
 
         g_free(pri_db_filename);
         g_free(fil_db_filename);
@@ -1220,29 +1220,29 @@ dump_merged_metadata(GHashTable *merged_hashtable,
         g_free(fil_db_c_filename);
         g_free(oth_db_c_filename);
 
-        cr_fill_repomdrecord(pri_db_rec, CR_CHECKSUM_SHA256);
-        cr_fill_repomdrecord(fil_db_rec, CR_CHECKSUM_SHA256);
-        cr_fill_repomdrecord(oth_db_rec, CR_CHECKSUM_SHA256);
+        cr_repomd_record_fill(pri_db_rec, CR_CHECKSUM_SHA256);
+        cr_repomd_record_fill(fil_db_rec, CR_CHECKSUM_SHA256);
+        cr_repomd_record_fill(oth_db_rec, CR_CHECKSUM_SHA256);
     }
 
 
     // Add checksums into files names
 
-    cr_rename_repomdrecord_file(pri_xml_rec);
-    cr_rename_repomdrecord_file(fil_xml_rec);
-    cr_rename_repomdrecord_file(oth_xml_rec);
-    cr_rename_repomdrecord_file(pri_db_rec);
-    cr_rename_repomdrecord_file(fil_db_rec);
-    cr_rename_repomdrecord_file(oth_db_rec);
-    cr_rename_repomdrecord_file(groupfile_rec);
-    cr_rename_repomdrecord_file(compressed_groupfile_rec);
-    cr_rename_repomdrecord_file(update_info_rec);
-    cr_rename_repomdrecord_file(pkgorigins_rec);
+    cr_repomd_record_rename_file(pri_xml_rec);
+    cr_repomd_record_rename_file(fil_xml_rec);
+    cr_repomd_record_rename_file(oth_xml_rec);
+    cr_repomd_record_rename_file(pri_db_rec);
+    cr_repomd_record_rename_file(fil_db_rec);
+    cr_repomd_record_rename_file(oth_db_rec);
+    cr_repomd_record_rename_file(groupfile_rec);
+    cr_repomd_record_rename_file(compressed_groupfile_rec);
+    cr_repomd_record_rename_file(update_info_rec);
+    cr_repomd_record_rename_file(pkgorigins_rec);
 
 
     // Gen repomd.xml content
 
-    cr_Repomd repomd_obj = cr_new_repomd();
+    cr_Repomd repomd_obj = cr_repomd_new();
     cr_repomd_set_record(repomd_obj, pri_xml_rec,   "primary");
     cr_repomd_set_record(repomd_obj, fil_xml_rec,   "filelists");
     cr_repomd_set_record(repomd_obj, oth_xml_rec,   "other");
@@ -1254,9 +1254,9 @@ dump_merged_metadata(GHashTable *merged_hashtable,
     cr_repomd_set_record(repomd_obj, update_info_rec,"updateinfo");
     cr_repomd_set_record(repomd_obj, pkgorigins_rec, "origin");
 
-    char *repomd_xml = cr_generate_repomd_xml(repomd_obj);
+    char *repomd_xml = cr_repomd_xml_dump(repomd_obj);
 
-    cr_free_repomd(repomd_obj);
+    cr_repomd_free(repomd_obj);
 
     if (repomd_xml) {
         gchar *repomd_path = g_strconcat(cmd_options->tmp_out_repo, "repomd.xml", NULL);
index 7d5aceb..b356e73 100644 (file)
@@ -78,7 +78,7 @@ cr_free_distro(cr_Distro distro)
 
 
 cr_RepomdRecord
-cr_new_repomdrecord(const char *path)
+cr_repomd_record_new(const char *path)
 {
     cr_RepomdRecord md = (cr_RepomdRecord) g_malloc0(sizeof(*md));
     md->chunk = g_string_chunk_new(1024);
@@ -95,7 +95,7 @@ cr_new_repomdrecord(const char *path)
 
 
 void
-cr_free_repomdrecord(cr_RepomdRecord md)
+cr_repomd_record_free(cr_RepomdRecord md)
 {
     if (!md)
         return;
@@ -106,7 +106,7 @@ cr_free_repomdrecord(cr_RepomdRecord md)
 
 
 contentStat *
-get_compressed_content_stat(const char *filename, cr_ChecksumType checksum_type)
+cr_get_compressed_content_stat(const char *filename, cr_ChecksumType checksum_type)
 {
     if (!g_file_test(filename, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
         return NULL;
@@ -184,7 +184,7 @@ get_compressed_content_stat(const char *filename, cr_ChecksumType checksum_type)
 
 
 int
-cr_fill_repomdrecord(cr_RepomdRecord md, cr_ChecksumType checksum_type)
+cr_repomd_record_fill(cr_RepomdRecord md, cr_ChecksumType checksum_type)
 {
     const char *checksum_str;
     cr_ChecksumType checksum_t;
@@ -226,7 +226,7 @@ cr_fill_repomdrecord(cr_RepomdRecord md, cr_ChecksumType checksum_type)
         {
             // File compressed by supported algorithm
             contentStat *open_stat = NULL;
-            open_stat = get_compressed_content_stat(path, checksum_t);
+            open_stat = cr_get_compressed_content_stat(path, checksum_t);
             md->checksum_open_type = g_string_chunk_insert(md->chunk, checksum_str);
             md->checksum_open = g_string_chunk_insert(md->chunk, open_stat->checksum);
             if (!md->size_open) {
@@ -274,7 +274,7 @@ cr_fill_repomdrecord(cr_RepomdRecord md, cr_ChecksumType checksum_type)
 
 
 void
-cr_process_groupfile_repomdrecord(cr_RepomdRecord groupfile,
+cr_repomd_record_groupfile(cr_RepomdRecord groupfile,
                                   cr_RepomdRecord cgroupfile,
                                   cr_ChecksumType checksum_type,
                                   cr_CompressionType groupfile_compression)
@@ -395,7 +395,7 @@ cr_process_groupfile_repomdrecord(cr_RepomdRecord groupfile,
 
 
 void
-dump_data_items(xmlNodePtr root, cr_RepomdRecord md, const xmlChar *type)
+cr_repomd_dump_data_items(xmlNodePtr root, cr_RepomdRecord md, const xmlChar *type)
 {
     xmlNodePtr data, node;
     gchar str_buffer[STR_BUFFER_SIZE];
@@ -441,12 +441,19 @@ dump_data_items(xmlNodePtr root, cr_RepomdRecord md, const xmlChar *type)
 
 
 char *
-repomd_xml_dump(cr_Repomd repomd)
+cr_repomd_xml_dump(cr_Repomd repomd)
 {
     xmlDocPtr doc;
     xmlNodePtr root;
     GList *keys, *element;
 
+    // Set current time as revision if no revision specified
+
+    if (!repomd->revision) {
+        gchar *rev = g_strdup_printf("%ld", time(NULL));
+        cr_repomd_set_revision(repomd, rev);
+        g_free(rev);
+    }
 
     // Start of XML document
 
@@ -497,7 +504,7 @@ repomd_xml_dump(cr_Repomd repomd)
     for (element = keys; element; element = g_list_next(element)) {
         char *type = element->data;
         cr_RepomdRecord rec = g_hash_table_lookup(repomd->records, type);
-        dump_data_items(root, rec, (const xmlChar *) type);
+        cr_repomd_dump_data_items(root, rec, (const xmlChar *) type);
     }
 
     g_list_free(keys);
@@ -521,7 +528,7 @@ repomd_xml_dump(cr_Repomd repomd)
 
 
 void
-cr_rename_repomdrecord_file(cr_RepomdRecord md)
+cr_repomd_record_rename_file(cr_RepomdRecord md)
 {
     int x, len;
     gchar *location_prefix = NULL;
@@ -613,19 +620,19 @@ cr_rename_repomdrecord_file(cr_RepomdRecord md)
 
 
 cr_Repomd
-cr_new_repomd()
+cr_repomd_new()
 {
    cr_Repomd repomd = g_malloc0(sizeof(struct _cr_Repomd));
    repomd->records = g_hash_table_new_full(g_str_hash,
                                            g_str_equal,
                                            g_free,
-                                           (GDestroyNotify) cr_free_repomdrecord);
+                                           (GDestroyNotify) cr_repomd_record_free);
    return repomd;
 }
 
 
 void
-cr_free_repomd(cr_Repomd repomd)
+cr_repomd_free(cr_Repomd repomd)
 {
     if (!repomd) return;
     g_hash_table_destroy(repomd->records);
@@ -685,15 +692,3 @@ cr_repomd_add_content_tag(cr_Repomd repomd, const char *tag)
     repomd->content_tags = g_slist_append(repomd->content_tags, g_strdup(tag));
 }
 
-
-gchar *
-cr_generate_repomd_xml(cr_Repomd repomd)
-{
-    if (!repomd->revision) {
-        gchar *rev = g_strdup_printf("%ld", time(NULL));
-        cr_repomd_set_revision(repomd, rev);
-        g_free(rev);
-    }
-
-    return repomd_xml_dump(repomd);
-}
index 58405a5..5e3304a 100644 (file)
@@ -70,25 +70,25 @@ struct _cr_Repomd {
 /** Creates (alloc) new cr_RepomdRecord object
  * @param path                  path to the compressed file
  */
-cr_RepomdRecord cr_new_repomdrecord(const char *path);
+cr_RepomdRecord cr_repomd_record_new(const char *path);
 
 /** Destroy cr_RepomdRecord object.
  * NOTE: Do NOT use this function on objects attached to cr_Repomd
  * (by cr_repomd_set_record).
  * @param record                cr_RepomdRecord object
  */
-void cr_free_repomdrecord(cr_RepomdRecord record);
+void cr_repomd_record_free(cr_RepomdRecord record);
 
 /** Fill unfilled items in the cr_RepomdRecord (calculate checksums,
  * get file size before/after compression, etc.).
- * Note: For groupfile you shoud use cr_process_groupfile_repomdrecord function.
+ * Note: For groupfile you shoud use cr_repomd_record_groupfile function.
  * @param record                cr_RepomdRecord object
  * @param checksum_type         type of checksum to use
  */
-int cr_fill_repomdrecord(cr_RepomdRecord record,
+int cr_repomd_record_fill(cr_RepomdRecord record,
                          cr_ChecksumType checksum_type);
 
-/** Analogue of cr_fill_repomdrecord but for groupfile.
+/** Analogue of cr_repomd_record_fill but for groupfile.
  * Groupfile must be set with the path to existing non compressed groupfile.
  * Compressed group file will be created and compressed_groupfile record
  * updated.
@@ -98,7 +98,7 @@ int cr_fill_repomdrecord(cr_RepomdRecord record,
  * @param checksum_type         type of checksums
  * @param compression           type of compression
  */
-void cr_process_groupfile_repomdrecord(cr_RepomdRecord groupfile,
+void cr_repomd_record_groupfile(cr_RepomdRecord groupfile,
                                        cr_RepomdRecord compressed_groupfile,
                                        cr_ChecksumType checksum_type,
                                        cr_CompressionType compression);
@@ -106,11 +106,11 @@ void cr_process_groupfile_repomdrecord(cr_RepomdRecord groupfile,
 /** Add a hash as prefix to the filename.
  * @param record                cr_RepomdRecord of file to be renamed
  */
-void cr_rename_repomdrecord_file(cr_RepomdRecord record);
+void cr_repomd_record_rename_file(cr_RepomdRecord record);
 
 /** Create new empty cr_Repomd object wich represents content of repomd.xml.
  */
-cr_Repomd cr_new_repomd();
+cr_Repomd cr_repomd_new();
 
 /** Set cr_Repomd record into cr_Repomd object.
  * @param repomd                cr_Repomd object
@@ -151,14 +151,15 @@ void cr_repomd_add_content_tag(cr_Repomd repomd, const char *tag);
 /** Frees cr_Repomd object and all its cr_RepomdRecord objects
  * @param repomd                cr_Repomd object
  */
-void cr_free_repomd(cr_Repomd repomd);
+void cr_repomd_free(cr_Repomd repomd);
 
 
 /** Generate repomd.xml content.
+ * Don't forget to use cr_xml_dump_init() before call this function.
  * @param repomd                cr_Repomd object
  * @return                      string with repomd.xml content
  */
-gchar *cr_generate_repomd_xml(cr_Repomd repomd);
+gchar *cr_repomd_xml_dump(cr_Repomd repomd);
 
 /** @} */