|
|
c3e9a2 |
From c73e7dd16b7915ac9c67a376e014ea1220095348 Mon Sep 17 00:00:00 2001
|
|
|
c3e9a2 |
From: =?UTF-8?q?Nikola=20Forr=C3=B3?= <nforro@redhat.com>
|
|
|
c3e9a2 |
Date: Tue, 27 Aug 2019 17:53:03 +0200
|
|
|
c3e9a2 |
Subject: [PATCH] man(1): Fix override dir handling
|
|
|
c3e9a2 |
MIME-Version: 1.0
|
|
|
c3e9a2 |
Content-Type: text/plain; charset=UTF-8
|
|
|
c3e9a2 |
Content-Transfer-Encoding: 8bit
|
|
|
c3e9a2 |
|
|
|
c3e9a2 |
Previously, override dir was affecting only some cases
|
|
|
c3e9a2 |
of manpath determination.
|
|
|
c3e9a2 |
|
|
|
c3e9a2 |
Apply it only when all paths has been gathered instead.
|
|
|
c3e9a2 |
(Depending on the definition of when the override dir applies,
|
|
|
c3e9a2 |
this might not be correct).
|
|
|
c3e9a2 |
|
|
|
c3e9a2 |
Also look for override dir when sorting candidates.
|
|
|
c3e9a2 |
|
|
|
c3e9a2 |
Fixes src/tests/man-9 failing when --with-override-dir=od
|
|
|
c3e9a2 |
is passed to ./configure.
|
|
|
c3e9a2 |
|
|
|
c3e9a2 |
Reported-by: Nikola Forró <nforro@redhat.com>
|
|
|
c3e9a2 |
Tested-by: Nikola Forró <nforro@redhat.com>
|
|
|
c3e9a2 |
---
|
|
|
c3e9a2 |
src/man.c | 33 ++++++++++++++++++++++++++++++++
|
|
|
c3e9a2 |
src/manp.c | 55 +++++++++++++++++++++---------------------------------
|
|
|
c3e9a2 |
2 files changed, 54 insertions(+), 34 deletions(-)
|
|
|
c3e9a2 |
|
|
|
c3e9a2 |
diff --git a/src/man.c b/src/man.c
|
|
|
c3e9a2 |
index 6d1cba7..b3d13d1 100644
|
|
|
c3e9a2 |
--- a/src/man.c
|
|
|
c3e9a2 |
+++ b/src/man.c
|
|
|
c3e9a2 |
@@ -2712,6 +2712,32 @@ static bool duplicate_candidates (struct candidate *left,
|
|
|
c3e9a2 |
return ret;
|
|
|
c3e9a2 |
}
|
|
|
c3e9a2 |
|
|
|
c3e9a2 |
+static int cand1_differs_by_override_dir (const struct candidate *left,
|
|
|
c3e9a2 |
+ const struct candidate *right)
|
|
|
c3e9a2 |
+{
|
|
|
c3e9a2 |
+ size_t ov_len, pre_ov_len;
|
|
|
c3e9a2 |
+
|
|
|
c3e9a2 |
+ ov_len = strlen (OVERRIDE_DIR);
|
|
|
c3e9a2 |
+ if (!ov_len)
|
|
|
c3e9a2 |
+ return 0;
|
|
|
c3e9a2 |
+
|
|
|
c3e9a2 |
+ if (!STREQ (left->source->name, right->source->name))
|
|
|
c3e9a2 |
+ return 0;
|
|
|
c3e9a2 |
+
|
|
|
c3e9a2 |
+ pre_ov_len = strlen(right->path);
|
|
|
c3e9a2 |
+ if (!STRNEQ (left->path, right->path, pre_ov_len))
|
|
|
c3e9a2 |
+ return 0;
|
|
|
c3e9a2 |
+
|
|
|
c3e9a2 |
+ if (left->path[pre_ov_len] != '/')
|
|
|
c3e9a2 |
+ return 0;
|
|
|
c3e9a2 |
+ pre_ov_len++;
|
|
|
c3e9a2 |
+
|
|
|
c3e9a2 |
+ if (STREQ (left->path + pre_ov_len, OVERRIDE_DIR))
|
|
|
c3e9a2 |
+ return 1;
|
|
|
c3e9a2 |
+
|
|
|
c3e9a2 |
+ return 0;
|
|
|
c3e9a2 |
+}
|
|
|
c3e9a2 |
+
|
|
|
c3e9a2 |
static int compare_candidates (const struct candidate *left,
|
|
|
c3e9a2 |
const struct candidate *right)
|
|
|
c3e9a2 |
{
|
|
|
c3e9a2 |
@@ -2801,6 +2827,13 @@ static int compare_candidates (const struct candidate *left,
|
|
|
c3e9a2 |
if (cmp)
|
|
|
c3e9a2 |
return cmp;
|
|
|
c3e9a2 |
|
|
|
c3e9a2 |
+ /* Sort override dir first
|
|
|
c3e9a2 |
+ */
|
|
|
c3e9a2 |
+ if (cand1_differs_by_override_dir(left, right))
|
|
|
c3e9a2 |
+ return -1;
|
|
|
c3e9a2 |
+ if (cand1_differs_by_override_dir(right, left))
|
|
|
c3e9a2 |
+ return 1;
|
|
|
c3e9a2 |
+
|
|
|
c3e9a2 |
/* Try comparing based on language. We used to prefer to display a
|
|
|
c3e9a2 |
* page in the user's preferred language than a page from a better
|
|
|
c3e9a2 |
* section, but that attracted objections, so now we prefer to get
|
|
|
c3e9a2 |
diff --git a/src/manp.c b/src/manp.c
|
|
|
c3e9a2 |
index 5441339..e437183 100644
|
|
|
c3e9a2 |
--- a/src/manp.c
|
|
|
c3e9a2 |
+++ b/src/manp.c
|
|
|
c3e9a2 |
@@ -903,23 +903,6 @@ static char *def_path (enum config_flag flag)
|
|
|
c3e9a2 |
return manpath;
|
|
|
c3e9a2 |
}
|
|
|
c3e9a2 |
|
|
|
c3e9a2 |
-/*
|
|
|
c3e9a2 |
- * If specified with configure, append OVERRIDE_DIR to dir param and add it
|
|
|
c3e9a2 |
- * to list.
|
|
|
c3e9a2 |
- */
|
|
|
c3e9a2 |
-static void insert_override_dir (gl_list_t list, const char *dir)
|
|
|
c3e9a2 |
-{
|
|
|
c3e9a2 |
- char *override_dir = NULL;
|
|
|
c3e9a2 |
-
|
|
|
c3e9a2 |
- if (!strlen (OVERRIDE_DIR))
|
|
|
c3e9a2 |
- return;
|
|
|
c3e9a2 |
-
|
|
|
c3e9a2 |
- if ((override_dir = xasprintf ("%s/%s", dir, OVERRIDE_DIR))) {
|
|
|
c3e9a2 |
- add_dir_to_list (list, override_dir);
|
|
|
c3e9a2 |
- free (override_dir);
|
|
|
c3e9a2 |
- }
|
|
|
c3e9a2 |
-}
|
|
|
c3e9a2 |
-
|
|
|
c3e9a2 |
/*
|
|
|
c3e9a2 |
* For each directory in the user's path, see if it is one of the
|
|
|
c3e9a2 |
* directories listed in the man_db.config file. If so, and it is
|
|
|
c3e9a2 |
@@ -968,7 +951,6 @@ char *get_manpath_from_path (const char *path, int mandatory)
|
|
|
c3e9a2 |
if (!manpath_map_found)
|
|
|
c3e9a2 |
debug ("is in the config file\n");
|
|
|
c3e9a2 |
manpath_map_found = true;
|
|
|
c3e9a2 |
- insert_override_dir (tmplist, config_item->cont);
|
|
|
c3e9a2 |
add_dir_to_list (tmplist, config_item->cont);
|
|
|
c3e9a2 |
} GL_LIST_FOREACH_END (config);
|
|
|
c3e9a2 |
|
|
|
c3e9a2 |
@@ -989,11 +971,8 @@ char *get_manpath_from_path (const char *path, int mandatory)
|
|
|
c3e9a2 |
debug ("adding mandatory man directories\n");
|
|
|
c3e9a2 |
|
|
|
c3e9a2 |
GL_LIST_FOREACH_START (config, config_item) {
|
|
|
c3e9a2 |
- if (config_item->flag == MANDATORY) {
|
|
|
c3e9a2 |
- insert_override_dir (tmplist,
|
|
|
c3e9a2 |
- config_item->key);
|
|
|
c3e9a2 |
+ if (config_item->flag == MANDATORY)
|
|
|
c3e9a2 |
add_dir_to_list (tmplist, config_item->key);
|
|
|
c3e9a2 |
- }
|
|
|
c3e9a2 |
} GL_LIST_FOREACH_END (config);
|
|
|
c3e9a2 |
}
|
|
|
c3e9a2 |
|
|
|
c3e9a2 |
@@ -1078,7 +1057,6 @@ static void add_man_subdirs (gl_list_t list, const char *path)
|
|
|
c3e9a2 |
if (subdir) {
|
|
|
c3e9a2 |
newpath = xasprintf ("%.*s/man", (int) (subdir - path), path);
|
|
|
c3e9a2 |
if (is_directory (newpath) == 1) {
|
|
|
c3e9a2 |
- insert_override_dir (list, newpath);
|
|
|
c3e9a2 |
add_dir_to_list (list, newpath);
|
|
|
c3e9a2 |
}
|
|
|
c3e9a2 |
free (newpath);
|
|
|
c3e9a2 |
@@ -1086,7 +1064,6 @@ static void add_man_subdirs (gl_list_t list, const char *path)
|
|
|
c3e9a2 |
|
|
|
c3e9a2 |
newpath = xasprintf ("%s/man", path);
|
|
|
c3e9a2 |
if (is_directory (newpath) == 1) {
|
|
|
c3e9a2 |
- insert_override_dir (list, newpath);
|
|
|
c3e9a2 |
add_dir_to_list (list, newpath);
|
|
|
c3e9a2 |
}
|
|
|
c3e9a2 |
free (newpath);
|
|
|
c3e9a2 |
@@ -1095,7 +1072,6 @@ static void add_man_subdirs (gl_list_t list, const char *path)
|
|
|
c3e9a2 |
newpath = xasprintf ("%.*s/share/man",
|
|
|
c3e9a2 |
(int) (subdir - path), path);
|
|
|
c3e9a2 |
if (is_directory (newpath) == 1) {
|
|
|
c3e9a2 |
- insert_override_dir (list, newpath);
|
|
|
c3e9a2 |
add_dir_to_list (list, newpath);
|
|
|
c3e9a2 |
}
|
|
|
c3e9a2 |
free (newpath);
|
|
|
c3e9a2 |
@@ -1103,7 +1079,6 @@ static void add_man_subdirs (gl_list_t list, const char *path)
|
|
|
c3e9a2 |
|
|
|
c3e9a2 |
newpath = xasprintf ("%s/share/man", path);
|
|
|
c3e9a2 |
if (is_directory (newpath) == 1) {
|
|
|
c3e9a2 |
- insert_override_dir (list, newpath);
|
|
|
c3e9a2 |
add_dir_to_list (list, newpath);
|
|
|
c3e9a2 |
}
|
|
|
c3e9a2 |
free (newpath);
|
|
|
c3e9a2 |
@@ -1199,7 +1174,9 @@ gl_list_t create_pathlist (const char *manp)
|
|
|
c3e9a2 |
const struct canonicalized_path *cp;
|
|
|
c3e9a2 |
|
|
|
c3e9a2 |
/* Expand the manpath into a list of (path, canonicalized path)
|
|
|
c3e9a2 |
- * pairs for easier handling. add_dir_to_path_list only adds items
|
|
|
c3e9a2 |
+ * pairs for easier handling. For each entry, add corresponding
|
|
|
c3e9a2 |
+ * OVERRIDE_DIR.
|
|
|
c3e9a2 |
+ * add_dir_to_path_list only adds items
|
|
|
c3e9a2 |
* if they do not have the same canonicalized path as an existing
|
|
|
c3e9a2 |
* item, thereby eliminating duplicates due to symlinks.
|
|
|
c3e9a2 |
*/
|
|
|
c3e9a2 |
@@ -1208,15 +1185,25 @@ gl_list_t create_pathlist (const char *manp)
|
|
|
c3e9a2 |
(GL_LINKEDHASH_LIST, canonicalized_path_equals,
|
|
|
c3e9a2 |
canonicalized_path_hash, canonicalized_path_free, false);
|
|
|
c3e9a2 |
for (p = manp;; p = end + 1) {
|
|
|
c3e9a2 |
+ char *element, *element_override;
|
|
|
c3e9a2 |
+ ssize_t p_len;
|
|
|
c3e9a2 |
+
|
|
|
c3e9a2 |
end = strchr (p, ':');
|
|
|
c3e9a2 |
- if (end) {
|
|
|
c3e9a2 |
- char *element = xstrndup (p, end - p);
|
|
|
c3e9a2 |
- add_dir_to_path_list (canonicalized_list, element);
|
|
|
c3e9a2 |
- free (element);
|
|
|
c3e9a2 |
- } else {
|
|
|
c3e9a2 |
- add_dir_to_path_list (canonicalized_list, p);
|
|
|
c3e9a2 |
- break;
|
|
|
c3e9a2 |
+ p_len = end ? end - p : (ssize_t)strlen(p);
|
|
|
c3e9a2 |
+
|
|
|
c3e9a2 |
+ element = xstrndup (p, p_len);
|
|
|
c3e9a2 |
+
|
|
|
c3e9a2 |
+ if (strlen(OVERRIDE_DIR)) {
|
|
|
c3e9a2 |
+ element_override = xasprintf("%s/%s", element, OVERRIDE_DIR);
|
|
|
c3e9a2 |
+ add_dir_to_path_list (canonicalized_list, element_override);
|
|
|
c3e9a2 |
+ free (element_override);
|
|
|
c3e9a2 |
}
|
|
|
c3e9a2 |
+
|
|
|
c3e9a2 |
+ add_dir_to_path_list (canonicalized_list, element);
|
|
|
c3e9a2 |
+ free (element);
|
|
|
c3e9a2 |
+
|
|
|
c3e9a2 |
+ if (!end)
|
|
|
c3e9a2 |
+ break;
|
|
|
c3e9a2 |
}
|
|
|
c3e9a2 |
|
|
|
c3e9a2 |
list = new_string_list (GL_ARRAY_LIST, false);
|
|
|
c3e9a2 |
--
|
|
|
c3e9a2 |
2.26.2
|
|
|
c3e9a2 |
|