From 66d35d180db4dcdb818883c5030e555f15f4befd Mon Sep 17 00:00:00 2001 From: jusung son Date: Fri, 25 Aug 2017 15:53:09 +0900 Subject: [PATCH] Modify upgrade script - delete the codes for 3.0 - remove garbage data Change-Id: I10394f7ebabfb92191a91db0b7f4e51b22668ccd Signed-off-by: jusung son --- CMakeLists.txt | 1 - migration/CMakeLists.txt | 19 ---- migration/vconf_migration.c | 226 ----------------------------------------- packaging/buxton2.spec | 1 - scripts/299.buxton2_upgrade.sh | 21 +--- 5 files changed, 2 insertions(+), 266 deletions(-) mode change 100644 => 100755 CMakeLists.txt delete mode 100644 migration/CMakeLists.txt delete mode 100644 migration/vconf_migration.c mode change 100644 => 100755 scripts/299.buxton2_upgrade.sh diff --git a/CMakeLists.txt b/CMakeLists.txt old mode 100644 new mode 100755 index e3085eb..15d420c --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,7 +66,6 @@ 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 deleted file mode 100644 index 269b714..0000000 --- a/migration/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -# migration tool build -INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/lib/include) - -SET(SRC - vconf_migration.c - ../common/common.c - ../common/direct.c - ../common/backends.c - ../common/config.c - ../common/serialize.c - ../common/cache.c -) - -ADD_EXECUTABLE(vconf_migration ${SRC}) -SET_TARGET_PROPERTIES(vconf_migration PROPERTIES - LINK_FLAGS "-fPIE" -) -TARGET_LINK_LIBRARIES(vconf_migration vconf buxton2 -ldl) -INSTALL(TARGETS vconf_migration DESTINATION bin) diff --git a/migration/vconf_migration.c b/migration/vconf_migration.c deleted file mode 100644 index 9f80102..0000000 --- a/migration/vconf_migration.c +++ /dev/null @@ -1,226 +0,0 @@ -/* - * 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 - -#include "direct.h" -#include "common.h" - -#define BUF_LEN 1024 - -enum vconf_t { - VCONF_TYPE_NONE = 0, /**< Vconf none type for Error detection */ - VCONF_TYPE_STRING = 40, /**< Vconf string type */ - VCONF_TYPE_INT = 41, /**< Vconf integer type */ - VCONF_TYPE_DOUBLE = 42, /**< Vconf double type */ - VCONF_TYPE_BOOL = 43, /**< Vconf boolean type */ - VCONF_TYPE_DIR /**< Vconf directory type */ -}; - -struct buxton_layer *system_layer; - -static void _set_vconf_key(const char *path) -{ - 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\n", 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\n", errno); - errno = ENODATA; - } - goto out_func; - } - - keyname = strrchr(path, '/'); - - if (keyname == NULL) - goto out_func; - - 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\n", errno); - goto out_func; - } else { - struct buxton_value *v; - v = buxton_value_create_int32(value_int); - direct_set(system_layer, keyname, v); - buxton_value_free(v); - } - - 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\n", errno); - goto out_func; - } else { - struct buxton_value *v; - v = buxton_value_create_double(value_dbl); - direct_set(system_layer, keyname, v); - buxton_value_free(v); - } - - 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\n", errno); - goto out_func; - } else { - struct buxton_value *v; - v = buxton_value_create_boolean(value_int); - direct_set(system_layer, keyname, v); - buxton_value_free(v); - } - - 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\n", errno); - } else { - struct buxton_value *v; - if (value) - v = buxton_value_create_string(value); - else - v = buxton_value_create_string(""); - direct_set(system_layer, keyname, v); - buxton_value_free(v); - } - 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]; - - 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); - - _set_vconf_key(buf); - } - - closedir(dir); - - return 0; -} - -int main(int argc, char *argv[]) -{ - direct_init(MODULE_DIR, CONFPATH); - system_layer = buxton_create_layer("system"); - buxton_layer_set_type(system_layer, BUXTON_LAYER_NORMAL); - - if (_load_vconf_dir("/opt/var/kdb/db") < 0) - fprintf(stderr, "fail to migrate db backend keys : %d\n", errno); - - if (_load_vconf_dir("/opt/var/kdb/file") < 0) - fprintf(stderr, "fail to migrate file backend keys : %d\n", errno); - - buxton_free_layer(system_layer); - direct_exit(); - - return EXIT_SUCCESS; -} diff --git a/packaging/buxton2.spec b/packaging/buxton2.spec index b1b2465..7216139 100755 --- a/packaging/buxton2.spec +++ b/packaging/buxton2.spec @@ -190,7 +190,6 @@ chsmack -a System %{dbdir}/* %attr(0700,buxton,buxton) %dir %{_localstatedir}/lib/%{name} %attr(0700,buxton,buxton) %dir %{basedbdir} %attr(0750,root,root) %{upgrade_script_path}/299.buxton2_upgrade.sh -%attr(0750,root,root) %{_bindir}/vconf_migration %files devel %manifest %{name}.manifest diff --git a/scripts/299.buxton2_upgrade.sh b/scripts/299.buxton2_upgrade.sh old mode 100644 new mode 100755 index 9daf128..104979e --- a/scripts/299.buxton2_upgrade.sh +++ b/scripts/299.buxton2_upgrade.sh @@ -1,25 +1,8 @@ #!/bin/sh # -# buxton upgrade initialize script (2.4 -> 3.0) +# buxton upgrade initialize script (3.0 -> 4.0) # -PATH=/bin:/usr/bin:/sbin:/usr/sbin -RW_DB_PATH=/var/lib/buxton2 -VCONF_KEY_PATH=/opt/var/kdb - buxton2ctl security-disable -mkdir -p $RW_DB_PATH -chmod 700 $RW_DB_PATH -chsmack -a System $RW_DB_PATH -chsmack -t $RW_DB_PATH - -if [ -d "$VCONF_KEY_PATH" ] -then - vconf_migration - rm -r $VCONF_KEY_PATH -fi - -chown -R buxton:buxton $RW_DB_PATH -chmod 0600 $RW_DB_PATH/* -chsmack -a System $RW_DB_PATH/* +buxton2ctl remove-garbage-data system -- 2.7.4