[tracker-miners/wip/carlosg/status-improvements: 1/2] tracker: Handle stale reports for disappeared files in "tracker3 status"




commit 878e7eebd811276cc281c6b5ddeb4c7bfd344944
Author: Carlos Garnacho <carlosg gnome org>
Date:   Fri Apr 8 12:02:19 2022 +0200

    tracker: Handle stale reports for disappeared files in "tracker3 status"
    
    As every race condition is possible in filesystems, it is possible that a
    file disappears under tracker-extract-3 feet after existence checks, but
    before the extractor module opens the file for metadata extraction.
    
    In that case we could generate error reports for files that do no longer
    exist, and whose report won't be automatically deleted ever again.
    
    Ensure to trim these stale files during "tracker3 status" output
    generation, so there's something able to remove these from the filesystem
    and they don't confuse users into thinking these are legit errors.

 src/tracker/tracker-status.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)
---
diff --git a/src/tracker/tracker-status.c b/src/tracker/tracker-status.c
index f8ac1f5e3..8519ddc41 100644
--- a/src/tracker/tracker-status.c
+++ b/src/tracker/tracker-status.c
@@ -337,13 +337,19 @@ print_errors (GList *keyfiles)
        for (l = keyfiles; l; l = l->next) {
                GKeyFile *keyfile = l->data;
                gchar *uri, *message, *path, *str1, *str2;
-               GFile *file;
+               g_autoptr(GFile) file = NULL;
 
                uri = g_key_file_get_string (keyfile, GROUP, KEY_URI, NULL);
                file = g_file_new_for_uri (uri);
                path = g_file_get_path (file);
+               g_free (uri);
+
+               if (!g_file_query_exists (file, NULL)) {
+                       tracker_error_report_delete (file);
+                       continue;
+               }
+
                message = g_key_file_get_string (keyfile, GROUP, KEY_MESSAGE, NULL);
-               g_object_unref (file);
 
                str1 = tracker_term_ellipsize (path, col_len[0], TRACKER_ELLIPSIZE_START);
                str2 = tracker_term_ellipsize (message, col_len[1], TRACKER_ELLIPSIZE_END);
@@ -351,7 +357,6 @@ print_errors (GList *keyfiles)
                g_print ("%-*s %-*s\n",
                         col_len[0], str1,
                         col_len[1], str2);
-               g_free (uri);
                g_free (path);
                g_free (message);
                g_free (str1);
@@ -455,7 +460,7 @@ show_errors (gchar **terms)
 
        for (i = 0; terms[i] != NULL; i++) {
                for (l = keyfiles; l; l = l->next) {
-                       GFile *file;
+                       g_autoptr(GFile) file = NULL;
                        gchar *uri, *path;
 
                        keyfile = l->data;
@@ -463,6 +468,11 @@ show_errors (gchar **terms)
                        file = g_file_new_for_uri (uri);
                        path = g_file_get_path (file);
 
+                       if (!g_file_query_exists (file, NULL)) {
+                               tracker_error_report_delete (file);
+                               continue;
+                       }
+
                        if (strstr (path, terms[i])) {
                                gchar *sparql = g_key_file_get_string (keyfile, GROUP, KEY_SPARQL, NULL);
                                gchar *message = g_key_file_get_string (keyfile, GROUP, KEY_MESSAGE, NULL);
@@ -480,7 +490,6 @@ show_errors (gchar **terms)
                                g_free (message);
                        }
 
-                       g_object_unref (file);
                        g_free (uri);
                        g_free (path);
                }


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