From 117345107d77ebcea926aa339a572fa5de30fb95 Mon Sep 17 00:00:00 2001
From: Jakub Filak <jfilak@redhat.com>
Date: Fri, 12 Dec 2014 09:17:59 +0100
Subject: [PATCH] dump_dir: introduce dd_copy_file()
Related to abrt/abrt#548
Signed-off-by: Jakub Filak <jfilak@redhat.com>
---
src/include/dump_dir.h | 1 +
src/lib/create_dump_dir.c | 10 +---------
src/lib/dump_dir.c | 16 ++++++++++++++++
3 files changed, 18 insertions(+), 9 deletions(-)
diff --git a/src/include/dump_dir.h b/src/include/dump_dir.h
index fff23f2..84cabbf 100644
--- a/src/include/dump_dir.h
+++ b/src/include/dump_dir.h
@@ -96,6 +96,7 @@ char* dd_load_text_ext(const struct dump_dir *dd, const char *name, unsigned fla
char* dd_load_text(const struct dump_dir *dd, const char *name);
void dd_save_text(struct dump_dir *dd, const char *name, const char *data);
void dd_save_binary(struct dump_dir *dd, const char *name, const char *data, unsigned size);
+int dd_copy_file(struct dump_dir *dd, const char *name, const char *source_path);
/* Returns value less than 0 if any error occured; otherwise returns size of an
* item in Bytes. If an item does not exist returns 0 instead of an error
* value.
diff --git a/src/lib/create_dump_dir.c b/src/lib/create_dump_dir.c
index d683b8e..a96f7bd 100644
--- a/src/lib/create_dump_dir.c
+++ b/src/lib/create_dump_dir.c
@@ -101,15 +101,7 @@ struct dump_dir *create_dump_dir_from_problem_data_ext(problem_data_t *problem_d
if (value->flags & CD_FLAG_BIN)
{
- char *dest = concat_path_file(dd->dd_dirname, name);
- log_info("copying '%s' to '%s'", value->content, dest);
- off_t copied = copy_file(value->content, dest, DEFAULT_DUMP_DIR_MODE | S_IROTH);
- if (copied < 0)
- error_msg("Can't copy %s to %s", value->content, dest);
- else
- log_info("copied %li bytes", (unsigned long)copied);
- free(dest);
-
+ dd_copy_file(dd, name, value->content);
continue;
}
diff --git a/src/lib/dump_dir.c b/src/lib/dump_dir.c
index 1e6ce64..d7ddec7 100644
--- a/src/lib/dump_dir.c
+++ b/src/lib/dump_dir.c
@@ -1487,6 +1487,22 @@ int dd_mark_as_notreportable(struct dump_dir *dd, const char *reason)
return 0;
}
+int dd_copy_file(struct dump_dir *dd, const char *name, const char *source_path)
+{
+ char *dest = concat_path_file(dd->dd_dirname, name);
+
+ log_debug("copying '%s' to '%s'", source_path, dest);
+
+ off_t copied = copy_file(source_path, dest, DEFAULT_DUMP_DIR_MODE | S_IROTH);
+ if (copied < 0)
+ error_msg("Can't copy %s to %s", source_path, dest);
+ else
+ log_debug("copied %li bytes", (unsigned long)copied);
+
+ free(dest);
+ return copied < 0;
+}
+
/* flags - for future needs */
int dd_create_archive(struct dump_dir *dd, const char *archive_name,
const_string_vector_const_ptr_t exclude_elements, int flags)
--
1.8.3.1