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