Implement WRT upgrade tool from 2.4 to 3.0
authorInhwan Lee <ideal.lee@samsung.com>
Mon, 12 Sep 2016 09:24:53 +0000 (18:24 +0900)
committerJongHeon Choi <j-h.choi@samsung.com>
Wed, 21 Sep 2016 02:27:38 +0000 (11:27 +0900)
Change-Id: I868723234fdaea7b6e7a55c57511a233b0e691ab

common/app_db.cc
common/app_db_sqlite.h
packaging/crosswalk-tizen.spec
wrt-upgrade/310.wrt.upgrade.sh [new file with mode: 0644]
wrt-upgrade/wrt-upgrade-info.cc [new file with mode: 0644]
wrt-upgrade/wrt-upgrade-info.h [new file with mode: 0644]
wrt-upgrade/wrt-upgrade.cc [new file with mode: 0644]
wrt-upgrade/wrt-upgrade.gyp [new file with mode: 0644]
wrt-upgrade/wrt-upgrade.h [new file with mode: 0644]
xwalk_tizen.gyp

index 9ae065a..fa6a3c6 100644 (file)
 #include <app.h>
 #include <sqlite3.h>
 #include <unistd.h>
+#include <fstream>
 #endif
 
 #include <memory>
 
 #include "common/logger.h"
 #include "common/string_utils.h"
+#include "common/file_utils.h"
+#include "common/picojson.h"
+
 #ifndef USE_APP_PREFERENCE
 #include "common/app_db_sqlite.h"
 #endif
@@ -136,6 +140,72 @@ SqliteDB::~SqliteDB() {
   }
 }
 
