Blame SOURCES/0144-problem_data-cache-problem_item-size.patch

28bab8
From 6048dae71114788b6e6dc13fe69e744463b552a1 Mon Sep 17 00:00:00 2001
28bab8
From: Jakub Filak <jfilak@redhat.com>
28bab8
Date: Tue, 24 Mar 2015 18:05:59 +0100
28bab8
Subject: [PATCH] problem_data: cache problem_item size
28bab8
28bab8
This is necessary for problem_data gotten from D-Bus where the
28bab8
underlying files might not be directly accessible.
28bab8
28bab8
Related: #1224984
28bab8
28bab8
Signed-off-by: Jakub Filak <jfilak@redhat.com>
28bab8
---
28bab8
 src/include/problem_data.h |  8 ++++++++
28bab8
 src/lib/problem_data.c     | 27 +++++++++++++++++++++++----
28bab8
 2 files changed, 31 insertions(+), 4 deletions(-)
28bab8
28bab8
diff --git a/src/include/problem_data.h b/src/include/problem_data.h
28bab8
index 96d0af6..0fc8b78 100644
28bab8
--- a/src/include/problem_data.h
28bab8
+++ b/src/include/problem_data.h
28bab8
@@ -46,9 +46,12 @@ enum {
28bab8
     CD_FLAG_BIGTXT        = (1 << 6),
28bab8
 };
28bab8
 
28bab8
+#define PROBLEM_ITEM_UNINITIALIZED_SIZE ((unsigned long)-1)
28bab8
+
28bab8
 struct problem_item {
28bab8
     char    *content;
28bab8
     unsigned flags;
28bab8
+    unsigned long size;
28bab8
     /* Used by UI for presenting "item allowed/not allowed" checkboxes: */
28bab8
     int      selected_by_user;     /* 0 "don't know", -1 "no", 1 "yes" */
28bab8
     int      allowed_by_reporter;  /* 0 "no", 1 "yes" */
28bab8
@@ -82,6 +85,11 @@ void problem_data_add(problem_data_t *problem_data,
28bab8
                 const char *name,
28bab8
                 const char *content,
28bab8
                 unsigned flags);
28bab8
+struct problem_item *problem_data_add_ext(problem_data_t *problem_data,
28bab8
+                const char *name,
28bab8
+                const char *content,
28bab8
+                unsigned flags,
28bab8
+                unsigned long size);
28bab8
 void problem_data_add_text_noteditable(problem_data_t *problem_data,
28bab8
                 const char *name,
28bab8
                 const char *content);
28bab8
diff --git a/src/lib/problem_data.c b/src/lib/problem_data.c
28bab8
index 9a2b566..212f337 100644
28bab8
--- a/src/lib/problem_data.c
28bab8
+++ b/src/lib/problem_data.c
28bab8
@@ -54,20 +54,27 @@ char *problem_item_format(struct problem_item *item)
28bab8
 
28bab8
 int problem_item_get_size(struct problem_item *item, unsigned long *size)
28bab8
 {
28bab8
+    if (item->size != PROBLEM_ITEM_UNINITIALIZED_SIZE)
28bab8
+    {
28bab8
+        *size = item->size;
28bab8
+        return 0;
28bab8
+    }
28bab8
+
28bab8
     if (item->flags & CD_FLAG_TXT)
28bab8
     {
28bab8
-        *size = strlen(item->content);
28bab8
+        *size = item->size = strlen(item->content);
28bab8
         return 0;
28bab8
     }
28bab8
 
28bab8
     /* else if (item->flags & CD_FLAG_BIN) */
28bab8
+
28bab8
     struct stat statbuf;
28bab8
     statbuf.st_size = 0;
28bab8
 
28bab8
     if (stat(item->content, &statbuf) != 0)
28bab8
         return -errno;
28bab8
 
28bab8
-    *size = statbuf.st_size;
28bab8
+    *size = item->size = statbuf.st_size;
28bab8
     return 0;
28bab8
 }
28bab8
 
28bab8
@@ -181,10 +188,11 @@ void problem_data_add_current_process_data(problem_data_t *pd)
28bab8
     }
28bab8
 }
28bab8
 
28bab8
-void problem_data_add(problem_data_t *problem_data,
28bab8
+struct problem_item *problem_data_add_ext(problem_data_t *problem_data,
28bab8
                 const char *name,
28bab8
                 const char *content,
28bab8
-                unsigned flags)
28bab8
+                unsigned flags,
28bab8
+                unsigned long size)
28bab8
 {
28bab8
     if (!(flags & CD_FLAG_BIN))
28bab8
         flags |= CD_FLAG_TXT;
28bab8
@@ -194,7 +202,18 @@ void problem_data_add(problem_data_t *problem_data,
28bab8
     struct problem_item *item = (struct problem_item *)xzalloc(sizeof(*item));
28bab8
     item->content = xstrdup(content);
28bab8
     item->flags = flags;
28bab8
+    item->size = size;
28bab8
     g_hash_table_replace(problem_data, xstrdup(name), item);
28bab8
+
28bab8
+    return item;
28bab8
+}
28bab8
+
28bab8
+void problem_data_add(problem_data_t *problem_data,
28bab8
+                const char *name,
28bab8
+                const char *content,
28bab8
+                unsigned flags)
28bab8
+{
28bab8
+    problem_data_add_ext(problem_data, name, content, flags, PROBLEM_ITEM_UNINITIALIZED_SIZE);
28bab8
 }
28bab8
 
28bab8
 void problem_data_add_text_noteditable(problem_data_t *problem_data,
28bab8
-- 
28bab8
2.4.3
28bab8