[patch] fix SQLite db creation

Mark Johnston markjdb at gmail.com
Mon Aug 6 18:13:24 EDT 2012


Hello,

I recently noticed that tc Setup is broken for SQLite on recent builds
of FreeBSD. This turns out to be because of a change to realpath(3)
which causes it to return an error if the last component of a filename
doesn't exist (previously it didn't). The end result is that tc Setup
always fails to create the database.

The inline patch fixes this. It also removes an unneeded dependency for
SQLite + webui, and changes the SQLite init code to create the db
directory if it doesn't exist (after asking the user). When I get
prompted for the database name, I usually use "db/tinderbox-db", and
would previously have to remember to "mkdir db" first.

Thanks!
-Mark

diff --git a/lib/db-sqlite.sh b/lib/db-sqlite.sh
index 757394d..836067a 100644
--- a/lib/db-sqlite.sh
+++ b/lib/db-sqlite.sh
@@ -1,5 +1,5 @@
 export DB_MAN_PREREQS="databases/sqlite3 databases/p5-DBD-SQLite"
-export DB_OPT_PREREQS="databases/php5-sqlite databases/php5-pdo_sqlite"
+export DB_OPT_PREREQS="databases/php5-pdo_sqlite"
 
 export DB_PROMPT=''
 export DB_SCHEMA_LOAD='/usr/local/bin/sqlite3 -batch ${db_name} < "${schema_file}"'
diff --git a/lib/tinderlib.sh b/lib/tinderlib.sh
index ecf8284..9e9cf4e 100644
--- a/lib/tinderlib.sh
+++ b/lib/tinderlib.sh
@@ -628,19 +628,29 @@ getDbInfoSQLite() {
         echo 1>&2 "    Database name : ${db_name}"
         read -p "(y/N)" option
 
+        db_dir=$(dirname "${db_name}")
+
         case "${option}" in
             [Yy]|[Yy][Ee][Ss])
-                if $(realpath -q "${db_name}" > /dev/null 2>&1); then
-                    finished=1
-                else
-                    echo 1>&2 "ERROR: directory $(dirname ${db_name}) does not exist."
-                    return 1
+                if ! realpath -q $db_dir > /dev/null 2>&1; then
+                    echo 1>&2 "WARNING: directory $db_dir does not exist. Would you like to create it?"
+                    read -p "(Y/n)" option
+                    case "${option}" in
+                    ""|[Yy]|[Yy][Ee][Ss])
+                        mkdir -p $db_dir
+                        ;;
+                    *)
+                        echo 1>&2 "ERROR: directory $db_dir does not exist, cannot perform database initialization"
+                        exit 1
+                        ;;
+                    esac
                 fi
+                finished=1
                 ;;
         esac
     done
 
-    echo $(realpath "${db_name}")
+    echo $(realpath ${db_dir})/$(basename "${db_name}")
 
     return 0
 }


More information about the tinderbox-list mailing list