Commit 754e0edf authored by Slava Monich's avatar Slava Monich

[mms-lib] Use g_build_filename to build filenames

parent 92cdbc24
/*
* Copyright (C) 2013-2016 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2013-2020 Jolla Ltd.
* Copyright (C) 2013-2020 Slava Monich <slava.monich@jolla.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
......@@ -59,13 +59,12 @@ mms_attachment_image_prepare_filename(
image->attachment.file_name = image->attachment.original_file;
} else {
char* dir = g_path_get_dirname(image->attachment.original_file);
char* subdir = g_strconcat(dir, "/" MMS_RESIZE_DIR, NULL);
char* fname = g_path_get_basename(image->attachment.original_file);
char* subdir = g_build_filename(dir, MMS_RESIZE_DIR, NULL);
g_mkdir_with_parents(subdir, MMS_DIR_PERM);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
image->resized = g_strconcat(subdir, "/",
g_basename(image->attachment.original_file), NULL);
G_GNUC_END_IGNORE_DEPRECATIONS;
image->resized = g_build_filename(subdir, fname, NULL);
g_free(dir);
g_free(fname);
g_free(subdir);
}
return image->resized;
......
/*
* Copyright (C) 2013-2018 Jolla Ltd.
* Copyright (C) 2013-2018 Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2013-2020 Jolla Ltd.
* Copyright (C) 2013-2020 Slava Monich <slava.monich@jolla.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
......@@ -800,7 +800,7 @@ mms_dispatcher_finalize(
{
MMSTask* task;
const char* root_dir = disp->settings->config->root_dir;
char* msg_dir = g_strconcat(root_dir, "/" MMS_MESSAGE_DIR "/", NULL);
char* msg_dir = g_build_filename(root_dir, MMS_MESSAGE_DIR, NULL);
GVERBOSE_("");
mms_handler_remove_callback(disp->handler, disp->handler_done_id);
mms_connman_remove_callback(disp->cm, disp->connman_done_id);
......
/*
* Copyright (C) 2013-2016 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2013-2020 Jolla Ltd.
* Copyright (C) 2013-2020 Slava Monich <slava.monich@jolla.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
......@@ -108,7 +108,7 @@ mms_create_file(
int fd = -1;
int err = g_mkdir_with_parents(dir, MMS_DIR_PERM);
if (!err || errno == EEXIST) {
char* fname = g_strconcat(dir, "/", file, NULL);
char* fname = g_build_filename(dir, file, NULL);
fd = open(fname, O_CREAT|O_RDWR|O_TRUNC|O_BINARY, MMS_FILE_PERM);
if (fd < 0) {
MMS_ERROR(error, MMS_LIB_ERROR_IO,
......@@ -140,7 +140,7 @@ mms_write_file(
int err = g_mkdir_with_parents(dir, MMS_DIR_PERM);
if (!err || errno == EEXIST) {
GError* error = NULL;
char* fname = g_strconcat(dir, "/", file, NULL);
char* fname = g_build_filename(dir, file, NULL);
unlink(fname);
if (g_file_set_contents(fname, data, size, &error)) {
GVERBOSE("Created %s", fname);
......
/*
* Copyright (C) 2013-2015 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2013-2020 Jolla Ltd.
* Copyright (C) 2013-2020 Slava Monich <slava.monich@jolla.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
......@@ -13,8 +13,8 @@
*
*/
#ifndef JOLLA_MMS_FILE_UTIL_H
#define JOLLA_MMS_FILE_UTIL_H
#ifndef SAILFISH_MMS_FILE_UTIL_H
#define SAILFISH_MMS_FILE_UTIL_H
#include "mms_lib_types.h"
......@@ -86,14 +86,14 @@ mms_file_decode(
GError** error);
#define mms_message_dir(config,id) \
(g_strconcat((config)->root_dir, "/" MMS_MESSAGE_DIR "/" , id, NULL))
(g_build_filename((config)->root_dir, MMS_MESSAGE_DIR, id, NULL))
#define mms_task_dir(task) \
mms_message_dir(task_config(task),(task)->id)
#define mms_task_file(task,file) \
(g_strconcat(task_config(task)->root_dir, "/" MMS_MESSAGE_DIR "/" , \
(task)->id, "/", file, NULL))
(g_build_filename(task_config(task)->root_dir, MMS_MESSAGE_DIR, \
(task)->id, file, NULL))
#endif /* JOLLA_MMS_FILE_UTIL_H */
#endif /* SAILFISH_MMS_FILE_UTIL_H */
/*
* Local Variables:
......
......@@ -359,10 +359,10 @@ mms_task_make_id(
{
if (!task->id || !task->id[0]) {
const char* root_dir = task_config(task)->root_dir;
char* msgdir = g_strconcat(root_dir, "/", MMS_MESSAGE_DIR, NULL);
char* msgdir = g_build_filename(root_dir, MMS_MESSAGE_DIR, NULL);
int err = g_mkdir_with_parents(msgdir, MMS_DIR_PERM);
if (!err || errno == EEXIST) {
char* tmpl = g_strconcat(msgdir, "/XXXXXX" , NULL);
char* tmpl = g_build_filename(msgdir, "XXXXXX", NULL);
char* taskdir = g_mkdtemp_full(tmpl, MMS_DIR_PERM);
if (taskdir) {
g_free(task->id);
......
/*
* Copyright (C) 2013-2016 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2013-2020 Jolla Ltd.
* Copyright (C) 2013-2020 Slava Monich <slava.monich@jolla.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
......@@ -122,7 +122,7 @@ mms_task_decode_part(
orig_file = mms_task_decode_add_file_name(part_files, default_name);
g_free(default_name);
part->orig = g_strconcat(dir, "/", orig_file, NULL);
part->orig = g_build_filename(dir, orig_file, NULL);
if (rename(part->file, part->orig) == 0) {
GError* error = NULL;
if (!mms_file_decode(part->orig, part->file, enc, &error)) {
......@@ -202,7 +202,7 @@ mms_task_decode_retrieve_conf(
break;
}
msg->parts_dir = g_strconcat(dir, "/" , MMS_PARTS_DIR, NULL);
msg->parts_dir = g_build_filename(dir, MMS_PARTS_DIR, NULL);
for (i=0, entry = pdu->attachments; entry; entry = entry->next, i++) {
struct mms_attachment* attach = entry->data;
const char* name = attach->content_location ?
......
/*
* Copyright (C) 2013-2016 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2013-2020 Jolla Ltd.
* Copyright (C) 2013-2020 Slava Monich <slava.monich@jolla.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
......@@ -426,13 +426,13 @@ mms_task_encode_generate_path(
}
/* Most likely the very first check would succeed */
path = g_strconcat(dir, "/", file, NULL);
path = g_build_filename(dir, file, NULL);
if (g_file_test(path, G_FILE_TEST_IS_REGULAR)) {
for (i=0; i<100; i++) {
char* newfile = g_strconcat("_", file, NULL);
g_free(tmpfile);
g_free(path);
path = g_strconcat(dir, "/", newfile, NULL);
path = g_build_filename(dir, newfile, NULL);
file = tmpfile = newfile;
if (!g_file_test(path, G_FILE_TEST_IS_REGULAR)) break;
}
......
/*
* Copyright (C) 2013-2017 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2013-2020 Jolla Ltd.
* Copyright (C) 2013-2020 Slava Monich <slava.monich@jolla.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
......@@ -93,7 +93,7 @@ mms_task_notification_done(
GDEBUG(" Database id: %s", id);
if (task->id) {
char* olddir = mms_task_dir(task);
char* file = g_strconcat(olddir, "/"
char* file = g_build_filename(olddir,
MMS_NOTIFICATION_IND_FILE, NULL);
/* Replace fake id with the real one */
g_free(task->id);
......
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