unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: "Đoàn Trần Công Danh" <congdanhqx@gmail.com>
To: notmuch@notmuchmail.org
Cc: "Tomi Ollila" <tomi.ollila@iki.fi>,
	"Đoàn Trần Công Danh" <congdanhqx@gmail.com>
Subject: [PATCH v3] compat: rename {,notmuch_}canonicalize_file_name
Date: Sat, 24 Apr 2021 07:57:19 +0700	[thread overview]
Message-ID: <20210424005719.26456-1-congdanhqx@gmail.com> (raw)
In-Reply-To: <20210417001835.24251-1-congdanhqx@gmail.com>

When compat canonicalize_file_name was introduced, it was limited to
C code only because it was used by C code only during that time.

From 5ec6fd4d, (lib/open: check for split configuration when creating
database., 2021-02-16), lib/open.cc, which is C++, relies on the
existent of canonicalize_file_name.

However, we can't blindly enable canonicalize_file_name for C++ code,
because different implementation has different additional signature for
C++ and users can arbitrarily add -DHAVE_CANONICALIZE_FILE_NAME=0 to
{C,CXX}FLAGS.

Let's move our implementation into a util library.

Helped-by: Tomi Ollila <tomi.ollila@iki.fi>
Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>
---
 compat/Makefile.local                         |  4 ----
 compat/compat.h                               |  8 --------
 lib/open.cc                                   |  5 +++--
 notmuch-config.c                              |  3 ++-
 util/Makefile.local                           |  2 +-
 .../path-util.c                               | 17 +++++++++++++----
 util/path-util.h                              | 19 +++++++++++++++++++
 7 files changed, 38 insertions(+), 20 deletions(-)
 rename compat/canonicalize_file_name.c => util/path-util.c (52%)
 create mode 100644 util/path-util.h

diff --git a/compat/Makefile.local b/compat/Makefile.local
index 2ee1b399..c58ca746 100644
--- a/compat/Makefile.local
+++ b/compat/Makefile.local
@@ -5,10 +5,6 @@ extra_cflags += -I$(srcdir)/$(dir)
 
 notmuch_compat_srcs :=
 
-ifneq ($(HAVE_CANONICALIZE_FILE_NAME),1)
-notmuch_compat_srcs += $(dir)/canonicalize_file_name.c
-endif
-
 ifneq ($(HAVE_GETLINE),1)
 notmuch_compat_srcs += $(dir)/getline.c $(dir)/getdelim.c
 endif
