From: David Bremner <david@tethera.net>
To: notmuch@notmuchmail.org
Cc: spwhitton@spwhitton.name
Subject: [PATCH 4/6] lib/open: refactor call to mkdir into function
Date: Fri, 29 Jul 2022 09:19:59 -0300 [thread overview]
Message-ID: <20220729122001.1556787-5-david@tethera.net> (raw)
In-Reply-To: <20220729122001.1556787-1-david@tethera.net>
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"))) {
--
2.35.2
next prev parent reply other threads:[~2022-07-29 12:20 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-29 12:19 v1 Create database directory David Bremner
2022-07-29 12:19 ` [PATCH 1/6] tests: remove dead code from T055-path-config.sh David Bremner
2022-08-06 12:19 ` David Bremner
2022-07-29 12:19 ` [PATCH 2/6] test: add test for creating database in various configurations David Bremner
2022-09-03 11:33 ` David Bremner
2022-07-29 12:19 ` [PATCH 3/6] test/path-config: set database.mail_root but not database.path David Bremner
2022-07-29 12:19 ` David Bremner [this message]
2022-07-29 12:20 ` [PATCH 5/6] lib/open: return non-SUCCESS on missing database path David Bremner
2022-07-29 12:20 ` [PATCH 6/6] lib/open: create database path in some cases David Bremner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220729122001.1556787-5-david@tethera.net \
--to=david@tethera.net \
--cc=notmuch@notmuchmail.org \
--cc=spwhitton@spwhitton.name \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).