From f2e9eb4e2271f98c142f98028eaf31c928283a79 Mon Sep 17 00:00:00 2001 From: handa Date: Thu, 14 Sep 2006 00:56:44 +0000 Subject: [PATCH] Include . (mdatabase__lock): Make a directory if necessary. --- src/database.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/database.c b/src/database.c index 68f788c..614fb9f 100644 --- a/src/database.c +++ b/src/database.c @@ -134,6 +134,7 @@ #include #include #include +#include #include "m17n.h" #include "m17n-misc.h" @@ -1030,10 +1031,20 @@ mdatabase__lock (MDatabase *mdb) fp = fopen (db_info->uniq_file, "w"); if (! fp) { - free (db_info->uniq_file); - free (db_info->lock_file); - db_info->lock_file = NULL; - return -1; + char *str = strdup (db_info->uniq_file); + char *dir = dirname (str); + + if (stat (dir, &buf) == 0 + || mkdir (dir, 0777) < 0 + || ! (fp = fopen (db_info->uniq_file, "w"))) + { + free (db_info->uniq_file); + free (db_info->lock_file); + db_info->lock_file = NULL; + free (str); + return -1; + } + free (str); } fclose (fp); if (link (db_info->uniq_file, db_info->lock_file) < 0 -- 1.7.10.4