summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2009-12-23 20:46:29 +0100
committerJon Bergli Heier <snakebite@jvnv.net>2009-12-23 20:46:29 +0100
commitbcf72c14ddedec281139fafce6cf955f7669a814 (patch)
tree3a437326431045d30bcecf32c8f7b75eb66a7928
parent1217519ac2f87f96e52d2a1085d2e6660d96d3fb (diff)
Database should be in the DATA directory, not the CONFIG directory.
Cleaned up headers in db.c.
-rw-r--r--db.c26
1 files changed, 11 insertions, 15 deletions
diff --git a/db.c b/db.c
index 1215430..4446d1e 100644
--- a/db.c
+++ b/db.c
@@ -1,10 +1,6 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <sys/types.h>
#include <unistd.h>
+#include <glib/gstdio.h>
#include <glib/gprintf.h>
#include "db.h"
@@ -53,20 +49,20 @@ static int db_create_tables() {
int db_open() {
int rc;
- int configfound;
+ int datafound;
char *dbfile;
- char *configdir;
+ char *datadir;
- configdir = g_strdup_printf("%s/walls", g_get_user_config_dir());
- if(access(configdir, F_OK) == -1 && g_mkdir_with_parents(configdir, 0700) == -1) {
- g_free(configdir);
+ datadir = g_strdup_printf("%s/walls", g_get_user_data_dir());
+ if(access(datadir, F_OK) == -1 && g_mkdir_with_parents(datadir, 0700) == -1) {
+ g_free(datadir);
return 0;
}
- g_free(configdir);
- dbfile = g_strdup_printf("%s/walls/db", g_get_user_config_dir());
- printf("db file: %s\n", dbfile);
- configfound = access(dbfile, F_OK) == 0;
+ dbfile = g_strdup_printf("%s/db", datadir);
+ datafound = g_access(dbfile, F_OK) == 0;
+
+ g_free(datadir);
rc = sqlite3_open(dbfile, &db);
g_free(dbfile);
@@ -75,7 +71,7 @@ int db_open() {
return 0;
}
- if(!configfound && !db_create_tables()) {
+ if(!datafound && !db_create_tables()) {
db_close();
return 0;
}