// XML
- pri_xml_rec->checksum_open = cr_safe_string_chunk_insert(
- pri_xml_rec->chunk,
- pri_stat->checksum);
- pri_xml_rec->checksum_open_type = cr_safe_string_chunk_insert(
- pri_xml_rec->chunk,
- cr_checksum_name_str(pri_stat->checksum_type));
- pri_xml_rec->size_open = pri_stat->size;
-
- fil_xml_rec->checksum_open = cr_safe_string_chunk_insert(
- fil_xml_rec->chunk,
- fil_stat->checksum);
- fil_xml_rec->checksum_open_type = cr_safe_string_chunk_insert(
- fil_xml_rec->chunk,
- cr_checksum_name_str(fil_stat->checksum_type));
- fil_xml_rec->size_open = fil_stat->size;
-
- oth_xml_rec->checksum_open = cr_safe_string_chunk_insert(
- oth_xml_rec->chunk,
- oth_stat->checksum);
- oth_xml_rec->checksum_open_type = cr_safe_string_chunk_insert(
- oth_xml_rec->chunk,
- cr_checksum_name_str(oth_stat->checksum_type));
- oth_xml_rec->size_open = oth_stat->size;
+ cr_repomd_record_load_contentstat(pri_xml_rec, pri_stat);
+ cr_repomd_record_load_contentstat(fil_xml_rec, fil_stat);
+ cr_repomd_record_load_contentstat(oth_xml_rec, oth_stat);
cr_repomd_record_fill(pri_xml_rec, cmd_options->checksum_type, NULL);
cr_repomd_record_fill(fil_xml_rec, cmd_options->checksum_type, NULL);
// XML
- pri_xml_rec->checksum_open = cr_safe_string_chunk_insert(
- pri_xml_rec->chunk,
- pri_stat->checksum);
- pri_xml_rec->checksum_open_type = cr_safe_string_chunk_insert(
- pri_xml_rec->chunk,
- cr_checksum_name_str(pri_stat->checksum_type));
- pri_xml_rec->size_open = pri_stat->size;
-
- fil_xml_rec->checksum_open = cr_safe_string_chunk_insert(
- fil_xml_rec->chunk,
- fil_stat->checksum);
- fil_xml_rec->checksum_open_type = cr_safe_string_chunk_insert(
- fil_xml_rec->chunk,
- cr_checksum_name_str(fil_stat->checksum_type));
- fil_xml_rec->size_open = fil_stat->size;
-
- oth_xml_rec->checksum_open = cr_safe_string_chunk_insert(
- oth_xml_rec->chunk,
- oth_stat->checksum);
- oth_xml_rec->checksum_open_type = cr_safe_string_chunk_insert(
- oth_xml_rec->chunk,
- cr_checksum_name_str(oth_stat->checksum_type));
- oth_xml_rec->size_open = oth_stat->size;
+ cr_repomd_record_load_contentstat(pri_xml_rec, pri_stat);
+ cr_repomd_record_load_contentstat(fil_xml_rec, fil_stat);
+ cr_repomd_record_load_contentstat(oth_xml_rec, oth_stat);
cr_repomd_record_fill(pri_xml_rec, CR_CHECKSUM_SHA256, NULL);
cr_repomd_record_fill(fil_xml_rec, CR_CHECKSUM_SHA256, NULL);
#include "repomdrecord-py.h"
#include "exception-py.h"
#include "typeconversion.h"
+#include "contentstat-py.h"
typedef struct {
PyObject_HEAD
Py_RETURN_NONE;
}
+static PyObject *
+load_contentstat(_RepomdRecordObject *self, PyObject *args)
+{
+ PyObject *contentstat;
+
+ if (!PyArg_ParseTuple(args, "O!:load_contentstat",
+ &ContentStat_Type,
+ &contentstat))
+ return NULL;
+
+ if (check_RepomdRecordStatus(self))
+ return NULL;
+
+ cr_repomd_record_load_contentstat(self->record,
+ ContentStat_FromPyObject(contentstat));
+ Py_RETURN_NONE;
+}
+
static struct PyMethodDef repomdrecord_methods[] = {
{"copy", (PyCFunction)copy_repomdrecord, METH_NOARGS, NULL},
{"fill", (PyCFunction)fill, METH_VARARGS, NULL},
{"compress_and_fill", (PyCFunction)compress_and_fill, METH_VARARGS, NULL},
{"rename_file", (PyCFunction)rename_file, METH_NOARGS, NULL},
+ {"load_contentstat", (PyCFunction)load_contentstat, METH_VARARGS, NULL},
{NULL} /* sentinel */
};
return CRE_OK;
}
+void
+cr_repomd_record_load_contentstat(cr_RepomdRecord *record,
+ cr_ContentStat *stats)
+{
+ if (!stats)
+ return;
+
+ record->checksum_open = cr_safe_string_chunk_insert(record->chunk,
+ stats->checksum);
+ record->checksum_open_type = cr_safe_string_chunk_insert(record->chunk,
+ cr_checksum_name_str(stats->checksum_type));
+ record->size_open = stats->size;
+}
+
cr_Repomd *
cr_repomd_new()
{
/** Fill unfilled items in the cr_RepomdRecord (calculate checksums,
* get file size before/after compression, etc.).
- * Note: For groupfile you shoud use cr_repomd_record_compress_and_fill
- * function.
+ * Note: If checksum_open, checksum_open_type and size_open are filed
+ * then their calculation will be skiped. This items could be filled
+ * directly on our own or use function for load them from a cr_ContentStat.
+ * If no open stats are supplied, then this function has to decompress
+ * the file for the open checksum calculation.
* @param record cr_RepomdRecord object
* @param checksum_type type of checksum to use
* @param err GError **
*/
int cr_repomd_record_rename_file(cr_RepomdRecord *record, GError **err);
+/** Load the open stats (checksum_open, checksum_open_type and size_open)
+ * from the cr_ContentStat object.
+ * @param record cr_RepomdRecord
+ * @param stats cr_ContentStat
+ */
+void cr_repomd_record_load_contentstat(cr_RepomdRecord *record,
+ cr_ContentStat *stats);
+
/** Create new empty cr_Repomd object wich represents content of repomd.xml.
*/
cr_Repomd *cr_repomd_new();
sorted(['10091f8e2e235ae875cb18c91c443891c7f1a599d41f44d518e8af759a6c8109-primary.xml.gz',
'b33fc63178d852333a826385bc15d9b72cb6658be7fb927ec28c4e40b5d426fb-primary.xml']))
+ def test_repomdrecord_load_contentstat(self):
+ rec = cr.RepomdRecord("primary", None)
+ self.assertTrue(rec)
+
+ stat = cr.ContentStat(cr.SHA256)
+ stat.checksum = "foobar"
+ stat.checksum_type = cr.SHA256
+ stat.size = 123
+
+ self.assertEqual(rec.checksum_open, None)
+ self.assertEqual(rec.checksum_open_type, None)
+ self.assertEqual(rec.size, 0)
+
+ rec.load_contentstat(stat);
+
+ self.assertEqual(rec.checksum_open, "foobar")
+ self.assertEqual(rec.checksum_open_type, "sha256")
+ self.assertEqual(rec.size_open, 123)
+