[tracker-miners/wip/carlosg/consistent-error-reports] libtracker-miners-common: Ensure consistence and durability of error reports




commit e121d86358ddef163c7d9625871c33373952a9a8
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed Mar 23 18:22:13 2022 +0100

    libtracker-miners-common: Ensure consistence and durability of error reports
    
    In certain situations such as power loss, it is possible that
    g_key_file_save_to_file() will end up in a 0-size or 0-filled file. Use the
    greater guarantees provided by G_FILE_SET_CONTENTS_CONSISTENT and
    G_FILE_SET_CONTENTS_DURABLE to ensure that error reports are either written
    fully or not written at all.
    
    Closes: https://gitlab.gnome.org/GNOME/tracker-miners/-/issues/151

 src/libtracker-miners-common/tracker-error-report.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
---
diff --git a/src/libtracker-miners-common/tracker-error-report.c 
b/src/libtracker-miners-common/tracker-error-report.c
index 8afc37917..720171aa4 100644
--- a/src/libtracker-miners-common/tracker-error-report.c
+++ b/src/libtracker-miners-common/tracker-error-report.c
@@ -61,8 +61,9 @@ tracker_error_report (GFile       *file,
                       const gchar *sparql)
 {
        GKeyFile *key_file;
-       gchar *report_path, *uri;
+       gchar *report_path, *uri, *data;
        GError *error = NULL;
+       gssize len;
 
        if (!report_dir)
                return;
@@ -78,7 +79,12 @@ tracker_error_report (GFile       *file,
        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)) {
+       data = g_key_file_to_data (key_file, &len, NULL);
+
+       if (g_file_set_contents_full (report_path, data, len,
+                                     G_FILE_SET_CONTENTS_CONSISTENT |
+                                     G_FILE_SET_CONTENTS_DURABLE,
+                                     0666, &error)) {
                g_warning ("Could not save error report: %s\n", error->message);
                g_error_free (error);
        }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]