From 4bddb6d1c043e5b3a9ebdf1ed0114c655be9a589 Mon Sep 17 00:00:00 2001 From: Tomas Mlcoch Date: Wed, 16 Jul 2014 16:56:21 +0200 Subject: [PATCH] xml_file: Support for prestodelta.xml format --- src/xml_file.c | 22 ++++++++++++++++++++-- src/xml_file.h | 21 +++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/xml_file.c b/src/xml_file.c index 4230a5b..6732da9 100644 --- a/src/xml_file.c +++ b/src/xml_file.c @@ -35,10 +35,12 @@ CR_XML_FILELISTS_NS"\" packages=\"%d\">\n" #define XML_OTHER_HEADER XML_HEADER"\n" +#define XML_PRESTODELTA_HEADER XML_HEADER"\n" #define XML_PRIMARY_FOOTER "" #define XML_FILELISTS_FOOTER "" #define XML_OTHER_FOOTER "" +#define XML_PRESTODELTA_FOOTER "" cr_XmlFile * cr_xmlfile_sopen(const char *filename, @@ -85,10 +87,20 @@ int cr_xmlfile_set_num_of_pkgs(cr_XmlFile *f, long num, GError **err) { assert(f); - assert(f->header == 0); - assert(num >= 0); assert(!err || *err == NULL); + if (f->header != 0) { + g_set_error(err, CR_XML_FILE_ERROR, CRE_BADARG, + "Header was already written"); + return CRE_BADARG; + } + + if (num < 0) { + g_set_error(err, CR_XML_FILE_ERROR, CRE_BADARG, + "The number must be a positive integer number"); + return CRE_BADARG; + } + f->pkgs = num; return CRE_OK; } @@ -113,6 +125,9 @@ cr_xmlfile_write_xml_header(cr_XmlFile *f, GError **err) case CR_XMLFILE_OTHER: xml_header = XML_OTHER_HEADER; break; + case CR_XMLFILE_PRESTODELTA: + xml_header = XML_PRESTODELTA_HEADER; + break; default: g_critical("%s: Bad file type", __func__); assert(0); @@ -151,6 +166,9 @@ cr_xmlfile_write_xml_footer(cr_XmlFile *f, GError **err) case CR_XMLFILE_OTHER: xml_footer = XML_OTHER_FOOTER; break; + case CR_XMLFILE_PRESTODELTA: + xml_footer = XML_PRESTODELTA_FOOTER; + break; default: g_critical("%s: Bad file type", __func__); assert(0); diff --git a/src/xml_file.h b/src/xml_file.h index 6e5a6de..588d34d 100644 --- a/src/xml_file.h +++ b/src/xml_file.h @@ -39,6 +39,7 @@ typedef enum { CR_XMLFILE_PRIMARY, /*!< primary.xml */ CR_XMLFILE_FILELISTS, /*!< filelists.xml */ CR_XMLFILE_OTHER, /*!< other.xml */ + CR_XMLFILE_PRESTODELTA, /*!< prestodelta.xml */ CR_XMLFILE_SENTINEL, /*!< sentinel of the list */ } cr_XmlFileType; @@ -114,6 +115,26 @@ typedef struct { #define cr_xmlfile_sopen_other(FILENAME, COMTYPE, STAT, ERR) \ cr_xmlfile_sopen(FILENAME, CR_XMLFILE_OTHER, COMTYPE, STAT, ERR) +/** Open a new prestodelta XML file. + * @param FILENAME Filename. + * @param COMTYPE Type of used compression. + * @param ERR GError ** + * @return Opened cr_XmlFile or NULL on error + */ +#define cr_xmlfile_open_prestodelta(FILENAME, COMTYPE, ERR) \ + cr_xmlfile_open(FILENAME, CR_XMLFILE_PRESTODELTA, COMTYPE, ERR) + +/** Open a new prestodelta XML file. + * @param FILENAME Filename. + * @param COMTYPE Type of compression. + * @param STAT cr_ContentStat object or NULL. + * @param ERR GError ** + * @return Opened cr_XmlFile or NULL on error + */ +#define cr_xmlfile_sopen_prestodelta(FILENAME, COMTYPE, STAT, ERR) \ + cr_xmlfile_sopen(FILENAME, CR_XMLFILE_PRESTODELTA, COMTYPE, STAT, ERR) + + /** Open a new XML file with stats. * Note: Opened file must not exists! This function cannot * open existing file!. -- 2.7.4