From: Jiwoong Im Date: Mon, 29 Aug 2016 08:06:19 +0000 (+0900) Subject: add vconf key migration tool (2.4 -> 3.0) X-Git-Tag: accepted/tizen/common/20160905.171445~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4550f3ca759d127a556c65d35f96d492e287ed47;p=platform%2Fcore%2Fsystem%2Fbuxton2.git add vconf key migration tool (2.4 -> 3.0) Change-Id: I1e78d043b712e6667ad981cf80f1ac842ade2140 Signed-off-by: Jiwoong Im --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 8ca9b31..9d2b8c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,6 +66,7 @@ ADD_SUBDIRECTORY(backend) ADD_SUBDIRECTORY(lib) ADD_SUBDIRECTORY(client) ADD_SUBDIRECTORY(vconf-compat) +ADD_SUBDIRECTORY(migration) IF(BUILD_EXAMPLE) ADD_SUBDIRECTORY(example) diff --git a/migration/CMakeLists.txt b/migration/CMakeLists.txt new file mode 100644 index 0000000..d7da168 --- /dev/null +++ b/migration/CMakeLists.txt @@ -0,0 +1,20 @@ +# migration tool build + +PKG_CHECK_MODULES(V_PKGS REQUIRED vconf-internal-keys) + +FOREACH(flag ${V_PKGS_CFLAGS}) + SET(VCONF_CFLAGS "${VCONF_CFLAGS} ${flag}") +ENDFOREACH() +SET(VCONF_CFLAGS "-fvisibility=hidden ${VCONF_CFLAGS}") + + +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/lib/include) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/vconf-compat) + +ADD_EXECUTABLE(vconf_migration vconf_migration.c) +TARGET_LINK_LIBRARIES(vconf_migration vconf) +SET_TARGET_PROPERTIES(vconf_migration PROPERTIES + COMPILE_FLAGS ${VCONF_CFLAGS} +) + +INSTALL(TARGETS vconf_migration DESTINATION bin) diff --git a/migration/vconf_migration.c b/migration/vconf_migration.c new file mode 100644 index 0000000..3ade7a4 --- /dev/null +++ b/migration/vconf_migration.c @@ -0,0 +1,194 @@ +/* + * Vconf migration tool (2.4 -> 3.0) + * + * Copyright (C) 2016 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License) + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#define BUF_LEN 1024 + +static void _get_vconf_keys(const char *path, keylist_t *keylist) +{ + int type = 0; + FILE *fp = NULL; + int read_size = 0; + char *keyname; + int i; + + fp = fopen(path, "r+"); + if (fp == NULL) { + fprintf(stderr, "unable to open key path[%s] : %d", path, errno); + return; + } + + read_size = fread((void *)&type, sizeof(int), 1, fp); + if ((read_size <= 0) || (read_size > sizeof(int))) { + if (!ferror(fp)) { + fprintf(stderr, "number of read items for type is 0 with false ferror. err : %d", errno); + errno = ENODATA; + } + goto out_func; + } + + keyname = strrchr(path, '/'); + + while (*(keyname - 1) != '/') + keyname--; + + i = 0; + while (keyname[i] != '\0') { + if (keyname[i] == '+') + keyname[i] = '/'; + i++; + } + + /* read data value */ + switch (type) { + case VCONF_TYPE_INT: + { + int value_int = 0; + read_size = fread((void *)&value_int, sizeof(int), 1, fp); + if ((read_size <= 0) || (read_size > sizeof(int))) { + if (!ferror(fp)) + fprintf(stderr, "number of read items for value is wrong. err : %d", errno); + goto out_func; + } else { + vconf_keylist_add_int(keylist, keyname, value_int); + } + + break; + } + case VCONF_TYPE_DOUBLE: + { + double value_dbl = 0; + read_size = fread((void *)&value_dbl, sizeof(double), 1, fp); + if ((read_size <= 0) || (read_size > sizeof(double))) { + if (!ferror(fp)) + fprintf(stderr, "number of read items for value is wrong. err : %d", errno); + goto out_func; + } else { + vconf_keylist_add_dbl(keylist, keyname, value_dbl); + } + + break; + } + case VCONF_TYPE_BOOL: + { + int value_int = 0; + read_size = fread((void *)&value_int, sizeof(int), 1, fp); + if ((read_size <= 0) || (read_size > sizeof(int))) { + if (!ferror(fp)) + fprintf(stderr, "number of read items for value is wrong. err : %d", errno); + goto out_func; + } else { + vconf_keylist_add_bool(keylist, keyname, value_int); + } + + break; + } + case VCONF_TYPE_STRING: + { + char file_buf[BUF_LEN] = {0,}; + char *value = NULL; + int value_size = 0; + + while (fgets(file_buf, sizeof(file_buf), fp)) { + if (value) { + value_size = value_size + strlen(file_buf); + value = (char *) realloc(value, value_size); + if (value == NULL) + break; + strncat(value, file_buf, strlen(file_buf)); + } else { + value_size = strlen(file_buf) + 1; + value = (char *)malloc(value_size); + if (value == NULL) + break; + memset(value, 0x00, value_size); + strncpy(value, file_buf, strlen(file_buf)); + } + } + + if (ferror(fp)) { + fprintf(stderr, "fgets error for getting string key : %d", errno); + } else { + if (value) + vconf_keylist_add_str(keylist, keyname, value); + else + vconf_keylist_add_str(keylist, keyname, ""); + } + if (value) + free(value); + + break; + } + } + +out_func: + fclose(fp); +} + +static int _load_vconf_dir(const char *directory) +{ + DIR *dir; + struct dirent file_info; + struct dirent *result; + char buf[BUF_LEN]; + keylist_t *keylist = vconf_keylist_new(); + + dir = opendir(directory); + if (!dir) + return -1; + + while (readdir_r(dir, &file_info, &result) == 0) { + if (result == NULL) + break; + if (file_info.d_type != DT_REG) + continue; + + snprintf(buf, sizeof(buf), "%s/%s", directory, + file_info.d_name); + + _get_vconf_keys(buf, keylist); + } + + vconf_set(keylist); + + vconf_keylist_free(keylist); + closedir(dir); + + return 0; +} + +int main(int argc, char *argv[]) +{ + if (_load_vconf_dir("/opt/var/kdb/db") < 0) + fprintf(stderr, "fail to migrate db backend keys : %d", errno); + + if (_load_vconf_dir("/opt/var/kdb/file") < 0) + fprintf(stderr, "fail to migrate db backend keys : %d", errno); + + return EXIT_SUCCESS; +} diff --git a/packaging/buxton2.spec b/packaging/buxton2.spec index 6e80a81..d22e74f 100644 --- a/packaging/buxton2.spec +++ b/packaging/buxton2.spec @@ -182,7 +182,8 @@ chsmack -a System %{basedbdir}/* %{_unitdir}/sockets.target.wants/%{name}.socket %attr(0700,buxton,buxton) %dir %{_localstatedir}/lib/%{name} %attr(0700,buxton,buxton) %dir %{basedbdir} -%{upgrade_script_path}/100.buxton2_upgrade.sh +%attr(0750,root,root) %{upgrade_script_path}/100.buxton2_upgrade.sh +%attr(0750,root,root) %{_bindir}/vconf_migration %files devel %manifest %{name}.manifest diff --git a/scripts/100.buxton2_upgrade.sh b/scripts/100.buxton2_upgrade.sh index bbd3273..a86e583 100644 --- a/scripts/100.buxton2_upgrade.sh +++ b/scripts/100.buxton2_upgrade.sh @@ -11,3 +11,5 @@ chown -R buxton:buxton $RW_DB_PATH chmod 700 $RW_DB_PATH chsmack -a System $RW_DB_PATH chsmack -t $RW_DB_PATH + +vconf_migration