3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * Licensed under the Apache License, Version 2.0 (the License);
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
21 #include "utility/sync_util.h"
22 #include "utility/fw_file.h"
24 #include "fsapi/operation.h"
27 #define EXPORT_API __attribute__ ((visibility("default")))
30 #ifndef SYNC_AGENT_LOG
32 #define LOG_TAG "AF_UTIL_FILE"
35 #define UTIL_DEFAULT_ACCOUNT_PLUGIN_FOLDER "/opt/data/sync-agent/db"
37 EXPORT_API int sync_agent_set_int_into_file(char *file_path, int value)
41 retvm_if(file_path == NULL, 0, "file_path parameter is NULL !!");
44 char *temp_value = NULL;
46 if (!sync_agent_is_existing_fs(UTIL_DEFAULT_ACCOUNT_PLUGIN_FOLDER)) {
47 if (!sync_agent_create_directory(UTIL_DEFAULT_ACCOUNT_PLUGIN_FOLDER)) {
48 _DEBUG_ERROR("Failed to create default folder");
54 snprintf(path, sizeof(path), "%s/%s", UTIL_DEFAULT_ACCOUNT_PLUGIN_FOLDER, file_path);
55 temp_value = g_strdup_printf("%d", value);
57 if (temp_value != NULL) {
58 _DEBUG_INFO("path = %s", path);
59 _DEBUG_INFO("value = %s", temp_value);
61 if (!sync_agent_write_whole_file(path, temp_value, strlen(temp_value), true)) {
62 _DEBUG_ERROR("Failed write data");
69 _DEBUG_ERROR("strdup() FAIL !!!");
79 EXPORT_API int sync_agent_get_int_from_file(char *file_path, int *value)
83 retvm_if(file_path == NULL, 0, "file_path parameter is NULL !!");
84 retvm_if(value == NULL, 0, "value parameter is NULL !!");
87 char *temp_value = NULL;
90 snprintf(path, sizeof(path), "%s/%s", UTIL_DEFAULT_ACCOUNT_PLUGIN_FOLDER, file_path);
92 _DEBUG_INFO("path = %s", path);
93 if (!sync_agent_read_whole_file(path, &temp_value, &size)) {
94 _DEBUG_ERROR("Failed to read file");
99 *value = atoi(temp_value);
101 _DEBUG_INFO("value = %d", *value);
103 // if (temp_value != NULL)
111 EXPORT_API int sync_agent_unset_file(char *file_path)
115 retvm_if(file_path == NULL, 0, "file_path parameter is NULL !!");
119 snprintf(path, sizeof(path), "%s/%s", UTIL_DEFAULT_ACCOUNT_PLUGIN_FOLDER, file_path);
120 _DEBUG_INFO("path = %s", path);
124 return sync_agent_delete_file(path);