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

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