+void SqliteDB::MigrationAppdb() {
+  // file check
+  std::string migration_path = app_data_path_ + ".runtime.migration";
+  if (!common::utils::Exists(migration_path)) {
+    return;
+  } else {
+    LOGGER(DEBUG) << "Migration file found : " << migration_path;
+  }
+
+  std::ifstream migration_file(migration_path);
+  if (!migration_file.is_open()) {
+    LOGGER(ERROR) << "Fail to open file";
+    return;
+  }
+  picojson::value v;
+  std::string err;
+  err = picojson::parse(v, migration_file);
+  if (!err.empty()) {
+    LOGGER(ERROR) << "Fail to parse file :" << err;
+    return;
+  }
+
+  LOGGER(DEBUG) << "Start to get list data";
+
+  picojson::array data_list;
+
+  if (!v.get("preference").is<picojson::null>()) {
+    picojson::array preference_list
+      = v.get("preference").get<picojson::array>();
+    data_list.insert(data_list.end(),
+                     preference_list.begin(),
+                     preference_list.end());
+  }
+  if (!v.get("certificate").is<picojson::null>()) {
+    picojson::array certificate_list
+      = v.get("certificate").get<picojson::array>();
+    data_list.insert(data_list.end(),
+                     certificate_list.begin(),
+                     certificate_list.end());
+  }
+  if (!v.get("security_origin").is<picojson::null>()) {
+    picojson::array security_origin_list
+      = v.get("security_origin").get<picojson::array>();
+    data_list.insert(data_list.end(),
+                     security_origin_list.begin(),
+                     security_origin_list.end());
+  }
+
+  for (auto it = data_list.begin(); it != data_list.end(); ++it) {
+    if (!it->is<picojson::object>()) continue;
+    std::string section = it->get("section").to_str();
+    std::string key = it->get("key").to_str();
+    std::string value = it->get("value").to_str();
+
+    LOGGER(DEBUG) << "INPUT[" << section << "][" << key << "][" << value << "]";
+    Set(section, key, value);
+  }
+
+  LOGGER(DEBUG) << "Migration complete";
+
+  if (0 != remove(migration_path.c_str())) {
+    LOGGER(ERROR) << "Fail to remove migration file";
+  }
+}
+
+
 void SqliteDB::Initialize() {
   if (app_data_path_.empty()) {
     LOGGER(ERROR) << "app data path was empty";
@@ -166,6 +236,7 @@ void SqliteDB::Initialize() {
     if (errmsg)
       sqlite3_free(errmsg);
   }
+  MigrationAppdb();
 }
 
 bool SqliteDB::HasKey(const std::string& section,
index 8804831..f59f614 100644 (file)
@@ -43,6 +43,7 @@ class SqliteDB : public AppDB {
 
  private:
   void Initialize();
+  void MigrationAppdb();
   std::string app_data_path_;
   sqlite3* sqldb_;
 };
index bb0fe38..1b29b72 100755 (executable)
@@ -128,6 +128,7 @@ mkdir -p %{buildroot}%{_datadir}/locale
 mkdir -p %{buildroot}%{_datadir}/icons/xwalk
 mkdir -p %{buildroot}%{_datadir}/edje/xwalk
 mkdir -p %{buildroot}%{extension_path}
+mkdir -p %{buildroot}%{_datadir}/upgrade/scripts
 
 # License files
 cp LICENSE %{buildroot}%{_datadir}/license/%{name}
@@ -170,6 +171,10 @@ install -p -m 755 out/Default/lib/libxwalk_injected_bundle.so %{buildroot}%{_lib
 # wrt-loader
 install -p -m 755 out/Default/wrt-loader %{buildroot}%{_bindir}
 
+# wrt-upgrade
+install -p -m 755 out/Default/wrt-upgrade %{buildroot}%{_bindir}
+install -p -m 644 out/Default/gen/310.wrt.upgrade.sh %{buildroot}%{_datadir}/upgrade/scripts/310.wrt.upgrade.sh
+
 %clean
 rm -fr %{buildroot}
 
@@ -190,4 +195,6 @@ rm -fr %{buildroot}
 %attr(755,root,root) %{_bindir}/wrt
 %attr(755,root,root) %{_bindir}/wrt-loader
 %attr(644,root,root) %{_datadir}/aul/wrt.loader
+%attr(755,root,root) %{_bindir}/wrt-upgrade
+%attr(755,root,root) %{_datadir}/upgrade/scripts/310.wrt.upgrade.sh
 %caps(cap_sys_admin,cap_setgid=ei) %{_bindir}/wrt-loader
diff --git a/wrt-upgrade/310.wrt.upgrade.sh b/wrt-upgrade/310.wrt.upgrade.sh
new file mode 100644 (file)
index 0000000..2a3dba9
--- /dev/null
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+#excute upgrade application
+/usr/bin/wrt-upgrade
+
+#remove unuse databases
+rm /opt/dbspace/.wrt.db
+rm /opt/dbspace/.wrt.db-journal
+
+rm -r /opt/share/widget
+
+rm /opt/usr/dbspace/.wrt_custom_handler.db
+rm /opt/usr/dbspace/.wrt_custom_handler.db-journal
+rm /opt/usr/dbspace/.wrt_i18n.db
+rm /opt/usr/dbspace/.wrt_i18n.db-journal
diff --git a/wrt-upgrade/wrt-upgrade-info.cc b/wrt-upgrade/wrt-upgrade-info.cc
new file mode 100644 (file)
index 0000000..ca905fe
--- /dev/null
@@ -0,0 +1,171 @@
+// Copyright (c) 2013 Intel Corporation. All rights reserved.
+// Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "wrt-upgrade/wrt-upgrade-info.h"
+#include "common/logger.h"
+
+// #include <sstream>
+
+namespace {
+const std::string kSectionPrefix = "_SECT_";
+const std::string kSectionSuffix = "_SECT_";
+
+const std::string kDBPublicSection = "public";
+const std::string kDBPrivateSection = "private";
+
+const std::string kGeolocationPermissionPrefix = "__WRT_GEOPERM_";
+const std::string kNotificationPermissionPrefix = "__WRT_NOTIPERM_";
+const std::string kQuotaPermissionPrefix = "__WRT_QUOTAPERM_";
+const std::string kCertificateAllowPrefix = "__WRT_CERTIPERM_";
+const std::string kUsermediaPermissionPrefix = "__WRT_USERMEDIAPERM_";
+
+const std::string kValueAllow = "allowed";
+const std::string kValueDenied = "denied";
+const std::string kValueUnknown = "unknown";
+
+const std::string kAppDirectoryPrefix = "/opt/usr/home/owner/apps_rw/";
+const std::string kAppSecurityOriginDBFile = "/data/.security_origin.db";
+const std::string kAppCertificateDBFile = "/data/.certificate.db";
+
+enum {
+  FEATURE_GEOLOCATION = 0,
+  FEATURE_WEB_NOTIFICATION,
+  FEATURE_USER_MEDIA,
+  FEATURE_FULLSCREEN_MODE,
+  FEATURE_WEB_DATABASE,
+  FEATURE_CAMERA,
+  FEATURE_AUDIO_RECORDER
+};
+enum {
+  RESULT_UNKNOWN = 0,
+  RESULT_ALLOW_ONCE,
+  RESULT_DENY_ONCE,
+  RESULT_ALLOW_ALWAYS,
+  RESULT_DENY_ALWAYS
+};
+}  // namespace
+
+namespace upgrade {
+
+PreferenceInfo::PreferenceInfo(std::string key, std::string value) {
+  m_section_ = kDBPublicSection;
+  m_key_ = key;
+  m_value_ = value;
+}
+SecurityOriginInfo::SecurityOriginInfo(
+        int feature,
+        std::string scheme,
+        std::string host,
+        int port,
+        int result) {
+  m_section_ = kDBPrivateSection;
+  m_key_ = translateKey(feature, scheme, host, port);
+  m_value_ = translateValue(result);
+}
+std::string SecurityOriginInfo::translateKey(
+    int feature,
+    std::string scheme,
+    std::string host,
+    int port) {
+
+  std::string key = "";
+
+  switch (feature) {
+  case FEATURE_GEOLOCATION :
+      key += kGeolocationPermissionPrefix;
+  break;
+  case FEATURE_WEB_NOTIFICATION :
+      key += kNotificationPermissionPrefix;
+  break;
+  case FEATURE_USER_MEDIA :
+      key += kUsermediaPermissionPrefix;
+  break;
+  case FEATURE_WEB_DATABASE :
+      key += kQuotaPermissionPrefix;
+  break;
+  default :
+  break;
+  }
+
+  key += scheme;
+  key += "://";
+  key += host;
+  key += ":";
+  key += std::to_string(port);
+
+  return key;
+}
+std::string SecurityOriginInfo::translateValue(int result) {
+  std::string value = "";
+
+  switch (result) {
+  case RESULT_ALLOW_ALWAYS :
+       value = kValueAllow;
+  break;
+  case RESULT_DENY_ALWAYS :
+      value = kValueDenied;
+  break;
+  case RESULT_UNKNOWN :
+  case RESULT_ALLOW_ONCE :
+  case RESULT_DENY_ONCE :
+  default :
+      value = kValueUnknown;
+  break;
+  }
+  return value;
+}
+CertificateInfo::CertificateInfo(
+        std::string pem,
+        int result) {
+  m_section_ = kDBPrivateSection;
+  m_key_ = translateKey(pem);
+  m_value_ = translateValue(result);
+}
+std::string CertificateInfo::translateKey(std::string pem) {
+  std::string key = "";
+  key = kCertificateAllowPrefix + pem;
+  return key;
+}
+std::string CertificateInfo::translateValue(int result) {
+  std::string value = "";
+
+  switch (result) {
+  case RESULT_ALLOW_ALWAYS :
+    value = kValueAllow;
+  break;
+  case RESULT_DENY_ALWAYS :
+    value = kValueDenied;
+  break;
+  case RESULT_UNKNOWN :
+  case RESULT_ALLOW_ONCE :
+  case RESULT_DENY_ONCE :
+  default :
+    value = kValueUnknown;
+  break;
+  }
+  return value;
+}
+WrtUpgradeInfo::WrtUpgradeInfo(std::string appid) {
+  app_id_ = appid;
+  pkg_id_ = appid.substr(0, appid.find_first_of('.'));
+  app_dir_ = kAppDirectoryPrefix + pkg_id_;
+}
+void WrtUpgradeInfo::addPreferenceInfo(PreferenceInfo preference) {
+  preference_info_list_.push_back(preference);
+}
+void WrtUpgradeInfo::addSecurityOriginInfo(SecurityOriginInfo security_origin) {
+  security_origin_info_list_.push_back(security_origin);
+}
+void WrtUpgradeInfo::addCertificateInfo(CertificateInfo certificate) {
+  certificate_info_list.push_back(certificate);
+}
+
+std::string WrtUpgradeInfo::getSecurityOriginDB() {
+  return app_dir_ + kAppSecurityOriginDBFile;
+}
+std::string WrtUpgradeInfo::getCertificateDB() {
+  return app_dir_ + kAppCertificateDBFile;
+}
+}  // namespace upgrade
diff --git a/wrt-upgrade/wrt-upgrade-info.h b/wrt-upgrade/wrt-upgrade-info.h
new file mode 100644 (file)
index 0000000..c304e62
--- /dev/null
@@ -0,0 +1,103 @@
+// Copyright (c) 2013 Intel Corporation. All rights reserved.
+// Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef WRT_UPGRADE_INFO_H
+#define WRT_UPGRADE_INFO_H
+
+#include <iostream>
+#include <string>
+#include <vector>
+
+namespace upgrade {
+class PreferenceInfo{
+ public:
+  PreferenceInfo(std::string key, std::string value);
+  std::string getSection() {return m_section_;}
+  std::string getKey() {return m_key_;}
+  std::string getValue() {return m_value_;}
+ private:
+  std::string m_section_;
+  std::string m_key_;
+  std::string m_value_;
+};
+
+class SecurityOriginInfo{
+ public:
+    SecurityOriginInfo(
+         int feature,
+        std::string scheme,
+        std::string host,
+        int port,
+        int result);
+  std::string getSection() {return m_section_;}
+  std::string getKey() {return m_key_;}
+  std::string getValue() {return m_value_;}
+ private:
+  std::string translateKey(
+     int feature,
+      std::string scheme,
+      std::string host,
+      int port);
+  std::string translateValue(int result);
+  std::string m_section_;
+  std::string m_key_;
+  std::string m_value_;
+};
+
+class CertificateInfo{
+ public:
+    CertificateInfo(
+        std::string pem,
+        int result);
+  std::string getSection() {return m_section_;}
+  std::string getKey() {return m_key_;}
+  std::string getValue() {return m_value_;}
+ private:
+  std::string translateKey(std::string pem);
+  std::string translateValue(int result);
+  std::string m_section_;
+  std::string m_key_;
+  std::string m_value_;
+};
+
+class WrtUpgradeInfo{
+ public:
+  WrtUpgradeInfo() {}
+  explicit WrtUpgradeInfo(std::string appid);
+
+  std::string getAppid() { return app_id_; }
+  std::string getPkgid() { return pkg_id_; }
+  std::string getAppDir() { return app_dir_; }
+  std::string getSecurityOriginDB();
+  std::string getCertificateDB();
+
+  void addPreferenceInfo(PreferenceInfo preference);
+  void addSecurityOriginInfo(SecurityOriginInfo security_origin);
+  void addCertificateInfo(CertificateInfo certificate);
+
+  PreferenceInfo getPreferenceInfo(int idx)
+      {return preference_info_list_[idx];}
+  SecurityOriginInfo getSecurityOriginInfo(int idx)
+      {return security_origin_info_list_[idx];}
+  CertificateInfo getCertificateInfo(int idx)
+      {return certificate_info_list[idx];}
+
+  int getPreferenceInfoSize()
+      {return static_cast<int>(preference_info_list_.size());}
+  int getSecurityOriginInfoSize()
+      {return static_cast<int>(security_origin_info_list_.size());}
+  int getCertificateInfoSize()
+      {return static_cast<int>(certificate_info_list.size());}
+
+ private:
+  std::string pkg_id_;
+  std::string app_id_;
+  std::string app_dir_;
+  std::vector<PreferenceInfo> preference_info_list_;
+  std::vector<SecurityOriginInfo> security_origin_info_list_;
+  std::vector<CertificateInfo> certificate_info_list;
+};
+}  // namespace upgrade
+#endif  // WRT_UPGRADE_INFO_H
diff --git a/wrt-upgrade/wrt-upgrade.cc b/wrt-upgrade/wrt-upgrade.cc
new file mode 100644 (file)
index 0000000..6376f54
--- /dev/null
@@ -0,0 +1,301 @@
+// Copyright (c) 2013 Intel Corporation. All rights reserved.
+// Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "wrt-upgrade/wrt-upgrade.h"
+
+#include <sqlite3.h>
+#include <unistd.h>
+
+#include <iostream>
+#include <fstream>
+#include <utility>
+
+#include "common/picojson.h"
+#include "common/logger.h"
+#include "common/file_utils.h"
+
+namespace {
+  const std::string kWRTDbFile = "/opt/dbspace/.wrt.db";
+  const std::string kAppDirectoryPrefix = "/opt/usr/home/owner/apps_rw/";
+  const std::string kAppMigrationFile = "/data/.runtime.migration";
+  const std::string kJournalPostfix = "-journal";
+}  // namespace
+
+namespace upgrade {
+WrtUpgrade::WrtUpgrade() {
+}
+WrtUpgrade::~WrtUpgrade() {
+}
+void WrtUpgrade::Run() {
+  ParseWrtDatabse();
+  ParseSecurityOriginDatabase();
+  ParseCertificatenDatabase();
+  CreateMigrationFile();
+  RemoveDatabases();
+  RedirectSymlink();
+}
+void WrtUpgrade::ParseWrtDatabse() {
+  std::cout << "parseWrtDatabse" << std::endl;
+  sqlite3 *wrt_db;
+  try {
+    int ret = sqlite3_open(kWRTDbFile.c_str(), &wrt_db);
+    if (ret != SQLITE_OK) {
+      throw("error to open wrt database");
+    }
+
+    // get applist
+    std::string query = "select tizen_appid from widgetinfo";
+    sqlite3_stmt* stmt = NULL;
+
+    ret = sqlite3_prepare_v2(wrt_db, query.c_str() , -1, &stmt, NULL);
+    if (ret != SQLITE_OK) {
+      throw("error for prepare query");
+    }
+
+    while (SQLITE_ROW == sqlite3_step(stmt)) {
+      std::string appid
+        = std::string(reinterpret_cast<const char*>(
+                        sqlite3_column_text(stmt, 0)));
+      application_list_.push_back(appid);
+      application_map_.insert(
+        std::pair<std::string, WrtUpgradeInfo>(appid, WrtUpgradeInfo(appid)));
+    }
+
+    ret = sqlite3_finalize(stmt);
+    if (ret != SQLITE_OK) {
+      throw("error for finalize stmt");
+    }
+
+    // get widget preference
+    query = "select tizen_appid,key_name,key_value from widgetpreference";
+    stmt = NULL;
+
+    ret = sqlite3_prepare_v2(wrt_db, query.c_str() , -1, &stmt, NULL);
+    if (ret != SQLITE_OK) {
+      throw("error for prepare query");
+    }
+
+    while (SQLITE_ROW == sqlite3_step(stmt)) {
+      std::string appid
+        = std::string(reinterpret_cast<const char*>(
+                       sqlite3_column_text(stmt, 0)));
+      std::string key
+        = std::string(reinterpret_cast<const char*>(
+                       sqlite3_column_text(stmt, 1)));
+      std::string value
+        = std::string(reinterpret_cast<const char*>(
+                       sqlite3_column_text(stmt, 2)));
+
+      application_map_[appid].addPreferenceInfo(PreferenceInfo(key, value));
+    }
+    ret = sqlite3_finalize(stmt);
+    if (ret != SQLITE_OK) {
+      throw("error for finalize stmt");
+    }
+  } catch(const char* err) {
+    std::cout << err << std::endl;
+  }
+  sqlite3_close(wrt_db);
+}
+void WrtUpgrade::ParseSecurityOriginDatabase() {
+  std::cout << "parseSecurityOriginDatabase" << std::endl;
+  for (int i = 0; i < static_cast<int>(application_list_.size()) ; i++) {
+    sqlite3 *security_origin_db;
+    std::string appid = application_list_[i];
+    try {
+      std::string db_path = application_map_[appid].getSecurityOriginDB();
+
+      if (access(db_path.c_str(), 0) != 0) {
+        throw("file is not exist : ["+db_path+"]");
+      }
+      int ret = sqlite3_open(db_path.c_str(), &security_origin_db);
+      if (ret != SQLITE_OK) {
+        throw("error to open wrt database");
+      }
+
+      // get applist
+      std::string query = "select * from securityorigininfo";
+      sqlite3_stmt* stmt = NULL;
+
+      ret = sqlite3_prepare_v2(
+              security_origin_db, query.c_str() , -1, &stmt, NULL);
+      if (ret != SQLITE_OK) {
+        throw("error for prepare query");
+      }
+
+      while (SQLITE_ROW == sqlite3_step(stmt)) {
+        int feature = sqlite3_column_int(stmt, 0);
+        std::string scheme
+          = std::string(reinterpret_cast<const char*>(
+                         sqlite3_column_text(stmt, 1)));
+        std::string host
+          = std::string(reinterpret_cast<const char*>(
+                         sqlite3_column_text(stmt, 2)));
+        int port = sqlite3_column_int(stmt, 3);
+        int result = sqlite3_column_int(stmt, 4);
+        application_map_[appid].addSecurityOriginInfo(
+          SecurityOriginInfo(feature, scheme, host, port, result));
+      }
+
+      ret = sqlite3_finalize(stmt);
+      if (ret != SQLITE_OK) {
+        throw("error for finalize stmt");
+      }
+    } catch(...) {
+    }
+    sqlite3_close(security_origin_db);
+  }
+}
+void WrtUpgrade::ParseCertificatenDatabase() {
+  std::cout << "parseCertificateDatabase" << std::endl;
+  for (int i = 0 ; i < static_cast<int>(application_list_.size()) ; i++) {
+    sqlite3 *certificate_db;
+    std::string appid = application_list_[i];
+    try {
+      std::string db_path = application_map_[appid].getCertificateDB();
+
+      if (access(db_path.c_str(), 0) != 0) {
+        throw("file is not exist : ["+db_path+"]");
+      }
+      int ret = sqlite3_open(db_path.c_str(), &certificate_db);
+      if (ret != SQLITE_OK) {
+        throw("error to open wrt database");
+      }
+
+      // get applist
+      std::string query = "select * from certificateinfo";
+      sqlite3_stmt* stmt = NULL;
+
+      ret = sqlite3_prepare_v2(certificate_db, query.c_str() , -1, &stmt, NULL);
+      if (ret != SQLITE_OK) {
+        throw("error for prepare query");
+      }
+
+      while (SQLITE_ROW == sqlite3_step(stmt)) {
+        std::string certificate
+          = std::string(reinterpret_cast<const char*>(
+                         sqlite3_column_text(stmt, 0)));
+        int result = sqlite3_column_int(stmt, 1);
+        application_map_[appid].addCertificateInfo(
+                                  CertificateInfo(certificate, result));
+      }
+
+      ret = sqlite3_finalize(stmt);
+      if (ret != SQLITE_OK) {
+        throw("error for finalize stmt");
+      }
+    } catch(...) {
+    }
+    sqlite3_close(certificate_db);
+  }
+}
+void WrtUpgrade::CreateMigrationFile() {
+  std::cout << "createMigrationFile" << std::endl;
+  for (int i = 0 ; i < static_cast<int>(application_list_.size()) ; i++) {
+    std::string appid = application_list_[i];
+    std::string json_str = CreateJsonObject(appid);
+    if (!json_str.empty()) {
+      std::string pkg_id = appid.substr(0, appid.find_first_of('.'));
+      std::string output_file_path
+        = kAppDirectoryPrefix + pkg_id + kAppMigrationFile;
+      std::ofstream output_file(output_file_path);
+      output_file << json_str;
+      output_file.close();
+    }
+  }
+}
+void WrtUpgrade::RemoveDatabases() {
+  for (int i = 0 ; i < static_cast<int>(application_list_.size()) ; i++) {
+    std::string appid = application_list_[i];
+    try {
+      std::string security_origin_db_path
+        = application_map_[appid].getSecurityOriginDB();
+      std::string security_origin_journal_db_path
+        = security_origin_db_path + kJournalPostfix;
+      std::string certificate_db_path
+        = application_map_[appid].getCertificateDB();
+      std::string certificate_journal_db_path
+        = certificate_db_path + kJournalPostfix;
+
+      RemoveFile(security_origin_db_path);
+      RemoveFile(security_origin_journal_db_path);
+      RemoveFile(certificate_db_path);
+      RemoveFile(certificate_journal_db_path);
+    } catch(...) {
+    }
+  }
+}
+std::string WrtUpgrade::CreateJsonObject(std::string appid) {
+  WrtUpgradeInfo info = application_map_[appid];
+
+  if (info.getPreferenceInfoSize() == 0
+      && info.getSecurityOriginInfoSize() == 0
+      && info.getCertificateInfoSize() == 0) {
+    return "";
+  }
+  std::cout << "createJsonObject for " << appid << std::endl;
+
+  // make preference value arr : vector
+  picojson::array preference_arr;
+  for (int i = 0 ; i < info.getPreferenceInfoSize() ; i++) {
+    PreferenceInfo p_info = info.getPreferenceInfo(i);
+    picojson::object obj;
+    obj["key"] = picojson::value(p_info.getKey());
+    obj["value"] = picojson::value(p_info.getValue());
+    preference_arr.push_back(picojson::value(obj));
+  }
+
+  // make security_origin value arr : vector
+  picojson::array securityorigin_arr;
+  for (int i = 0 ; i < info.getSecurityOriginInfoSize() ; i++) {
+    SecurityOriginInfo s_info = info.getSecurityOriginInfo(i);
+    picojson::object obj;
+    obj["section"] = picojson::value(s_info.getSection());
+    obj["key"] = picojson::value(s_info.getKey());
+    obj["value"] = picojson::value(s_info.getValue());
+    securityorigin_arr.push_back(picojson::value(obj));
+  }
+
+  // make certificate value arr : vector
+  picojson::array certificate_arr;
+  for (int i = 0 ; i < info.getCertificateInfoSize() ; i++) {
+    CertificateInfo c_info = info.getCertificateInfo(i);
+    picojson::object obj;
+    obj["section"] = picojson::value(c_info.getSection());
+    obj["key"] = picojson::value(c_info.getKey());
+    obj["value"] = picojson::value(c_info.getValue());
+    certificate_arr.push_back(picojson::value(obj));
+  }
+
+  // make one json
+  picojson::object migration_obj;
+  migration_obj["preference"] = picojson::value(preference_arr);
+  migration_obj["security_orgin"] = picojson::value(securityorigin_arr);
+  migration_obj["certificate"] = picojson::value(certificate_arr);
+
+  picojson::value migration_val = picojson::value(migration_obj);
+  std::string json_str = migration_val.serialize();
+  return json_str;
+}
+bool WrtUpgrade::RemoveFile(const std::string& path) {
+  if (!common::utils::Exists(path)) {
+    LOGGER(ERROR) << "File is not Exist : " << path;
+    return false;
+  }
+  return (remove(path.c_str()) == 0);
+}
+void WrtUpgrade::RedirectSymlink() {
+  std::string xwalk_runtime = "/usr/bin/xwalk_runtime";
+  std::string wrt_client = "/usr/bin/wrt-client";
+
+  symlink(xwalk_runtime.c_str(), wrt_client.c_str());
+}
+}  // namespace upgrade
+int main() {
+  std::cout << "Tizen database migration tool for Webruntime" << std::endl;
+  upgrade::WrtUpgrade mt;
+  mt.Run();
+  return 0;
+}
diff --git a/wrt-upgrade/wrt-upgrade.gyp b/wrt-upgrade/wrt-upgrade.gyp
new file mode 100644 (file)
index 0000000..9e90439
--- /dev/null
@@ -0,0 +1,35 @@
+{
+  'includes': [
+    '../build/common.gypi',
+  ],
+  'targets': [
+    {
+      'target_name': 'wrt-upgrade',
+      'type': 'executable',
+      'dependencies': [
+        '../common/common.gyp:xwalk_tizen_common',
+      ],
+      'sources': [
+        'wrt-upgrade.cc',
+        'wrt-upgrade-info.cc',
+      ],
+      'variables': {
+        'packages': [
+          'sqlite3',
+          'dlog',
+        ],
+      },
+      'libraries' : [
+        '-ldl',
+      ],
+      'copies': [
+        {
+          'destination': '<(SHARED_INTERMEDIATE_DIR)',
+          'files': [
+            '310.wrt.upgrade.sh'
+          ],
+        },
+      ],
+    }, # end of target 'wrt-upgrade'
+  ], # end of targets
+}
diff --git a/wrt-upgrade/wrt-upgrade.h b/wrt-upgrade/wrt-upgrade.h
new file mode 100644 (file)
index 0000000..110cf46
--- /dev/null
@@ -0,0 +1,34 @@
+// Copyright (c) 2013 Intel Corporation. All rights reserved.
+// Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef WRT_UPGRADE_H
+#define WRT_UPGRADE_H
+#include <iostream>
+#include <vector>
+#include <map>
+#include <string>
+
+#include "wrt-upgrade/wrt-upgrade-info.h"
+
+namespace upgrade {
+class WrtUpgrade{
+ public:
+  WrtUpgrade();
+  ~WrtUpgrade();
+  void Run();
+ private:
+  void ParseWrtDatabse();
+  void ParseSecurityOriginDatabase();
+  void ParseCertificatenDatabase();
+  void CreateMigrationFile();
+  void RemoveDatabases();
+  bool RemoveFile(const std::string& path);
+  void RedirectSymlink();
+  std::string CreateJsonObject(std::string appid);
+  std::vector<std::string> application_list_;
+  std::map<std::string, WrtUpgradeInfo> application_map_;
+};
+}  // namespace upgrade
+#endif  // WRT_UPGRADE_H
index 4c6f3a9..94dea57 100644 (file)
@@ -8,6 +8,7 @@
         'extensions/extensions.gyp:*',
         'runtime/runtime.gyp:*',
         'loader/loader.gyp:*',
+        'wrt-upgrade/wrt-upgrade.gyp:*',
       ],
     }, # end of target 'xwalk_tizen'
   ], # end of targets