summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKévin THIERRY <kevin.thierry@open.eurogiciel.org>2014-03-13 13:28:48 +0100
committerKévin THIERRY <kevin.thierry@open.eurogiciel.org>2014-03-13 15:33:07 +0100
commitd89321911038079248de90043b93121d30221033 (patch)
tree4b69e9e1aa8ba3197f812e314cd40a58197184b9
parentcc94b25aa675fc061d456568f60fe56d536a540f (diff)
downloadlibrua-d89321911038079248de90043b93121d30221033.tar.gz
librua-d89321911038079248de90043b93121d30221033.tar.bz2
librua-d89321911038079248de90043b93121d30221033.zip
Create a per user DB instead of a global DB
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>
-rw-r--r--data/rua_db.sql9
-rw-r--r--include/db-schema.h14
-rwxr-xr-xinclude/rua.h2
-rw-r--r--packaging/librua.spec4
-rw-r--r--src/rua.c9
-rw-r--r--test/rua-test.c6
6 files changed, 16 insertions, 28 deletions
diff --git a/data/rua_db.sql b/data/rua_db.sql
deleted file mode 100644
index 4ae26ca..0000000
--- a/data/rua_db.sql
+++ /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
-);
diff --git a/include/db-schema.h b/include/db-schema.h
index f405aea..df05dbd 100644
--- a/include/db-schema.h
+++ b/include/db-schema.h
@@ -23,12 +23,14 @@
#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 */
diff --git a/include/rua.h b/include/rua.h
index 642e617..2bd8f51 100755
--- a/include/rua.h
+++ b/include/rua.h
@@ -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
diff --git a/packaging/librua.spec b/packaging/librua.spec
index b19b615..ca1c9e4 100644
--- a/packaging/librua.spec
+++ b/packaging/librua.spec
@@ -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
-
diff --git a/src/rua.c b/src/rua.c
index 9b5ef8b..1e70911 100644
--- a/src/rua.c
+++ b/src/rua.c
@@ -30,11 +30,13 @@
#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;
diff --git a/test/rua-test.c b/test/rua-test.c
index bcd6913..03a7032 100644
--- a/test/rua-test.c
+++ b/test/rua-test.c
@@ -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;
}
-
-