From 087aac2ab6d6d9e3a76a7818ebea9f075bd21766 Mon Sep 17 00:00:00 2001 From: InHong Han Date: Thu, 29 Oct 2020 10:28:04 +0900 Subject: [PATCH] Fixed issue regarding not able to check for the existence of the sticker Change-Id: Id684199f552d04e6d3c865eeafe5f49089d533fd --- client/sticker_defs.h | 1 + provider/sticker_provider.c | 29 +++++++++++++++++++++++------ server/stickerd_data_manager.c | 1 - 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/client/sticker_defs.h b/client/sticker_defs.h index 69167ec..f00e7da 100644 --- a/client/sticker_defs.h +++ b/client/sticker_defs.h @@ -49,6 +49,7 @@ extern "C" { } \ } \ } while (0) +#define STICKER_DIRECTORY "/opt/usr/share/sticker-data" typedef enum { STICKER_CLIENT_LIB_NONE, diff --git a/provider/sticker_provider.c b/provider/sticker_provider.c index 82e32c8..8b5ef32 100644 --- a/provider/sticker_provider.c +++ b/provider/sticker_provider.c @@ -136,26 +136,43 @@ EXPORT_API int sticker_provider_insert_data(sticker_provider_h provider_handle, if (!provider_handle || !data_handle || (data_handle->sticker_info_id > 0) || !data_handle->uri) return STICKER_ERROR_INVALID_PARAMETER; - ret = sticker_dbus_check_file_exists(provider_handle->gdbus_connection, data_handle->uri, &is_exist); + int len = strlen(STICKER_DIRECTORY) + strlen(data_handle->app_id) + strlen(data_handle->uri) + 3; + char *new_path = (char *)calloc(len, sizeof(char)); + + if (data_handle->uri[0] == '/') + snprintf(new_path, len, "%s/%s%s",STICKER_DIRECTORY, data_handle->app_id, data_handle->uri); + else + snprintf(new_path, len, "%s/%s/%s",STICKER_DIRECTORY, data_handle->app_id, data_handle->uri); + + ret = sticker_dbus_check_file_exists(provider_handle->gdbus_connection, new_path, &is_exist); if (ret != STICKER_ERROR_NONE) { LOGE("Failed to check file exists : %d", ret); - return STICKER_ERROR_OPERATION_FAILED; + ret = STICKER_ERROR_OPERATION_FAILED; + goto cleanup; } if (is_exist) { LOGE("Sticker already exists"); - return STICKER_ERROR_FILE_EXISTS; + ret = STICKER_ERROR_FILE_EXISTS; + goto cleanup; } ret = sticker_dbus_insert_sticker_info(provider_handle->gdbus_connection, data_handle); if (ret != STICKER_ERROR_NONE) { LOGE("Failed to insert sticker information : %d", ret); if (ret == STICKER_CLIENT_ERROR_NO_SUCH_FILE) - return STICKER_ERROR_NO_SUCH_FILE; + ret = STICKER_ERROR_NO_SUCH_FILE; else - return STICKER_ERROR_OPERATION_FAILED; + ret = STICKER_ERROR_OPERATION_FAILED; } - return STICKER_ERROR_NONE; + +cleanup: + if (new_path) { + free(new_path); + new_path = NULL; + } + + return ret; } EXPORT_API int sticker_provider_insert_data_by_json_file(sticker_provider_h provider_handle, const char *json_path, sticker_provider_insert_finished_cb callback, void *user_data) diff --git a/server/stickerd_data_manager.c b/server/stickerd_data_manager.c index 1be9971..c9b8f8b 100644 --- a/server/stickerd_data_manager.c +++ b/server/stickerd_data_manager.c @@ -39,7 +39,6 @@ #endif #define LOG_TAG "STICKERD_DATA_MANAGER" -#define STICKER_DIRECTORY "/opt/usr/share/sticker-data" #define MAX_ERROR_BUFFER 256 static GHashTable *_monitoring_hash = NULL; -- 2.7.4