Blame SOURCES/0143-problem_data-add-a-new-function-problem_item_get_siz.patch

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