Add errror module with error code enumeration and error domains.
Add GError** as param to some functions in xml_dump and repomd modules.
This improved interface is aimed to better (more informative and verbose)
error messages for programs using this library and createrepo_c python
bindings.
SET (createrepo_c_SRCS
compression_wrapper.c
+ error.c
load_metadata.c
locate_metadata.c
misc.c
compression_wrapper.h
constants.h
createrepo_c.h
+ error.h
load_metadata.h
locate_metadata.h
misc.h
g_warning("Cannot read package: %s", task->full_path);
goto task_cleanup;
}
- res = cr_xml_dump(pkg);
+ res = cr_xml_dump(pkg, NULL);
} else {
// Just gen XML from old loaded metadata
pkg = md;
- res = cr_xml_dump(md);
+ res = cr_xml_dump(md, NULL);
}
g_mutex_lock(udata->mutex_buffer);
// XML
- 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);
+ cr_repomd_record_fill(pri_xml_rec, cmd_options->checksum_type, NULL);
+ cr_repomd_record_fill(fil_xml_rec, cmd_options->checksum_type, NULL);
+ cr_repomd_record_fill(oth_xml_rec, cmd_options->checksum_type, NULL);
// Groupfile
cr_repomd_record_groupfile(groupfile_rec,
compressed_groupfile_rec,
cmd_options->checksum_type,
- groupfile_compression);
+ groupfile_compression,
+ NULL);
}
if (updateinfo) {
updateinfo_rec = cr_repomd_record_new(updateinfo);
- cr_repomd_record_fill(updateinfo_rec, cmd_options->checksum_type);
+ cr_repomd_record_fill(updateinfo_rec, cmd_options->checksum_type, NULL);
}
fil_db_rec = cr_repomd_record_new(fil_db_name);
oth_db_rec = cr_repomd_record_new(oth_db_name);
- 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);
+ cr_repomd_record_fill(pri_db_rec, cmd_options->checksum_type, NULL);
+ cr_repomd_record_fill(fil_db_rec, cmd_options->checksum_type, NULL);
+ cr_repomd_record_fill(oth_db_rec, cmd_options->checksum_type, NULL);
g_free(pri_db_name);
g_free(fil_db_name);
// Add checksums into files names
if (cmd_options->unique_md_filenames) {
- 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);
+ cr_repomd_record_rename_file(pri_xml_rec, NULL);
+ cr_repomd_record_rename_file(fil_xml_rec, NULL);
+ cr_repomd_record_rename_file(oth_xml_rec, NULL);
+ cr_repomd_record_rename_file(pri_db_rec, NULL);
+ cr_repomd_record_rename_file(fil_db_rec, NULL);
+ cr_repomd_record_rename_file(oth_db_rec, NULL);
+ cr_repomd_record_rename_file(groupfile_rec, NULL);
+ cr_repomd_record_rename_file(compressed_groupfile_rec, NULL);
+ cr_repomd_record_rename_file(updateinfo_rec, NULL);
}
#include <glib.h>
#include "compression_wrapper.h"
#include "constants.h"
+#include "error.h"
#include "load_metadata.h"
#include "locate_metadata.h"
#include "misc.h"
--- /dev/null
+/* createrepo_c - Library of routines for manipulation with repodata
+ * Copyright (C) 2013 Tomas Mlcoch
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ * USA.
+ */
+
+#include "error.h"
+
+GQuark
+cr_db_error_quark(void)
+{
+ return g_quark_from_static_string("cr_db_error");
+}
+
+GQuark
+cr_xml_dump_primary_error_quark(void)
+{
+ return g_quark_from_static_string("cr_xml_dump_primary_error");
+}
+
+GQuark
+cr_xml_dump_filelists_error_quark(void)
+{
+ return g_quark_from_static_string("cr_xml_dump_filelists_error");
+}
+
+GQuark
+cr_xml_dump_other_error_quark(void)
+{
+ return g_quark_from_static_string("cr_xml_dump_other_error");
+}
+
+GQuark
+cr_repomd_record_error_quark(void)
+{
+ return g_quark_from_static_string("cr_repomd_record_error");
+}
+
+GQuark
+cr_repomd_error_quark(void)
+{
+ return g_quark_from_static_string("cr_repomd_error");
+}
+
+GQuark
+cr_checksum_error_quark(void)
+{
+ return g_quark_from_static_string("cr_checksum_error");
+}
+
--- /dev/null
+/* createrepo_c - Library of routines for manipulation with repodata
+ * Copyright (C) 2013 Tomas Mlcoch
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ * USA.
+ */
+
+#ifndef __C_CREATEREPOLIB_ERROR_H__
+#define __C_CREATEREPOLIB_ERROR_H__
+
+#include <glib.h>
+
+typedef enum {
+ CRE_OK, /*!<
+ No error */
+ CRE_IO, /*!<
+ Input/Output error (cannot open file, etc.) */
+ CRE_MEMORY, /*!<
+ Cannot allocate memory */
+ CRE_STAT, /*!<
+ Stat() call failed */
+ CRE_DB, /*!<
+ A database error */
+ CRE_BADARG, /*!<
+ At least one argument of function is bad or non complete */
+ CRE_NOFILE, /*!<
+ File doesn't exists */
+ CRE_UNKNOWNCHECKSUMTYPE, /*!<
+ Unknown/Unsupported checksum type */
+} cr_Error;
+
+#define CR_DB_ERROR cr_db_error_quark()
+#define CR_XML_DUMP_PRIMARY_ERROR cr_xml_dump_primary_error_quark()
+#define CR_XML_DUMP_FILELISTS_ERROR cr_xml_dump_filelists_error_quark()
+#define CR_XML_DUMP_OTHER_ERROR cr_xml_dump_other_error_quark()
+#define CR_REPOMD_ERROR cr_repomd_error_quark()
+#define CR_REPOMD_RECORD_ERROR cr_repomd_record_error_quark()
+#define CR_CHECKSUM_ERROR cr_checksum_error_quark()
+
+GQuark cr_db_error_quark(void);
+GQuark cr_xml_dump_primary_error_quark(void);
+GQuark cr_xml_dump_filelists_error_quark(void);
+GQuark cr_xml_dump_other_error_quark(void);
+GQuark cr_repomd_error_quark(void);
+GQuark cr_repomd_record_error_quark(void);
+GQuark cr_checksum_error(void);
+
+#endif
cr_Package *pkg;
pkg = (cr_Package *) element->data;
- res = cr_xml_dump(pkg);
+ res = cr_xml_dump(pkg, NULL);
cr_puts(pri_f, (const char *) res.primary);
cr_puts(fil_f, (const char *) res.filelists);
// XML
- 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);
+ cr_repomd_record_fill(pri_xml_rec, CR_CHECKSUM_SHA256, NULL);
+ cr_repomd_record_fill(fil_xml_rec, CR_CHECKSUM_SHA256, NULL);
+ cr_repomd_record_fill(oth_xml_rec, CR_CHECKSUM_SHA256, NULL);
// Groupfile
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);
+ compressed_groupfile_rec,
+ CR_CHECKSUM_SHA256,
+ cmd_options->groupfile_compression_type,
+ NULL);
}
if (!cmd_options->noupdateinfo) {
update_info_rec = cr_repomd_record_new(update_info_filename);
- cr_repomd_record_fill(update_info_rec, CR_CHECKSUM_SHA256);
+ cr_repomd_record_fill(update_info_rec, CR_CHECKSUM_SHA256, NULL);
}
if (cmd_options->koji) {
gchar *pkgorigins_path = g_strconcat(cmd_options->tmp_out_repo, "pkgorigins.gz", NULL);
pkgorigins_rec = cr_repomd_record_new(pkgorigins_path);
- cr_repomd_record_fill(pkgorigins_rec, CR_CHECKSUM_SHA256);
+ cr_repomd_record_fill(pkgorigins_rec, CR_CHECKSUM_SHA256, NULL);
g_free(pkgorigins_path);
}
g_free(fil_db_c_filename);
g_free(oth_db_c_filename);
- 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);
+ cr_repomd_record_fill(pri_db_rec, CR_CHECKSUM_SHA256, NULL);
+ cr_repomd_record_fill(fil_db_rec, CR_CHECKSUM_SHA256, NULL);
+ cr_repomd_record_fill(oth_db_rec, CR_CHECKSUM_SHA256, NULL);
}
// Add checksums into files names
if (cmd_options->unique_md_filenames) {
- 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);
+ cr_repomd_record_rename_file(pri_xml_rec, NULL);
+ cr_repomd_record_rename_file(fil_xml_rec, NULL);
+ cr_repomd_record_rename_file(oth_xml_rec, NULL);
+ cr_repomd_record_rename_file(pri_db_rec, NULL);
+ cr_repomd_record_rename_file(fil_db_rec, NULL);
+ cr_repomd_record_rename_file(oth_db_rec, NULL);
+ cr_repomd_record_rename_file(groupfile_rec, NULL);
+ cr_repomd_record_rename_file(compressed_groupfile_rec, NULL);
+ cr_repomd_record_rename_file(update_info_rec, NULL);
+ cr_repomd_record_rename_file(pkgorigins_rec, NULL);
}
#define _XOPEN_SOURCE 500
#include <glib.h>
+#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <curl/curl.h>
#include <rpm/rpmlib.h>
+#include "error.h"
#include "logging.h"
#include "constants.h"
#include "misc.h"
char *
-cr_compute_file_checksum(const char *filename, cr_ChecksumType type)
+cr_compute_file_checksum(const char *filename,
+ cr_ChecksumType type,
+ GError **err)
{
GChecksumType gchecksumtype;
- if (!filename) {
- g_debug("%s: Filename param is NULL", __func__);
- return NULL;
- }
+ assert(filename);
+ assert(!err || *err == NULL);
// Check if file exists and if it is a regular file (not a directory)
if (!g_file_test(filename, (G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR))) {
g_debug("%s: File %s doesn't exists", __func__, filename);
+ g_set_error(err, CR_CHECKSUM_ERROR, CRE_NOFILE,
+ "File %s doesn't exists", filename);
return NULL;
}
break;
default:
g_debug("%s: Unknown checksum type", __func__);
+ g_set_error(err, CR_CHECKSUM_ERROR, CRE_UNKNOWNCHECKSUMTYPE,
+ "Unknown checksum type: %d", type);
return NULL;
};
if (!fp) {
g_critical("%s: Cannot open %s (%s)", __func__, filename,
strerror(errno));
+ g_set_error(err, CR_CHECKSUM_ERROR, CRE_IO,
+ "Cannot open %s: %s", filename, strerror(errno));
return NULL;
}
}
}
+ if (ferror(fp)) {
+ g_set_error(err, CR_CHECKSUM_ERROR, CRE_IO,
+ "fread call faied: %s", strerror(errno));
+ fclose(fp);
+ g_checksum_free(checksum);
+ return NULL;
+ }
+
fclose(fp);
if (!checksum_str) {
g_critical("%s: Cannot get checksum %s (low memory?)", __func__,
filename);
+ g_set_error(err, CR_CHECKSUM_ERROR, CRE_MEMORY,
+ "Cannot calculate checksum (low memory?)");
}
return checksum_str;
/** Compute file checksum.
* @param filename filename
* @param type type of checksum
+ * @param err GError **
* @return malloced null terminated string with checksum
* or NULL on error
*/
-char *cr_compute_file_checksum(const char *filename, cr_ChecksumType type);
+char *cr_compute_file_checksum(const char *filename,
+ cr_ChecksumType type,
+ GError **err);
/** Header range
*/
changelog_limit, hdr_start, hdr_end);
struct cr_XmlStruct result;
- result.primary = cr_xml_dump_primary(pkg);
- result.filelists = cr_xml_dump_filelists(pkg);
- result.other = cr_xml_dump_other(pkg);
+ result.primary = cr_xml_dump_primary(pkg, NULL);
+ result.filelists = cr_xml_dump_filelists(pkg, NULL);
+ result.other = cr_xml_dump_other(pkg, NULL);
// Cleanup
cr_package_free(pkg);
#include "logging.h"
#include "constants.h"
#include "parsehdr.h"
-#include "xml_dump.h"
#include "misc.h"
#include "parsehdr.h"
// Compute checksum
- char *checksum = cr_compute_file_checksum(filename, checksum_type);
+ char *checksum = cr_compute_file_checksum(filename, checksum_type, NULL);
// Get header range
// Compute checksum
- char *checksum = cr_compute_file_checksum(filename, checksum_type);
+ char *checksum = cr_compute_file_checksum(filename, checksum_type, NULL);
// Get header range
fill(_RepomdRecordObject *self, PyObject *args)
{
int checksum_type;
+ GError *err = NULL;
+
if (!PyArg_ParseTuple(args, "i:fill", &checksum_type))
return NULL;
+
if (check_RepomdRecordStatus(self))
return NULL;
- cr_repomd_record_fill(self->record, checksum_type);
+
+ cr_repomd_record_fill(self->record, checksum_type, &err);
+ if (err) {
+ PyErr_Format(CrErr_Exception, "fill method failed: %s", err->message);
+ g_clear_error(&err);
+ return NULL;
+ }
+
Py_RETURN_NONE;
}
{
int checksum_type, compression_type;
PyObject *compressed_repomdrecord;
+ GError *err = NULL;
+
if (!PyArg_ParseTuple(args, "O!ii:fill",
&RepomdRecord_Type,
&compressed_repomdrecord,
&checksum_type,
&compression_type))
return NULL;
+
if (check_RepomdRecordStatus(self))
return NULL;
+
cr_repomd_record_groupfile(self->record,
RepomdRecord_FromPyObject(compressed_repomdrecord),
checksum_type,
- compression_type);
+ compression_type,
+ &err);
+ if (err) {
+ PyErr_Format(CrErr_Exception, "compress_and_fill method failed: %s", err->message);
+ g_clear_error(&err);
+ return NULL;
+ }
+
Py_RETURN_NONE;
}
static PyObject *
rename_file(_RepomdRecordObject *self, void *nothing)
{
+ GError *err = NULL;
+
CR_UNUSED(nothing);
- cr_repomd_record_rename_file(self->record);
+
+ cr_repomd_record_rename_file(self->record, &err);
+ if (err) {
+ PyErr_Format(CrErr_Exception, "rename_file method failed: %s", err->message);
+ g_clear_error(&err);
+ return NULL;
+ }
+
Py_RETURN_NONE;
}
PyObject *
py_xml_dump_primary(PyObject *self, PyObject *args)
{
- CR_UNUSED(self);
PyObject *py_pkg, *py_str;
char *xml;
+ GError *err = NULL;
+
+ CR_UNUSED(self);
+
if (!PyArg_ParseTuple(args, "O!:py_xml_dump_primary", &Package_Type, &py_pkg))
return NULL;
- xml = cr_xml_dump_primary(Package_FromPyObject(py_pkg));
+
+ xml = cr_xml_dump_primary(Package_FromPyObject(py_pkg), &err);
+ if (err) {
+ PyErr_Format(CrErr_Exception, "Error while dumping primary xml: %s",
+ err->message);
+ g_clear_error(&err);
+ return NULL;
+ }
+
py_str = PyStringOrNone_FromString(xml);
free(xml);
return py_str;
PyObject *
py_xml_dump_filelists(PyObject *self, PyObject *args)
{
- CR_UNUSED(self);
PyObject *py_pkg, *py_str;
char *xml;
+ GError *err = NULL;
+
+ CR_UNUSED(self);
+
if (!PyArg_ParseTuple(args, "O!:py_xml_dump_filelists", &Package_Type, &py_pkg))
return NULL;
- xml = cr_xml_dump_filelists(Package_FromPyObject(py_pkg));
+
+ xml = cr_xml_dump_filelists(Package_FromPyObject(py_pkg), &err);
+ if (err) {
+ PyErr_Format(CrErr_Exception, "Error while dumping filelists xml: %s",
+ err->message);
+ g_clear_error(&err);
+ return NULL;
+ }
+
py_str = PyStringOrNone_FromString(xml);
free(xml);
return py_str;
PyObject *
py_xml_dump_other(PyObject *self, PyObject *args)
{
- CR_UNUSED(self);
PyObject *py_pkg, *py_str;
char *xml;
+ GError *err = NULL;
+
+ CR_UNUSED(self);
+
if (!PyArg_ParseTuple(args, "O!:py_xml_dump_other", &Package_Type, &py_pkg))
return NULL;
- xml = cr_xml_dump_other(Package_FromPyObject(py_pkg));
+
+ xml = cr_xml_dump_other(Package_FromPyObject(py_pkg), &err);
+ if (err) {
+ PyErr_Format(CrErr_Exception, "Error while dumping other xml: %s",
+ err->message);
+ g_clear_error(&err);
+ return NULL;
+ }
+
py_str = PyStringOrNone_FromString(xml);
free(xml);
return py_str;
PyObject *
py_xml_dump(PyObject *self, PyObject *args)
{
- CR_UNUSED(self);
PyObject *py_pkg, *tuple;
struct cr_XmlStruct xml_res;
+ GError *err = NULL;
+
+ CR_UNUSED(self);
if (!PyArg_ParseTuple(args, "O!:py_xml_dump", &Package_Type, &py_pkg))
return NULL;
- if ((tuple = PyTuple_New(3)) == NULL)
+
+ xml_res = cr_xml_dump(Package_FromPyObject(py_pkg), &err);
+ if (err) {
+ PyErr_Format(CrErr_Exception, "Error while dumping xml: %s",
+ err->message);
+ g_clear_error(&err);
return NULL;
+ }
- xml_res = cr_xml_dump(Package_FromPyObject(py_pkg));
+ if ((tuple = PyTuple_New(3)) == NULL) {
+ free(xml_res.primary);
+ free(xml_res.filelists);
+ free(xml_res.other);
+ return NULL;
+ }
PyTuple_SetItem(tuple, 0, PyStringOrNone_FromString(xml_res.primary));
PyTuple_SetItem(tuple, 1, PyStringOrNone_FromString(xml_res.filelists));
*/
#include <glib.h>
+#include <errno.h>
#include <string.h>
#include <sys/stat.h>
#include <time.h>
#include <assert.h>
#include <libxml/encoding.h>
#include <libxml/xmlwriter.h>
+#include "error.h"
#include "logging.h"
#include "misc.h"
#include "repomd.h"
#define XML_ENC "UTF-8"
#define FORMAT_XML 1
-#define REPOMD_OK 0
-#define REPOMD_ERR 1
+#define REPOMD_OK 0 // XXX
+#define REPOMD_ERR 1 // XXX
typedef struct _contentStat {
contentStat *
-cr_get_compressed_content_stat(const char *filename, cr_ChecksumType checksum_type)
+cr_get_compressed_content_stat(const char *filename,
+ cr_ChecksumType checksum_type,
+ GError **err)
{
+ assert(filename);
+ assert(!err || *err == NULL);
+
if (!g_file_test(filename, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
+ g_set_error(err, CR_REPOMD_RECORD_ERROR, CRE_NOFILE,
+ "File doesn't exists");
return NULL;
}
CR_FILE *cwfile;
if (!(cwfile = cr_open(filename, CR_CW_MODE_READ, CR_CW_AUTO_DETECT_COMPRESSION))) {
+ g_set_error(err, CR_REPOMD_RECORD_ERROR, CRE_IO,
+ "Cannot open a file");
return NULL;
}
break;
default:
g_critical("%s: Unknown checksum type", __func__);
+ g_set_error(err, CR_REPOMD_RECORD_ERROR, CRE_UNKNOWNCHECKSUMTYPE,
+ "Unknown checksum type: %d", checksum_type);
return NULL;
};
GChecksum *checksum = g_checksum_new(gchecksumtype);
if (!checksum) {
g_critical("%s: g_checksum_new() failed", __func__);
+ g_set_error(err, CR_REPOMD_RECORD_ERROR, CRE_UNKNOWNCHECKSUMTYPE,
+ "g_checksum_new() failed - Unknown checksum type");
return NULL;
}
if (readed == CR_CW_ERR) {
g_debug("%s: Error while read compressed file: %s",
__func__, filename);
+ g_set_error(err, CR_REPOMD_RECORD_ERROR, CRE_IO,
+ "Error while read compressed file");
break;
}
g_checksum_update (checksum, buffer, readed);
size += readed;
} while (readed == BUFFER_SIZE);
+ if (readed == CR_CW_ERR)
+ return NULL;
// Create result structure
if (result) {
result->checksum = g_strdup(g_checksum_get_string(checksum));
result->size = size;
+ } else {
+ g_set_error(err, CR_REPOMD_RECORD_ERROR, CRE_MEMORY,
+ "Cannot allocate memory");
}
int
-cr_repomd_record_fill(cr_RepomdRecord md, cr_ChecksumType checksum_type)
+cr_repomd_record_fill(cr_RepomdRecord md,
+ cr_ChecksumType checksum_type,
+ GError **err)
{
const char *checksum_str;
cr_ChecksumType checksum_t;
gchar *path;
+ GError *tmp_err = NULL;
- if (!md || !(md->location_real) || !strlen(md->location_real)) {
- // Nothing to do
- return REPOMD_ERR;
+ assert(!err || *err == NULL);
+ assert(md);
+
+ if (!(md->location_real) || !strlen(md->location_real)) {
+ g_set_error(err, CR_REPOMD_RECORD_ERROR, CRE_BADARG,
+ "Empty locations in repomd record object.");
+ return CRE_BADARG;
}
path = md->location_real;
if (!g_file_test(path, G_FILE_TEST_EXISTS|G_FILE_TEST_IS_REGULAR)) {
// File doesn't exists
g_warning("%s: File %s doesn't exists", __func__, path);
- return REPOMD_ERR;
+ g_set_error(err, CR_REPOMD_RECORD_ERROR, CRE_NOFILE,
+ "File %s doesn't exists", path);
+ return CRE_NOFILE;
}
if (!md->checksum_type || !md->checksum) {
gchar *chksum;
+
+ chksum = cr_compute_file_checksum(path, checksum_t, &tmp_err);
+ if (tmp_err) {
+ g_propagate_prefixed_error(err, tmp_err,
+ "Error while checksum calculation of %s:", path);
+ return (*err)->code;
+ }
+
md->checksum_type = g_string_chunk_insert(md->chunk, checksum_str);
- chksum = cr_compute_file_checksum(path, checksum_t);
md->checksum = g_string_chunk_insert(md->chunk, chksum);
g_free(chksum);
}
{
// File compressed by supported algorithm
contentStat *open_stat = NULL;
- open_stat = cr_get_compressed_content_stat(path, checksum_t);
+
+ open_stat = cr_get_compressed_content_stat(path, checksum_t, &tmp_err);
+ if (tmp_err) {
+ g_propagate_prefixed_error(err, tmp_err,
+ "Error while computing stat of compressed content of %s:",
+ path);
+ return (*err)->code;
+ }
+
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) {
+ if (!md->size_open)
md->size_open = open_stat->size;
- }
g_free(open_stat->checksum);
g_free(open_stat);
} else {
}
} else {
g_warning("%s: Stat on file \"%s\" failed", __func__, path);
+ g_set_error(err, CR_REPOMD_RECORD_ERROR, CRE_STAT,
+ "Stat() on %s failed: %s", path, strerror(errno));
+ return CRE_STAT;
}
}
// Set db version
- if (!md->db_ver) {
+ if (!md->db_ver)
md->db_ver = DEFAULT_DATABASE_VERSION;
- }
- return REPOMD_OK;
+ return CRE_OK;
}
void
cr_repomd_record_groupfile(cr_RepomdRecord groupfile,
- cr_RepomdRecord cgroupfile,
- cr_ChecksumType checksum_type,
- cr_CompressionType groupfile_compression)
+ cr_RepomdRecord cgroupfile,
+ cr_ChecksumType checksum_type,
+ cr_CompressionType groupfile_compression,
+ GError **err)
{
const char *suffix;
gchar *path, *cpath;
// Compute checksums
- checksum = cr_compute_file_checksum(path, checksum_t);
- cchecksum = cr_compute_file_checksum(cpath, checksum_t);
+ checksum = cr_compute_file_checksum(path, checksum_t, NULL);
+ cchecksum = cr_compute_file_checksum(cpath, checksum_t, NULL);
// Get stats
void
-cr_repomd_record_rename_file(cr_RepomdRecord md)
+cr_repomd_record_rename_file(cr_RepomdRecord md, GError **err)
{
int x, len;
gchar *location_prefix = NULL;
* Note: For groupfile you shoud use cr_repomd_record_groupfile function.
* @param record cr_RepomdRecord object
* @param checksum_type type of checksum to use
+ * @param err GError **
+ * @return cr_Error code
*/
int cr_repomd_record_fill(cr_RepomdRecord record,
- cr_ChecksumType checksum_type);
+ cr_ChecksumType checksum_type,
+ GError **err);
/** Analogue of cr_repomd_record_fill but for groupfile.
* Groupfile must be set with the path to existing non compressed groupfile.
* @param compressed_groupfile empty cr_RepomdRecord object that will by filled
* @param checksum_type type of checksums
* @param compression type of compression
+ * @param err GError **
*/
void cr_repomd_record_groupfile(cr_RepomdRecord groupfile,
cr_RepomdRecord compressed_groupfile,
cr_ChecksumType checksum_type,
- cr_CompressionType compression);
+ cr_CompressionType compression,
+ GError **err);
/** Add a hash as prefix to the filename.
* @param record cr_RepomdRecord of file to be renamed
+ * @param err GError **
*/
-void cr_repomd_record_rename_file(cr_RepomdRecord record);
+void cr_repomd_record_rename_file(cr_RepomdRecord record, GError **err);
/** Create new empty cr_Repomd object wich represents content of repomd.xml.
*/
#include "logging.h"
#include "misc.h"
#include "sqlite.h"
+#include "error.h"
#define ENCODED_PACKAGE_FILE_FILES 2048
#define ENCODED_PACKAGE_FILE_TYPES 60
-
-GQuark
-cr_db_error_quark(void)
-{
- static GQuark quark;
-
- if (!quark)
- quark = g_quark_from_static_string("cr_db_error");
-
- return quark;
-}
-
-
struct _DbPrimaryStatements {
sqlite3 *db;
sqlite3_stmt *pkg_handle;
rc = sqlite3_open(path, &db);
if (rc != SQLITE_OK) {
- g_set_error(err, CR_DB_ERROR, CR_DB_ERROR,
+ g_set_error(err, CR_DB_ERROR, CRE_DB,
"Can not open SQL database: %s", sqlite3_errmsg(db));
sqlite3_close(db);
db = NULL;
sql = "CREATE TABLE db_info (dbversion INTEGER, checksum TEXT)";
rc = sqlite3_exec(db, sql, NULL, NULL, NULL);
if (rc != SQLITE_OK) {
- g_set_error(err, CR_DB_ERROR, CR_DB_ERROR,
+ g_set_error(err, CR_DB_ERROR, CRE_DB,
"Can not create db_info table: %s",
sqlite3_errmsg (db));
}
rc = sqlite3_exec (db, sql, NULL, NULL, NULL);
if (rc != SQLITE_OK) {
- g_set_error (err, CR_DB_ERROR, CR_DB_ERROR,
+ g_set_error(err, CR_DB_ERROR, CRE_DB,
"Can not create packages table: %s",
sqlite3_errmsg (db));
return;
" pkgKey INTEGER)";
rc = sqlite3_exec (db, sql, NULL, NULL, NULL);
if (rc != SQLITE_OK) {
- g_set_error (err, CR_DB_ERROR, CR_DB_ERROR,
+ g_set_error(err, CR_DB_ERROR, CRE_DB,
"Can not create files table: %s",
sqlite3_errmsg (db));
return;
g_free (query);
if (rc != SQLITE_OK) {
- g_set_error (err, CR_DB_ERROR, CR_DB_ERROR,
+ g_set_error(err, CR_DB_ERROR, CRE_DB,
"Can not create %s table: %s",
deps[i], sqlite3_errmsg (db));
return;
rc = sqlite3_exec (db, sql, NULL, NULL, NULL);
if (rc != SQLITE_OK) {
- g_set_error (err, CR_DB_ERROR, CR_DB_ERROR,
+ g_set_error(err, CR_DB_ERROR, CRE_DB,
"Can not create removals trigger: %s",
sqlite3_errmsg (db));
return;
" pkgId TEXT)";
rc = sqlite3_exec (db, sql, NULL, NULL, NULL);
if (rc != SQLITE_OK) {
- g_set_error (err, CR_DB_ERROR, CR_DB_ERROR,
+ g_set_error(err, CR_DB_ERROR, CRE_DB,
"Can not create packages table: %s",
sqlite3_errmsg (db));
return;
" filetypes TEXT)";
rc = sqlite3_exec (db, sql, NULL, NULL, NULL);
if (rc != SQLITE_OK) {
- g_set_error (err, CR_DB_ERROR, CR_DB_ERROR,
+ g_set_error(err, CR_DB_ERROR, CRE_DB,
"Can not create filelist table: %s",
sqlite3_errmsg (db));
return;
rc = sqlite3_exec (db, sql, NULL, NULL, NULL);
if (rc != SQLITE_OK) {
- g_set_error (err, CR_DB_ERROR, CR_DB_ERROR,
+ g_set_error(err, CR_DB_ERROR, CRE_DB,
"Can not create remove_filelist trigger: %s",
sqlite3_errmsg (db));
return;
" pkgId TEXT)";
rc = sqlite3_exec (db, sql, NULL, NULL, NULL);
if (rc != SQLITE_OK) {
- g_set_error (err, CR_DB_ERROR, CR_DB_ERROR,
+ g_set_error(err, CR_DB_ERROR, CRE_DB,
"Can not create packages table: %s",
sqlite3_errmsg (db));
return;
" changelog TEXT)";
rc = sqlite3_exec (db, sql, NULL, NULL, NULL);
if (rc != SQLITE_OK) {
- g_set_error (err, CR_DB_ERROR, CR_DB_ERROR,
+ g_set_error(err, CR_DB_ERROR, CRE_DB,
"Can not create changelog table: %s",
sqlite3_errmsg (db));
return;
rc = sqlite3_exec (db, sql, NULL, NULL, NULL);
if (rc != SQLITE_OK) {
- g_set_error (err, CR_DB_ERROR, CR_DB_ERROR,
+ g_set_error(err, CR_DB_ERROR, CRE_DB,
"Can not create remove_changelogs trigger: %s",
sqlite3_errmsg (db));
return;
sql = "CREATE INDEX IF NOT EXISTS packagename ON packages (name)";
rc = sqlite3_exec (db, sql, NULL, NULL, NULL);
if (rc != SQLITE_OK) {
- g_set_error (err, CR_DB_ERROR, CR_DB_ERROR,
+ g_set_error(err, CR_DB_ERROR, CRE_DB,
"Can not create packagename index: %s",
sqlite3_errmsg (db));
return;
sql = "CREATE INDEX IF NOT EXISTS packageId ON packages (pkgId)";
rc = sqlite3_exec (db, sql, NULL, NULL, NULL);
if (rc != SQLITE_OK) {
- g_set_error (err, CR_DB_ERROR, CR_DB_ERROR,
+ g_set_error(err, CR_DB_ERROR, CRE_DB,
"Can not create packageId index: %s",
sqlite3_errmsg (db));
return;
sql = "CREATE INDEX IF NOT EXISTS filenames ON files (name)";
rc = sqlite3_exec (db, sql, NULL, NULL, NULL);
if (rc != SQLITE_OK) {
- g_set_error (err, CR_DB_ERROR, CR_DB_ERROR,
+ g_set_error(err, CR_DB_ERROR, CRE_DB,
"Can not create filenames index: %s",
sqlite3_errmsg (db));
return;
sql = "CREATE INDEX IF NOT EXISTS pkgfiles ON files (pkgKey)";
rc = sqlite3_exec (db, sql, NULL, NULL, NULL);
if (rc != SQLITE_OK) {
- g_set_error (err, CR_DB_ERROR, CR_DB_ERROR,
+ g_set_error(err, CR_DB_ERROR, CRE_DB,
"Can not create index on files table: %s",
sqlite3_errmsg (db));
return;
g_free (query);
if (rc != SQLITE_OK) {
- g_set_error (err, CR_DB_ERROR, CR_DB_ERROR,
+ g_set_error(err, CR_DB_ERROR, CRE_DB,
"Can not create index on %s table: %s",
deps[i], sqlite3_errmsg (db));
return;
rc = sqlite3_exec (db, query, NULL, NULL, NULL);
g_free(query);
if (rc != SQLITE_OK) {
- g_set_error (err, CR_DB_ERROR, CR_DB_ERROR,
+ g_set_error(err, CR_DB_ERROR, CRE_DB,
"Can not create %sname index: %s",
deps[i], sqlite3_errmsg (db));
return;
sql = "CREATE INDEX IF NOT EXISTS keyfile ON filelist (pkgKey)";
rc = sqlite3_exec (db, sql, NULL, NULL, NULL);
if (rc != SQLITE_OK) {
- g_set_error (err, CR_DB_ERROR, CR_DB_ERROR,
+ g_set_error(err, CR_DB_ERROR, CRE_DB,
"Can not create keyfile index: %s",
sqlite3_errmsg (db));
return;
sql = "CREATE INDEX IF NOT EXISTS pkgId ON packages (pkgId)";
rc = sqlite3_exec (db, sql, NULL, NULL, NULL);
if (rc != SQLITE_OK) {
- g_set_error (err, CR_DB_ERROR, CR_DB_ERROR,
+ g_set_error(err, CR_DB_ERROR, CRE_DB,
"Can not create pkgId index: %s",
sqlite3_errmsg (db));
return;
sql = "CREATE INDEX IF NOT EXISTS dirnames ON filelist (dirname)";
rc = sqlite3_exec (db, sql, NULL, NULL, NULL);
if (rc != SQLITE_OK) {
- g_set_error (err, CR_DB_ERROR, CR_DB_ERROR,
+ g_set_error(err, CR_DB_ERROR, CRE_DB,
"Can not create dirnames index: %s",
sqlite3_errmsg (db));
return;
sql = "CREATE INDEX IF NOT EXISTS keychange ON changelog (pkgKey)";
rc = sqlite3_exec (db, sql, NULL, NULL, NULL);
if (rc != SQLITE_OK) {
- g_set_error (err, CR_DB_ERROR, CR_DB_ERROR,
+ g_set_error(err, CR_DB_ERROR, CRE_DB,
"Can not create keychange index: %s",
sqlite3_errmsg (db));
return;
sql = "CREATE INDEX IF NOT EXISTS pkgId ON packages (pkgId)";
rc = sqlite3_exec (db, sql, NULL, NULL, NULL);
if (rc != SQLITE_OK) {
- g_set_error (err, CR_DB_ERROR, CR_DB_ERROR,
+ g_set_error(err, CR_DB_ERROR, CRE_DB,
"Can not create pkgId index: %s",
sqlite3_errmsg (db));
return;
/* Prepare insert statement */
rc = sqlite3_prepare_v2(db, query, -1, &handle, NULL);
if (rc != SQLITE_OK) {
- g_set_error(err, CR_DB_ERROR, CR_DB_ERROR,
+ g_set_error(err, CR_DB_ERROR, CRE_DB,
"Cannot prepare db_info update: %s",
sqlite3_errmsg(db));
g_critical("%s: Cannot prepare db_info update statement: %s",
rc = sqlite3_finalize(handle);
if (rc != SQLITE_OK) {
- g_set_error (err, CR_DB_ERROR, CR_DB_ERROR,
+ g_set_error(err, CR_DB_ERROR, CRE_DB,
"Cannot update dbinfo table: %s",
sqlite3_errmsg (db));
g_critical("%s: Cannot update dbinfo table: %s",
rc = sqlite3_prepare_v2 (db, query, -1, &handle, NULL);
if (rc != SQLITE_OK) {
- g_set_error (err, CR_DB_ERROR, CR_DB_ERROR,
+ g_set_error(err, CR_DB_ERROR, CRE_DB,
"Cannot prepare packages insertion: %s",
sqlite3_errmsg (db));
sqlite3_finalize (handle);
} else {
g_critical ("Error adding package to db: %s",
sqlite3_errmsg(db));
- g_set_error(err, CR_DB_ERROR, CR_DB_ERROR,
+ g_set_error(err, CR_DB_ERROR, CRE_DB,
"Error adding package to db: %s",
sqlite3_errmsg(db));
}
g_free (query);
if (rc != SQLITE_OK) {
- g_set_error (err, CR_DB_ERROR, CR_DB_ERROR,
+ g_set_error(err, CR_DB_ERROR, CRE_DB,
"Cannot prepare dependency insertion: %s",
sqlite3_errmsg (db));
sqlite3_finalize (handle);
if (rc != SQLITE_DONE) {
g_critical ("Error adding package dependency to db: %s",
sqlite3_errmsg (db));
- g_set_error(err, CR_DB_ERROR, CR_DB_ERROR,
+ g_set_error(err, CR_DB_ERROR, CRE_DB,
"Error adding package dependency to db: %s",
sqlite3_errmsg(db));
}
rc = sqlite3_prepare_v2 (db, query, -1, &handle, NULL);
if (rc != SQLITE_OK) {
- g_set_error (err, CR_DB_ERROR, CR_DB_ERROR,
+ g_set_error(err, CR_DB_ERROR, CRE_DB,
"Can not prepare file insertion: %s",
sqlite3_errmsg (db));
sqlite3_finalize (handle);
if (rc != SQLITE_DONE) {
g_critical ("Error adding package file to db: %s",
sqlite3_errmsg (db));
- g_set_error(err, CR_DB_ERROR, CR_DB_ERROR,
+ g_set_error(err, CR_DB_ERROR, CRE_DB,
"Error adding package file to db: %s",
sqlite3_errmsg(db));
}
rc = sqlite3_prepare_v2 (db, query, -1, &handle, NULL);
if (rc != SQLITE_OK) {
- g_set_error (err, CR_DB_ERROR, CR_DB_ERROR,
+ g_set_error(err, CR_DB_ERROR, CRE_DB,
"Can not prepare filelist insertion: %s",
sqlite3_errmsg (db));
sqlite3_finalize (handle);
if (rc != SQLITE_DONE) {
g_critical ("Error adding file records to db: %s",
sqlite3_errmsg (db));
- g_set_error(err, CR_DB_ERROR, CR_DB_ERROR,
+ g_set_error(err, CR_DB_ERROR, CRE_DB,
"Error adding file records to db : %s",
sqlite3_errmsg(db));
}
rc = sqlite3_prepare_v2 (db, query, -1, &handle, NULL);
if (rc != SQLITE_OK) {
- g_set_error (err, CR_DB_ERROR, CR_DB_ERROR,
+ g_set_error(err, CR_DB_ERROR, CRE_DB,
"Can not prepare changelog insertion: %s",
sqlite3_errmsg (db));
sqlite3_finalize (handle);
query = "INSERT INTO packages (pkgId) VALUES (?)";
rc = sqlite3_prepare_v2 (db, query, -1, &handle, NULL);
if (rc != SQLITE_OK) {
- g_set_error (err, CR_DB_ERROR, CR_DB_ERROR,
+ g_set_error(err, CR_DB_ERROR, CRE_DB,
"Can not prepare package ids insertion: %s",
sqlite3_errmsg (db));
sqlite3_finalize (handle);
} else {
g_critical("Error adding package to db: %s",
sqlite3_errmsg(db));
- g_set_error(err, CR_DB_ERROR, CR_DB_ERROR,
+ g_set_error(err, CR_DB_ERROR, CRE_DB,
"Error adding package to db: %s",
sqlite3_errmsg(db));
}
if (rc != SQLITE_DONE) {
g_critical ("Error adding changelog to db: %s",
sqlite3_errmsg (stmts->db));
- g_set_error(err, CR_DB_ERROR, CR_DB_ERROR,
+ g_set_error(err, CR_DB_ERROR, CRE_DB,
"Error adding changelog to db : %s",
sqlite3_errmsg(stmts->db));
return;
#define CR_DB_CACHE_DBVERSION 10 /*!< Version of DB api */
-#define CR_DB_ERROR cr_db_error_quark()
-GQuark cr_db_error_quark (void);
-
typedef struct _DbPrimaryStatements * cr_DbPrimaryStatements;
typedef struct _DbFilelistsStatements * cr_DbFilelistsStatements;
typedef struct _DbOtherStatements * cr_DbOtherStatements;
*/
#include <glib.h>
+#include <assert.h>
#include <libxml/encoding.h>
#include <libxml/xmlwriter.h>
#include <libxml/parser.h>
#include <string.h>
+#include "error.h"
#include "logging.h"
#include "misc.h"
#include "xml_dump.h"
struct cr_XmlStruct
-cr_xml_dump(cr_Package *pkg)
+cr_xml_dump(cr_Package *pkg, GError **err)
{
struct cr_XmlStruct result;
+ GError *tmp_err = NULL;
+
+ assert(!err || *err == NULL);
if (!pkg) {
result.primary = NULL;
return result;
}
- result.primary = cr_xml_dump_primary(pkg);
- result.filelists = cr_xml_dump_filelists(pkg);
- result.other = cr_xml_dump_other(pkg);
+ result.primary = cr_xml_dump_primary(pkg, &tmp_err);
+ if (tmp_err) {
+ g_propagate_error(err, tmp_err);
+ return result;
+ }
+
+ result.filelists = cr_xml_dump_filelists(pkg, &tmp_err);
+ if (tmp_err) {
+ g_propagate_error(err, tmp_err);
+ g_free(result.primary);
+ result.primary = NULL;
+ return result;
+ }
+
+ result.other = cr_xml_dump_other(pkg, &tmp_err);
+ if (tmp_err) {
+ g_propagate_error(err, tmp_err);
+ g_free(result.primary);
+ result.primary = NULL;
+ g_free(result.filelists);
+ result.filelists = NULL;
+ return result;
+ }
return result;
}
* "repodata/rpm.rpm", NULL, 10, NULL);
*
* cr_xml_dump_init();
- * xml = cr_xml_dump(pkg);
+ * xml = cr_xml_dump(pkg, NULL);
* cr_xml_dump_cleanup();
*
* cr_package_free(pkg);
/** Generate primary xml chunk from cr_Package.
* @param package cr_Package
+ * @param err **GError
* @return xml chunk string or NULL on error
*/
-char *cr_xml_dump_primary(cr_Package *package);
+char *cr_xml_dump_primary(cr_Package *package, GError **err);
/** Generate filelists xml chunk from cr_Package.
* @param package cr_Package
+ * @param err **GError
* @return xml chunk string or NULL on error
*/
-char *cr_xml_dump_filelists(cr_Package *package);
+char *cr_xml_dump_filelists(cr_Package *package, GError **err);
/** Generate other xml chunk from cr_Package.
* @param package cr_Package
+ * @param err **GError
* @return xml chunk string or NULL on error
*/
-char *cr_xml_dump_other(cr_Package *package);
+char *cr_xml_dump_other(cr_Package *package, GError **err);
/** Generate all three xml chunks (primary, filelists, other) from cr_Package.
* @param package cr_Package
+ * @param err **GError
* @return cr_XmlStruct
*/
-struct cr_XmlStruct cr_xml_dump(cr_Package *package);
+struct cr_XmlStruct cr_xml_dump(cr_Package *package, GError **err);
/** Prepare string to xml dump.
* If string is not utf8 it is converted (source encoding is supposed to be
#include <string.h>
#include <libxml/encoding.h>
#include <libxml/xmlwriter.h>
+#include "error.h"
#include "logging.h"
#include "package.h"
#include "xml_dump.h"
char *
-cr_xml_dump_filelists(cr_Package *package)
+cr_xml_dump_filelists(cr_Package *package, GError **err)
{
+ xmlNodePtr root;
+ char *result;
+
if (!package)
return NULL;
- xmlNodePtr root = NULL;
- root = xmlNewNode(NULL, BAD_CAST "package");
-
// Dump IT!
- cr_xml_dump_filelists_items(root, package);
-
- char *result;
xmlBufferPtr buf = xmlBufferCreate();
if (buf == NULL) {
g_critical("%s: Error creating the xml buffer", __func__);
+ g_set_error(err, CR_XML_DUMP_FILELISTS_ERROR, CRE_MEMORY,
+ "Cannot create an xml buffer");
return NULL;
}
- // Seems to be little bit faster than xmlDocDumpFormatMemory
+
+ root = xmlNewNode(NULL, BAD_CAST "package");
+ cr_xml_dump_filelists_items(root, package);
+ // xmlNodeDump seems to be a little bit faster than xmlDocDumpFormatMemory
xmlNodeDump(buf, NULL, root, FORMAT_LEVEL, FORMAT_XML);
assert(buf->content);
result = g_strndup((char *) buf->content, (buf->use+1));
result[buf->use] = '\n';
result[buf->use+1] = '\0';
- xmlBufferFree(buf);
// Cleanup
+ xmlBufferFree(buf);
xmlFreeNode(root);
return result;
#include <libxml/encoding.h>
#include <libxml/xmlwriter.h>
#include <libxml/xmlsave.h>
+#include "error.h"
#include "logging.h"
#include "package.h"
#include "xml_dump.h"
char *
-cr_xml_dump_other(cr_Package *package)
+cr_xml_dump_other(cr_Package *package, GError **err)
{
+ xmlNodePtr root;
+ char *result;
+
if (!package)
return NULL;
- xmlNodePtr root = NULL;
- root = xmlNewNode(NULL, BAD_CAST "package");
-
// Dump IT!
- cr_xml_dump_other_items(root, package);
-
- char *result;
xmlBufferPtr buf = xmlBufferCreate();
if (buf == NULL) {
g_critical("%s: Error creating the xml buffer", __func__);
+ g_set_error(err, CR_XML_DUMP_OTHER_ERROR, CRE_MEMORY,
+ "Cannot create an xml buffer");
return NULL;
}
- // Seems to be little bit faster than xmlDocDumpFormatMemory
-// xmlSaveCtxtPtr savebuf = xmlSaveToBuffer(buf, NULL, XML_SAVE_FORMAT|XML_SAVE_NO_DECL);
-// xmlSaveTree(savebuf, root);
+
+ root = xmlNewNode(NULL, BAD_CAST "package");
+ cr_xml_dump_other_items(root, package);
+ // xmlNodeDump seems to be a little bit faster than xmlDocDumpFormatMemory
xmlNodeDump(buf, NULL, root, FORMAT_LEVEL, FORMAT_XML);
assert(buf->content);
result = g_strndup((char *) buf->content, (buf->use+1));
result[buf->use] = '\n';
result[buf->use+1] = '\0';
- xmlBufferFree(buf);
// Cleanup
+ xmlBufferFree(buf);
xmlFreeNode(root);
return result;
#include <string.h>
#include <libxml/encoding.h>
#include <libxml/xmlwriter.h>
+#include "error.h"
#include "logging.h"
#include "package.h"
#include "xml_dump.h"
char *
-cr_xml_dump_primary(cr_Package *package)
+cr_xml_dump_primary(cr_Package *package, GError **err)
{
+ xmlNodePtr root;
+ char *result;
+
if (!package)
return NULL;
- xmlNodePtr root = NULL;
- root = xmlNewNode(NULL, BAD_CAST "package");
-
// Dump IT!
- cr_xml_dump_primary_base_items(root, package);
-
- char *result;
xmlBufferPtr buf = xmlBufferCreate();
if (buf == NULL) {
g_critical("%s: Error creating the xml buffer", __func__);
+ g_set_error(err, CR_XML_DUMP_PRIMARY_ERROR, CRE_MEMORY,
+ "Cannot create an xml buffer");
return NULL;
}
- // Seems to be little bit faster than xmlDocDumpFormatMemory
+
+ root = xmlNewNode(NULL, BAD_CAST "package");
+ cr_xml_dump_primary_base_items(root, package);
+ // xmlNodeDump seems to be a little bit faster than xmlDocDumpFormatMemory
xmlNodeDump(buf, NULL, root, FORMAT_LEVEL, FORMAT_XML);
assert(buf->content);
result = g_strndup((char *) buf->content, (buf->use+1));
result[buf->use] = '\n';
result[buf->use+1] = '\0';
- xmlBufferFree(buf);
// Cleanup
+ xmlBufferFree(buf);
xmlFreeNode(root);
return result;
{
char *checksum;
- checksum = cr_compute_file_checksum(EMPTY_FILE, CR_CHECKSUM_MD5);
+ checksum = cr_compute_file_checksum(EMPTY_FILE, CR_CHECKSUM_MD5, NULL);
g_assert_cmpstr(checksum, ==, "d41d8cd98f00b204e9800998ecf8427e");
g_free(checksum);
- checksum = cr_compute_file_checksum(EMPTY_FILE, CR_CHECKSUM_SHA1);
+ checksum = cr_compute_file_checksum(EMPTY_FILE, CR_CHECKSUM_SHA1, NULL);
g_assert_cmpstr(checksum, ==, "da39a3ee5e6b4b0d3255bfef95601890afd80709");
g_free(checksum);
- checksum = cr_compute_file_checksum(EMPTY_FILE, CR_CHECKSUM_SHA256);
+ checksum = cr_compute_file_checksum(EMPTY_FILE, CR_CHECKSUM_SHA256, NULL);
g_assert_cmpstr(checksum, ==, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
g_free(checksum);
- checksum = cr_compute_file_checksum(TEXT_FILE, CR_CHECKSUM_MD5);
+ checksum = cr_compute_file_checksum(TEXT_FILE, CR_CHECKSUM_MD5, NULL);
g_assert_cmpstr(checksum, ==, "d6d4da5c15f8fe7570ce6ab6b3503916");
g_free(checksum);
- checksum = cr_compute_file_checksum(TEXT_FILE, CR_CHECKSUM_SHA1);
+ checksum = cr_compute_file_checksum(TEXT_FILE, CR_CHECKSUM_SHA1, NULL);
g_assert_cmpstr(checksum, ==, "da048ee8fabfbef1b3d6d3f5a4be20029eecec77");
g_free(checksum);
- checksum = cr_compute_file_checksum(TEXT_FILE, CR_CHECKSUM_SHA256);
+ checksum = cr_compute_file_checksum(TEXT_FILE, CR_CHECKSUM_SHA256, NULL);
g_assert_cmpstr(checksum, ==, "2f395bdfa2750978965e4781ddf224c89646c7d7a1569b7ebb023b170f7bd8bb");
g_free(checksum);
- checksum = cr_compute_file_checksum(BINARY_FILE, CR_CHECKSUM_MD5);
+ checksum = cr_compute_file_checksum(BINARY_FILE, CR_CHECKSUM_MD5, NULL);
g_assert_cmpstr(checksum, ==, "4f8b033d7a402927a20c9328fc0e0f46");
g_free(checksum);
- checksum = cr_compute_file_checksum(BINARY_FILE, CR_CHECKSUM_SHA1);
+ checksum = cr_compute_file_checksum(BINARY_FILE, CR_CHECKSUM_SHA1, NULL);
g_assert_cmpstr(checksum, ==, "3539fb660a41846352ac4fa9076d168a3c77070b");
g_free(checksum);
- checksum = cr_compute_file_checksum(BINARY_FILE, CR_CHECKSUM_SHA256);
+ checksum = cr_compute_file_checksum(BINARY_FILE, CR_CHECKSUM_SHA256, NULL);
g_assert_cmpstr(checksum, ==, "bf68e32ad78cea8287be0f35b74fa3fecd0eaa91770b48f1a7282b015d6d883e");
g_free(checksum);
// Corner cases
- checksum = cr_compute_file_checksum(BINARY_FILE, 244);
+ checksum = cr_compute_file_checksum(BINARY_FILE, 244, NULL);
g_assert(!checksum);
- checksum = cr_compute_file_checksum(NON_EXIST_FILE, CR_CHECKSUM_MD5);
+ checksum = cr_compute_file_checksum(NON_EXIST_FILE, CR_CHECKSUM_MD5, NULL);
g_assert(!checksum);
-
- checksum = cr_compute_file_checksum(NULL, CR_CHECKSUM_MD5);
- g_assert(!checksum);
-
}
ret = cr_copy_file(EMPTY_FILE, copyfiletest->dst_file);
g_assert_cmpint(ret, ==, CR_COPY_OK);
g_assert(g_file_test(copyfiletest->dst_file, G_FILE_TEST_EXISTS|G_FILE_TEST_IS_REGULAR));
- checksum = cr_compute_file_checksum(copyfiletest->dst_file, CR_CHECKSUM_SHA256);
+ checksum = cr_compute_file_checksum(copyfiletest->dst_file, CR_CHECKSUM_SHA256, NULL);
g_assert_cmpstr(checksum, ==, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
g_free(checksum);
}
ret = cr_copy_file(TEXT_FILE, copyfiletest->dst_file);
g_assert_cmpint(ret, ==, CR_COPY_OK);
g_assert(g_file_test(copyfiletest->dst_file, G_FILE_TEST_EXISTS|G_FILE_TEST_IS_REGULAR));
- checksum = cr_compute_file_checksum(copyfiletest->dst_file, CR_CHECKSUM_SHA256);
+ checksum = cr_compute_file_checksum(copyfiletest->dst_file, CR_CHECKSUM_SHA256, NULL);
g_assert_cmpstr(checksum, ==, "2f395bdfa2750978965e4781ddf224c89646c7d7a1569b7ebb023b170f7bd8bb");
g_free(checksum);
}
ret = cr_copy_file(BINARY_FILE, copyfiletest->dst_file);
g_assert_cmpint(ret, ==, CR_COPY_OK);
g_assert(g_file_test(copyfiletest->dst_file, G_FILE_TEST_EXISTS|G_FILE_TEST_IS_REGULAR));
- checksum = cr_compute_file_checksum(copyfiletest->dst_file, CR_CHECKSUM_SHA256);
+ checksum = cr_compute_file_checksum(copyfiletest->dst_file, CR_CHECKSUM_SHA256, NULL);
g_assert_cmpstr(checksum, ==, "bf68e32ad78cea8287be0f35b74fa3fecd0eaa91770b48f1a7282b015d6d883e");
g_free(checksum);
}
ret = cr_copy_file(BINARY_FILE, copyfiletest->dst_file);
g_assert_cmpint(ret, ==, CR_COPY_OK);
g_assert(g_file_test(copyfiletest->dst_file, G_FILE_TEST_EXISTS|G_FILE_TEST_IS_REGULAR));
- checksum = cr_compute_file_checksum(copyfiletest->dst_file, CR_CHECKSUM_SHA256);
+ checksum = cr_compute_file_checksum(copyfiletest->dst_file, CR_CHECKSUM_SHA256, NULL);
g_assert_cmpstr(checksum, ==, "bf68e32ad78cea8287be0f35b74fa3fecd0eaa91770b48f1a7282b015d6d883e");
g_free(checksum);
ret = cr_copy_file(TEXT_FILE, copyfiletest->dst_file);
g_assert_cmpint(ret, ==, CR_COPY_OK);
g_assert(g_file_test(copyfiletest->dst_file, G_FILE_TEST_EXISTS|G_FILE_TEST_IS_REGULAR));
- checksum = cr_compute_file_checksum(copyfiletest->dst_file, CR_CHECKSUM_SHA256);
+ checksum = cr_compute_file_checksum(copyfiletest->dst_file, CR_CHECKSUM_SHA256, NULL);
g_assert_cmpstr(checksum, ==, "2f395bdfa2750978965e4781ddf224c89646c7d7a1569b7ebb023b170f7bd8bb");
g_free(checksum);
}
ret = cr_compress_file(TEXT_FILE, copyfiletest->dst_file, CR_CW_GZ_COMPRESSION);
g_assert_cmpint(ret, ==, CR_COPY_OK);
g_assert(g_file_test(copyfiletest->dst_file, G_FILE_TEST_EXISTS|G_FILE_TEST_IS_REGULAR));
- checksum = cr_compute_file_checksum(copyfiletest->dst_file, CR_CHECKSUM_SHA256);
+ checksum = cr_compute_file_checksum(copyfiletest->dst_file, CR_CHECKSUM_SHA256, NULL);
g_assert_cmpstr(checksum, ==, "8909fde88a5747d800fd2562b0f22945f014aa7df64cf1c15c7933ae54b72ab6");
g_free(checksum);
}
ret = cr_better_copy_file(BINARY_FILE, copyfiletest->dst_file);
g_assert_cmpint(ret, ==, CR_COPY_OK);
g_assert(g_file_test(copyfiletest->dst_file, G_FILE_TEST_EXISTS|G_FILE_TEST_IS_REGULAR));
- checksum = cr_compute_file_checksum(copyfiletest->dst_file, CR_CHECKSUM_SHA256);
+ checksum = cr_compute_file_checksum(copyfiletest->dst_file, CR_CHECKSUM_SHA256, NULL);
g_assert_cmpstr(checksum, ==, "bf68e32ad78cea8287be0f35b74fa3fecd0eaa91770b48f1a7282b015d6d883e");
g_free(checksum);
}