Made directory creation more robust, or atleast shorter.

We use a loop to build the file paths. Also be more descriptive about errors
and print them to stderr instead of stdout.
Allocate a fixed size buffer for db file location.

debug builds use an in-memory sqlite3 database instead of the default on-disk
database. Just incase we accidentally introduce an incompatible change to the
format.