[tracker-miners/wip/carlosg/cli-improvements: 2/30] libtracker-miners-common: Add error storage infrastructure
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker-miners/wip/carlosg/cli-improvements: 2/30] libtracker-miners-common: Add error storage infrastructure
- Date: Tue, 18 Aug 2020 09:18:31 +0000 (UTC)
commit 21aa1c4b76b8f871bcdab6c89e1719f1fef423e3
Author: Carlos Garnacho <carlosg gnome org>
Date: Sun Aug 16 11:46:48 2020 +0200
libtracker-miners-common: Add error storage infrastructure
Instead of logging things on stderr and asking users to look for it,
we are going for a coredumpctl-alike approach, where we persistently
log the errors in a way that can be quickly looked up and inspected
by the user.
This adds the lowlevel bits, so it is possible to store these errors.
src/libtracker-miners-common/meson.build | 1 +
src/libtracker-miners-common/tracker-common.h | 1 +
.../tracker-error-report.c | 103 +++++++++++++++++++++
.../tracker-error-report.h | 34 +++++++
4 files changed, 139 insertions(+)
---
diff --git a/src/libtracker-miners-common/meson.build b/src/libtracker-miners-common/meson.build
index 2b6590b70..7868f8623 100644
--- a/src/libtracker-miners-common/meson.build
+++ b/src/libtracker-miners-common/meson.build
@@ -11,6 +11,7 @@ tracker_miners_common_sources = [
'tracker-dbus.c',
'tracker-domain-ontology.c',
'tracker-debug.c',
+ 'tracker-error-report.c',
'tracker-file-utils.c',
'tracker-fts-config.c',
'tracker-ioprio.c',
diff --git a/src/libtracker-miners-common/tracker-common.h b/src/libtracker-miners-common/tracker-common.h
index dcf52f587..1d4f364c4 100644
--- a/src/libtracker-miners-common/tracker-common.h
+++ b/src/libtracker-miners-common/tracker-common.h
@@ -33,6 +33,7 @@
#include "tracker-debug.h"
#include "tracker-domain-ontology.h"
#include "tracker-enums.h"
+#include "tracker-error-report.h"
#include "tracker-file-utils.h"
#include "tracker-fts-config.h"
#include "tracker-ioprio.h"
diff --git a/src/libtracker-miners-common/tracker-error-report.c
b/src/libtracker-miners-common/tracker-error-report.c
new file mode 100644
index 000000000..501c2c634
--- /dev/null
+++ b/src/libtracker-miners-common/tracker-error-report.c
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2020, Red Hat Ltd
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * Author: Carlos Garnacho <carlosg gnome org>
+ */
+
+#include "tracker-error-report.h"
+
+#include <glib/gstdio.h>
+
+#define GROUP "Report"
+#define KEY_URI "Uri"
+#define KEY_MESSAGE "Message"
+#define KEY_SPARQL "Sparql"
+
+static gchar *report_dir = NULL;
+
+void
+tracker_error_report_init (GFile *cache_dir)
+{
+ GFile *report_file;
+
+ report_file = g_file_get_child (cache_dir, "errors");
+ report_dir = g_file_get_path (report_file);
+ g_mkdir_with_parents (report_dir, 0600);
+ g_object_unref (report_file);
+}
+
+static gchar *
+get_report_file (const gchar *uri)
+{
+ gchar *md5, *report_file;
+
+ md5 = g_compute_checksum_for_string (G_CHECKSUM_MD5, uri, -1);
+ report_file = g_build_filename (report_dir, md5, NULL);
+ g_free (md5);
+
+ return report_file;
+}
+
+void
+tracker_error_report (GFile *file,
+ const gchar *error_message,
+ const gchar *sparql)
+{
+ GKeyFile *key_file;
+ gchar *report_path, *uri;
+ GError *error = NULL;
+
+ if (!report_dir)
+ return;
+
+ uri = g_file_get_uri (file);
+ report_path = get_report_file (uri);
+ key_file = g_key_file_new ();
+ g_key_file_set_string (key_file, GROUP, KEY_URI, uri);
+
+ if (error_message)
+ g_key_file_set_string (key_file, GROUP, KEY_MESSAGE, error_message);
+
+ if (sparql)
+ g_key_file_set_string (key_file, GROUP, KEY_SPARQL, sparql);
+
+ if (!g_key_file_save_to_file (key_file, report_path, &error)) {
+ g_warning ("Could not save error report: %s\n", error->message);
+ g_error_free (error);
+ }
+
+ g_key_file_unref (key_file);
+ g_free (report_path);
+ g_free (uri);
+}
+
+void
+tracker_error_report_delete (GFile *file)
+{
+ gchar *uri, *report_path;
+
+ if (!report_dir)
+ return;
+
+ uri = g_file_get_uri (file);
+ report_path = get_report_file (uri);
+ g_remove (report_path);
+
+ g_free (report_path);
+ g_free (uri);
+}
diff --git a/src/libtracker-miners-common/tracker-error-report.h
b/src/libtracker-miners-common/tracker-error-report.h
new file mode 100644
index 000000000..c69a5e934
--- /dev/null
+++ b/src/libtracker-miners-common/tracker-error-report.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2020, Red Hat Ltd
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * Author: Carlos Garnacho <carlosg gnome org>
+ */
+
+#ifndef __TRACKER_ERROR_REPORT_H__
+#define __TRACKER_ERROR_REPORT_H__
+
+#include <gio/gio.h>
+
+void tracker_error_report_init (GFile *cache_dir);
+
+void tracker_error_report (GFile *file,
+ const gchar *error_message,
+ const gchar *sparql);
+void tracker_error_report_delete (GFile *file);
+
+#endif /* __TRACKER_ERROR_REPORT_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]