Create a per user DB instead of a global DB 91/17991/1
authorKévin THIERRY <kevin.thierry@open.eurogiciel.org>
Thu, 13 Mar 2014 12:28:48 +0000 (13:28 +0100)
committerKévin THIERRY <kevin.thierry@open.eurogiciel.org>
Thu, 13 Mar 2014 14:33:07 +0000 (15:33 +0100)
To fully support the multi-user architecture every user needs to have
its own DB since, in the case of librua, a global (system) DB doesn't
make much sense.

Bug-Tizen: PTREL-339
Change-Id: Id7c5ab27748cfe60cb998a956f06d5280fe1fe50
Signed-off-by: Kévin THIERRY <kevin.thierry@open.eurogiciel.org>
data/rua_db.sql [deleted file]
include/db-schema.h
include/rua.h
packaging/librua.spec
src/rua.c
test/rua-test.c

diff --git a/data/rua_db.sql b/data/rua_db.sql
deleted file mode 100644 (file)
index 4ae26ca..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-PRAGMA journal_mode = PERSIST;
-
-CREATE TABLE IF NOT EXISTS rua_history (
-       id INTEGER PRIMARY KEY,
-       pkg_name TEXT,
-       app_path TEXT,
-       arg TEXT,
-       launch_time INTEGER
-);
index f405aea..df05dbd 100644 (file)
 #define __RUA_SCHEMA_H__
 
 #define CREATE_RUA_HISTORY_TABLE " \
-create table if not exists rua_history ( \
-id INTEGER PRIMARY KEY, \
-pkg_name TEXT, \
-app_path TEXT, \
-arg TEXT, \
-launch_time INTEGER \
+PRAGMA journal_mode = PERSIST; \
+\
+CREATE TABLE IF NOT EXISTS rua_history ( \
+       id INTEGER PRIMARY KEY, \
+       pkg_name TEXT, \
+       app_path TEXT, \
+       arg TEXT, \
+       launch_time INTEGER \
 );"
 
 /* table index */
index 642e617..2bd8f51 100755 (executable)
@@ -20,7 +20,7 @@
  */
 
 /**
- * @file       rua.h
+ * @file        rua.h
  * @brief       RUA API declaration header file.
  * @author      Jinwoo Nam (jwoo.nam@samsung.com)
  * @version     0.1
index b19b615..ca1c9e4 100644 (file)
@@ -32,8 +32,6 @@ make %{?_smp_mflags}
 
 %install
 %make_install
-mkdir -p %{buildroot}%{TZ_SYS_DB}
-sqlite3 %{buildroot}%{TZ_SYS_DB}/.rua.db < data/rua_db.sql
 
 %post -p /sbin/ldconfig
 
@@ -42,7 +40,6 @@ sqlite3 %{buildroot}%{TZ_SYS_DB}/.rua.db < data/rua_db.sql
 %files
 %manifest %{name}.manifest
 %defattr(-,root,root,-)
-%config(noreplace) %attr(0660,root,%{TZ_SYS_USER_GROUP}) %{TZ_SYS_DB}/.rua.db*
 %{_libdir}/librua.so.*
 %license LICENSE
 
@@ -53,4 +50,3 @@ sqlite3 %{buildroot}%{TZ_SYS_DB}/.rua.db < data/rua_db.sql
 %{_includedir}/rua/*.h
 %{_libdir}/librua.so
 %{_libdir}/pkgconfig/rua.pc
-
index 9b5ef8b..1e70911 100644 (file)
--- a/src/rua.c
+++ b/src/rua.c
 
 #include <db-util.h>
 
+/* For multi-user support */
+#include <tzplatform_config.h>
+
 #include "rua.h"
 #include "db-schema.h"
 #include "perf-measure.h"
 
-#define RUA_DB_PATH    "/opt/dbspace"
 #define RUA_DB_NAME    ".rua.db"
 #define RUA_HISTORY    "rua_history"
 #define QUERY_MAXLEN   4096
@@ -281,7 +283,8 @@ int rua_init(void)
        }
 
        char defname[FILENAME_MAX];
-       snprintf(defname, sizeof(defname), "%s/%s", RUA_DB_PATH, RUA_DB_NAME);
+       const char *rua_db_path = tzplatform_getenv(TZ_USER_DB);
+       snprintf(defname, sizeof(defname), "%s/%s", rua_db_path, RUA_DB_NAME);
        _db = __db_init(defname);
 
        if (_db == NULL)
@@ -340,7 +343,7 @@ static sqlite3 *__db_init(char *root)
        int r;
        sqlite3 *db = NULL;
 
-       r = db_util_open(root, &db, 0);
+       r = db_util_open_with_options(root, &db, SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE, NULL);
        if (r) {
                db_util_close(db);
                return NULL;
index bcd6913..03a7032 100644 (file)
@@ -34,9 +34,8 @@ int __add_history(char *pkgname)
 {
        int ret = 0;
        struct rua_rec rec;
-       char apppath[FILENAME_MAX] = "";
+       const char *apppath = tzplatform_mkpath(TZ_SYS_RW_APP, pkgname);
 
-       apppath = tzplatform_mkpath(TZ_SYS_RW_APP, pkgname);
        memset(&rec, 0, sizeof(rec));
        rec.pkg_name = pkgname;
        rec.app_path = apppath;
@@ -52,7 +51,6 @@ int __add_history(char *pkgname)
        rua_fini();
 
        return ret;
-
 }
 
 int main(int argc, char* argv[])
@@ -64,5 +62,3 @@ int main(int argc, char* argv[])
        ret = __add_history(argv[1]);
        return 0;
 }
-
-