|
|
4b6aa8 |
From cbd400521218fe1e259493058799125a69bd7c3b Mon Sep 17 00:00:00 2001
|
|
|
4b6aa8 |
From: Jakub Filak <jfilak@redhat.com>
|
|
|
4b6aa8 |
Date: Mon, 16 Mar 2015 08:15:00 +0100
|
|
|
4b6aa8 |
Subject: [PATCH] problem_data: add a new function problem_item_get_size
|
|
|
4b6aa8 |
|
|
|
4b6aa8 |
Related: #1224984
|
|
|
4b6aa8 |
|
|
|
4b6aa8 |
Signed-off-by: Jakub Filak <jfilak@redhat.com>
|
|
|
4b6aa8 |
---
|
|
|
4b6aa8 |
src/include/problem_data.h | 1 +
|
|
|
4b6aa8 |
src/lib/make_descr.c | 12 ++++--------
|
|
|
4b6aa8 |
src/lib/problem_data.c | 19 +++++++++++++++++++
|
|
|
4b6aa8 |
3 files changed, 24 insertions(+), 8 deletions(-)
|
|
|
4b6aa8 |
|
|
|
4b6aa8 |
diff --git a/src/include/problem_data.h b/src/include/problem_data.h
|
|
|
4b6aa8 |
index 02c945c..96d0af6 100644
|
|
|
4b6aa8 |
--- a/src/include/problem_data.h
|
|
|
4b6aa8 |
+++ b/src/include/problem_data.h
|
|
|
4b6aa8 |
@@ -59,6 +59,7 @@ typedef struct problem_item problem_item;
|
|
|
4b6aa8 |
|
|
|
4b6aa8 |
char *problem_item_format(struct problem_item *item);
|
|
|
4b6aa8 |
|
|
|
4b6aa8 |
+int problem_item_get_size(struct problem_item *item, unsigned long *size);
|
|
|
4b6aa8 |
|
|
|
4b6aa8 |
/* In-memory problem data structure and accessors */
|
|
|
4b6aa8 |
|
|
|
4b6aa8 |
diff --git a/src/lib/make_descr.c b/src/lib/make_descr.c
|
|
|
4b6aa8 |
index 2bcbebd..f8da893 100644
|
|
|
4b6aa8 |
--- a/src/lib/make_descr.c
|
|
|
4b6aa8 |
+++ b/src/lib/make_descr.c
|
|
|
4b6aa8 |
@@ -216,12 +216,8 @@ char *make_description(problem_data_t *problem_data, char **names_to_skip,
|
|
|
4b6aa8 |
strbuf_append_char(buf_dsc, '\n');
|
|
|
4b6aa8 |
append_empty_line = false;
|
|
|
4b6aa8 |
|
|
|
4b6aa8 |
- struct stat statbuf;
|
|
|
4b6aa8 |
- int stat_err = 0;
|
|
|
4b6aa8 |
- if (item->flags & CD_FLAG_BIN)
|
|
|
4b6aa8 |
- stat_err = stat(item->content, &statbuf);
|
|
|
4b6aa8 |
- else
|
|
|
4b6aa8 |
- statbuf.st_size = strlen(item->content);
|
|
|
4b6aa8 |
+ unsigned long size = 0;
|
|
|
4b6aa8 |
+ int stat_err = problem_item_get_size(item, &size);
|
|
|
4b6aa8 |
|
|
|
4b6aa8 |
/* We don't print item->content for CD_FLAG_BIN, as it is
|
|
|
4b6aa8 |
* always "/path/to/dump/dir/KEY" - not informative.
|
|
|
4b6aa8 |
@@ -229,11 +225,11 @@ char *make_description(problem_data_t *problem_data, char **names_to_skip,
|
|
|
4b6aa8 |
int pad = 16 - (strlen(key) + 2);
|
|
|
4b6aa8 |
if (pad < 0) pad = 0;
|
|
|
4b6aa8 |
strbuf_append_strf(buf_dsc,
|
|
|
4b6aa8 |
- (!stat_err ? "%s: %*s%s file, %llu bytes\n" : "%s: %*s%s file\n"),
|
|
|
4b6aa8 |
+ (!stat_err ? "%s: %*s%s file, %lu bytes\n" : "%s: %*s%s file\n"),
|
|
|
4b6aa8 |
key,
|
|
|
4b6aa8 |
pad, "",
|
|
|
4b6aa8 |
((item->flags & CD_FLAG_BIN) ? "Binary" : "Text"),
|
|
|
4b6aa8 |
- (long long)statbuf.st_size
|
|
|
4b6aa8 |
+ size
|
|
|
4b6aa8 |
);
|
|
|
4b6aa8 |
empty = false;
|
|
|
4b6aa8 |
}
|
|
|
4b6aa8 |
diff --git a/src/lib/problem_data.c b/src/lib/problem_data.c
|
|
|
4b6aa8 |
index ebddd3c..9a2b566 100644
|
|
|
4b6aa8 |
--- a/src/lib/problem_data.c
|
|
|
4b6aa8 |
+++ b/src/lib/problem_data.c
|
|
|
4b6aa8 |
@@ -52,6 +52,25 @@ char *problem_item_format(struct problem_item *item)
|
|
|
4b6aa8 |
return NULL;
|
|
|
4b6aa8 |
}
|
|
|
4b6aa8 |
|
|
|
4b6aa8 |
+int problem_item_get_size(struct problem_item *item, unsigned long *size)
|
|
|
4b6aa8 |
+{
|
|
|
4b6aa8 |
+ if (item->flags & CD_FLAG_TXT)
|
|
|
4b6aa8 |
+ {
|
|
|
4b6aa8 |
+ *size = strlen(item->content);
|
|
|
4b6aa8 |
+ return 0;
|
|
|
4b6aa8 |
+ }
|
|
|
4b6aa8 |
+
|
|
|
4b6aa8 |
+ /* else if (item->flags & CD_FLAG_BIN) */
|
|
|
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 |
+ return 0;
|
|
|
4b6aa8 |
+}
|
|
|
4b6aa8 |
+
|
|
|
4b6aa8 |
/* problem_data["name"] = { "content", CD_FLAG_foo_bits } */
|
|
|
4b6aa8 |
|
|
|
4b6aa8 |
problem_data_t *problem_data_new(void)
|
|
|
4b6aa8 |
--
|
|
|
4b6aa8 |
2.4.3
|
|
|
4b6aa8 |
|