diff --git a/compat/compat.h b/compat/compat.h
index 8f15e585..59e91618 100644
--- a/compat/compat.h
+++ b/compat/compat.h
@@ -37,14 +37,6 @@ extern "C" {
 #define _POSIX_PTHREAD_SEMANTICS 1
 #endif
 
-#if ! HAVE_CANONICALIZE_FILE_NAME
-/* we only call this function from C, and this makes testing easier */
-#ifndef __cplusplus
-char *
-canonicalize_file_name (const char *path);
-#endif
-#endif
-
 #if ! HAVE_GETLINE
 #include <stdio.h>
 #include <unistd.h>
diff --git a/lib/open.cc b/lib/open.cc
index 5d80a884..bdb695fe 100644
--- a/lib/open.cc
+++ b/lib/open.cc
@@ -3,6 +3,7 @@
 
 #include "database-private.h"
 #include "parse-time-vrp.h"
+#include "path-util.h"
 
 #if HAVE_XAPIAN_DB_RETRY_LOCK
 #define DB_ACTION (Xapian::DB_CREATE_OR_OPEN | Xapian::DB_RETRY_LOCK)
@@ -612,9 +613,9 @@ notmuch_database_create_with_config (const char *database_path,
     _set_database_path (notmuch, database_path);
 
     if (key_file && ! split) {
-	char *mail_root = canonicalize_file_name (
+	char *mail_root = notmuch_canonicalize_file_name (
 	    g_key_file_get_value (key_file, "database", "mail_root", NULL));
-	char *db_path = canonicalize_file_name (database_path);
+	char *db_path = notmuch_canonicalize_file_name (database_path);
 
 	split = (mail_root && (0 != strcmp (mail_root, db_path)));
 
diff --git a/notmuch-config.c b/notmuch-config.c
index 16e86916..d9390c4d 100644
--- a/notmuch-config.c
+++ b/notmuch-config.c
@@ -24,6 +24,7 @@
 #include <netdb.h>
 #include <assert.h>
 
+#include "path-util.h"
 #include "unicode-util.h"
 
 static const char toplevel_config_comment[] =
@@ -327,7 +328,7 @@ notmuch_conffile_save (notmuch_conffile_t *config)
     }
 
     /* Try not to overwrite symlinks. */
-    filename = canonicalize_file_name (config->filename);
+    filename = notmuch_canonicalize_file_name (config->filename);
     if (! filename) {
 	if (errno == ENOENT) {
 	    filename = strdup (config->filename);
diff --git a/util/Makefile.local b/util/Makefile.local
index 7ef029a5..8a0b9bc3 100644
--- a/util/Makefile.local
+++ b/util/Makefile.local
@@ -6,7 +6,7 @@ extra_cflags += -I$(srcdir)/$(dir)
 libnotmuch_util_c_srcs := $(dir)/xutil.c $(dir)/error_util.c $(dir)/hex-escape.c \
 		  $(dir)/string-util.c $(dir)/talloc-extra.c $(dir)/zlib-extra.c \
 		$(dir)/util.c $(dir)/gmime-extra.c $(dir)/crypto.c \
-		$(dir)/repair.c \
+		$(dir)/repair.c $(dir)/path-util.c \
 		$(dir)/unicode-util.c
 
 libnotmuch_util_modules := $(libnotmuch_util_c_srcs:.c=.o)
diff --git a/compat/canonicalize_file_name.c b/util/path-util.c
similarity index 52%
rename from compat/canonicalize_file_name.c
rename to util/path-util.c
index 000f9e78..4b352baf 100644
--- a/compat/canonicalize_file_name.c
+++ b/util/path-util.c
@@ -1,12 +1,21 @@
-#include "compat.h"
+/*
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define _GNU_SOURCE
+
+#include "path-util.h"
+
 #include <limits.h>
-#undef _GNU_SOURCE
 #include <stdlib.h>
 
+
 char *
-canonicalize_file_name (const char *path)
+notmuch_canonicalize_file_name (const char *path)
 {
-#ifdef PATH_MAX
+#ifdef HAVE_CANONICALIZE_FILE_NAME
+    return canonicalize_file_name (path);
+#elif defined(PATH_MAX)
     char *resolved_path =  malloc (PATH_MAX + 1);
     if (resolved_path == NULL)
 	return NULL;
diff --git a/util/path-util.h b/util/path-util.h
new file mode 100644
index 00000000..ac85f696
--- /dev/null
+++ b/util/path-util.h
@@ -0,0 +1,19 @@
+/*
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#ifndef NOTMUCH_UTIL_PATH_UTIL_H_
+#define NOTMUCH_UTIL_PATH_UTIL_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+char *
+notmuch_canonicalize_file_name (const char *path);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* NOTMUCH_UTIL_PATH_UTIL_H_ */
-- 
2.31.1.500.gbc6bbdd36b\r

  parent reply	other threads:[~2021-04-24  0:57 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-17  0:18 [PATCH] compat: expose canonicalize_file_name to C++ Đoàn Trần Công Danh
2021-04-17 12:13 ` David Bremner
2021-04-17 12:49   ` Đoàn Trần Công Danh
2021-04-17 14:39     ` David Bremner
2021-04-18  4:13       ` Đoàn Trần Công Danh
2021-04-18  7:08         ` Tomi Ollila
2021-04-18 10:38           ` Đoàn Trần Công Danh
2021-04-23 17:31             ` David Bremner
2021-04-24  0:29               ` Đoàn Trần Công Danh
2021-04-18 12:48         ` David Bremner
2021-04-18 16:19           ` Tomi Ollila
2021-04-18 16:47             ` Tomi Ollila
2021-04-24  0:57 ` Đoàn Trần Công Danh [this message]
2021-04-24  1:01   ` [PATCH v3] compat: rename {,notmuch_}canonicalize_file_name Đoàn Trần Công Danh
2021-04-24  1:05   ` [PATCH v4] " Đoàn Trần Công Danh
2021-04-24 11:43     ` 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=20210424005719.26456-1-congdanhqx@gmail.com \
    --to=congdanhqx@gmail.com \
    --cc=notmuch@notmuchmail.org \
    --cc=tomi.ollila@iki.fi \
    /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).