[GRASS-SVN] r57276 - grass/trunk/db/drivers/sqlite
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Jul 25 12:40:23 PDT 2013
Author: mmetz
Date: 2013-07-25 12:40:23 -0700 (Thu, 25 Jul 2013)
New Revision: 57276
Modified:
grass/trunk/db/drivers/sqlite/db.c
Log:
sqlite driver: create directory if not existing
Modified: grass/trunk/db/drivers/sqlite/db.c
===================================================================
--- grass/trunk/db/drivers/sqlite/db.c 2013-07-25 18:48:03 UTC (rev 57275)
+++ grass/trunk/db/drivers/sqlite/db.c 2013-07-25 19:40:23 UTC (rev 57276)
@@ -32,8 +32,9 @@
*/
int db__driver_open_database(dbHandle * handle)
{
- char name2[GPATH_MAX];
+ char name2[GPATH_MAX], *path;
const char *name;
+ int i;
G_debug(3, "\ndb_driver_open_database()");
@@ -81,6 +82,25 @@
G_debug(2, "name2 = '%s'", name2);
+ path = G_store(name2);
+ path = G_convert_dirseps_to_host(path);
+ i = strlen(path);
+ while (path[i] != HOST_DIRSEP && i > 0)
+ i--;
+
+ path[i] = '\0';
+ if (*path) {
+ G_debug(2, "path to db is %s", path);
+
+ /* create directory if not existing */
+ if (access(path, 0) != 0) {
+ if (G_mkdir(path) != 0)
+ G_fatal_error(_("Unable to create directory '%s' for sqlite database"),
+ path);
+ }
+ }
+ G_free(path);
+
if (sqlite3_open(name2, &sqlite) != SQLITE_OK) {
db_d_append_error("%s %s\n%s",
_("Unable to open database:"),
More information about the grass-commit
mailing list