Commit 29ebd7bc authored by Slava Monich's avatar Slava Monich

[mms-lib] Replaced g_file_copy with mms_file_copy

Now that qemu no longer crashes during tests, enabled rpm check
parent 96462e1e
......@@ -177,6 +177,51 @@ mms_write_bytes(
return mms_write_file(dir, file, data, len, path);
}
/**
* Copies the file. Assumes that the destination directory exists.
*/
gboolean
mms_file_copy(
const char* src,
const char* dest,
GError** error)
{
gboolean ok = FALSE;
int out = open(dest, O_CREAT|O_WRONLY|O_TRUNC|O_BINARY, MMS_FILE_PERM);
if (out >= 0) {
int in = open(src, O_RDONLY | O_BINARY);
if (in >= 0) {
int nbytes;
const size_t buflen = 4096;
void* buf = g_malloc(buflen);
ok = TRUE;
while ((nbytes = read(in, buf, buflen)) > 0) {
if (write(out, buf, nbytes) < nbytes) {
ok = FALSE;
MMS_ERROR(error, MMS_LIB_ERROR_IO,
"Failed to write %s: %s", dest, strerror(errno));
break;
}
}
if (nbytes < 0) {
ok = FALSE;
MMS_ERROR(error, MMS_LIB_ERROR_IO,
"Failed to read %s: %s", src, strerror(errno));
}
g_free(buf);
close(in);
} else {
MMS_ERROR(error, MMS_LIB_ERROR_IO,
"Failed to open file %s: %s", src, strerror(errno));
}
close(out);
} else {
MMS_ERROR(error, MMS_LIB_ERROR_IO,
"Failed to create file %s: %s", dest, strerror(errno));
}
return ok;
}
/*
* Local Variables:
* mode: C
......
......@@ -69,6 +69,12 @@ mms_write_bytes(
GBytes* bytes,
char** path);
gboolean
mms_file_copy(
const char* src,
const char* dest,
GError** error);
#define mms_message_dir(config,id) \
(g_strconcat((config)->root_dir, "/" MMS_MESSAGE_DIR "/" , id, NULL))
#define mms_task_dir(task) \
......
......@@ -467,8 +467,6 @@ mms_task_encode_prepare_attachments(
MMSAttachmentInfo info = parts[i];
char* detected_type = NULL;
char* path;
GFile* src;
GFile* dest;
if (!info.content_type || !info.content_type[0]) {
detected_type = mms_attachment_guess_content_type(info.file_name);
......@@ -479,9 +477,7 @@ mms_task_encode_prepare_attachments(
g_basename(info.file_name), info.content_type);
G_GNUC_END_IGNORE_DEPRECATIONS;
src = g_file_new_for_path(info.file_name);
dest = g_file_new_for_path(path);
if (g_file_copy(src, dest, 0, NULL, NULL, NULL, error)) {
if (mms_file_copy(info.file_name, path, error)) {
info.file_name = path;
attachment = mms_attachment_new(config, &info, error);
if (attachment) {
......@@ -494,8 +490,7 @@ mms_task_encode_prepare_attachments(
} else if (error && *error) {
MMS_ERR("%s", MMS_ERRMSG(*error));
}
g_object_unref(src);
g_object_unref(dest);
g_free(detected_type);
g_free(path);
if (!attachment) break;
......
......@@ -15,6 +15,7 @@
#include "mms_attachment.h"
#include "mms_lib_util.h"
#include "mms_lib_log.h"
#include "mms_file_util.h"
#include "mms_log.h"
#include <libexif/exif-content.h>
......@@ -342,31 +343,6 @@ test_png_size(
return ok;
}
static
gboolean
test_file_copy(
const char* src,
const char* dest)
{
gboolean ok = FALSE;
FILE* in = fopen(src, "rb");
if (in) {
FILE* out = fopen(dest, "wb");
if (out) {
const size_t buflen = 4096;
size_t nbytes;
void* buf = g_malloc(buflen);
while ((nbytes = fread(buf, 1, buflen, in)) > 0 &&
fwrite(buf, 1, nbytes, out) == nbytes);
ok = (feof(in) && !ferror(in) && !ferror(out));
g_free(buf);
fclose(out);
}
fclose(in);
}
return ok;
}
static
int
test_run_one(
......@@ -382,7 +358,7 @@ test_run_one(
if (dir) {
GError* error = NULL;
char* testfile = g_strconcat(dir, "/", name, NULL);
if (test_file_copy(test->file, testfile)) {
if (mms_file_copy(test->file, testfile, NULL)) {
MMSAttachment* at;
MMSAttachmentInfo info;
MMSConfig test_config = *config;
......
......@@ -12,6 +12,8 @@ Requires: ofono
BuildRequires: python
BuildRequires: file-devel
BuildRequires: libpng-devel
BuildRequires: libexif-devel
BuildRequires: libjpeg-turbo-devel
BuildRequires: pkgconfig(glib-2.0) >= 2.32
BuildRequires: pkgconfig(libsoup-2.4) >= 2.38
......@@ -62,6 +64,9 @@ cp %{src}/%{dbusname}.push.conf %{buildroot}%{pushconfig}/%{dbusname}.conf
cp mms-dump/build/release/mms-dump %{buildroot}%{_prefix}/bin/
cp mms-send/build/release/mms-send %{buildroot}%{_prefix}/bin/
%check
make -C mms-lib/test test
%files
%defattr(-,root,root,-)
%config %{dbuspolicy}/%{dbusname}.conf
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment