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>
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
+++ /dev/null
-#include "compat.h"
-#include <limits.h>
-#undef _GNU_SOURCE
-#include <stdlib.h>
-
-char *
-canonicalize_file_name (const char *path)
-{
-#ifdef PATH_MAX
- char *resolved_path = malloc (PATH_MAX + 1);
- if (resolved_path == NULL)
- return NULL;
-
- return realpath (path, resolved_path);
-#else
-#error undefined PATH_MAX _and_ missing canonicalize_file_name not supported
-#endif
-}
#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>
#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)
_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)));
#include <netdb.h>
#include <assert.h>
+#include "path-util.h"
#include "unicode-util.h"
static const char toplevel_config_comment[] =
}
/* 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);
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)
--- /dev/null
+/*
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define _GNU_SOURCE
+
+#include "path-util.h"
+
+#include <limits.h>
+#include <stdlib.h>
+
+
+char *
+notmuch_canonicalize_file_name (const char *path)
+{
+#if 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;
+
+ return realpath (path, resolved_path);
+#else
+#error undefined PATH_MAX _and_ missing canonicalize_file_name not supported
+#endif
+}
--- /dev/null
+/*
+ * 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_ */