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