notmuch.git  about / heads / tags
Unnamed repository; edit this file 'description' to name the repository.
   commit 85587626690dfef33d318a40981ce822c2b3f5f4 (patch)
   parent 222279f6 test/path-config: set database.mail_root but not database.path
     tree 7e3aa20bc3fe762b44fd1648adc8b88c6db715b9
   author David Bremner <david@tethera.net>  2022-07-29 09:19:59 -0300
committer David Bremner <david@tethera.net>  2022-08-11 12:39:45 -0300

lib/open: refactor call to mkdir into function

This makes the error handling available for re-use. Using
g_mkdir_with_parents also handles the case of a pre-existing
directory. This introduces new functionality, namely creating the
parent directories, which will be useful for creating directories like
'.local/share/notmuch/default'.
---
 lib/open.cc | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/lib/open.cc b/lib/open.cc
index 30cfcf9e..85e46dc7 100644
--- a/lib/open.cc
+++ b/lib/open.cc
@@ -244,6 +244,18 @@ _choose_database_path (notmuch_database_t *notmuch,
     return NOTMUCH_STATUS_SUCCESS;
 }
 
+static notmuch_status_t
+_mkdir (const char *path, char **message)
+{
+    if (g_mkdir_with_parents (path, 0755)) {
+	IGNORE_RESULT (asprintf (message, "Error: Cannot create directory %s: %s.\n",
+				 path, strerror (errno)));
+	return NOTMUCH_STATUS_FILE_ERROR;
+    }
+    return NOTMUCH_STATUS_SUCCESS;
+}
+
+
 static notmuch_database_t *
 _alloc_notmuch (const char *database_path, const char *config_path, const char *profile)
 {
@@ -607,7 +619,6 @@ notmuch_database_create_with_config (const char *database_path,
     const char *notmuch_path = NULL;
     char *message = NULL;
     GKeyFile *key_file = NULL;
-    int err;
 
     _notmuch_init ();
 
@@ -653,15 +664,9 @@ notmuch_database_create_with_config (const char *database_path,
 	    goto DONE;
 	}
 
-	err = mkdir (notmuch_path, 0755);
-	if (err) {
-	    if (errno != EEXIST) {
-		IGNORE_RESULT (asprintf (&message, "Error: Cannot create directory %s: %s.\n",
-					 notmuch_path, strerror (errno)));
-		status = NOTMUCH_STATUS_FILE_ERROR;
-		goto DONE;
-	    }
-	}
+	status = _mkdir (notmuch_path, &message);
+	if (status)
+	    goto DONE;
     }
 
     if (! (notmuch->xapian_path = talloc_asprintf (notmuch, "%s/%s", notmuch_path, "xapian"))) {


glossary
--------
Commit objects reference one tree, and zero or more parents.

Single parent commits can typically generate a patch in
unified diff format via `git format-patch'.

Multiple parents means the commit is a merge.

Root commits have no ancestor.  Note that it is
possible to have multiple root commits when merging independent histories.

Every commit references one top-level tree object.

git clone https://yhetil.org/notmuch.git