Blame SOURCES/man-db-2.7.6.1-fix-override-dir-handling.patch

b9042c
From 84d6b3fab40be5e1ea288fb296df6cd8be06c985 Mon Sep 17 00:00:00 2001
b9042c
From: =?UTF-8?q?Nikola=20Forr=C3=B3?= <nforro@redhat.com>
b9042c
Date: Thu, 19 Jan 2017 10:45:57 +0100
b9042c
Subject: [PATCH] man(1): Fix override dir handling
b9042c
MIME-Version: 1.0
b9042c
Content-Type: text/plain; charset=UTF-8
b9042c
Content-Transfer-Encoding: 8bit
b9042c
b9042c
Previously, override dir was affecting only some cases
b9042c
of manpath determination.
b9042c
b9042c
Apply it only when all paths has been gathered instead.
b9042c
(Depending on the definition of when the override dir applies,
b9042c
this might not be correct).
b9042c
b9042c
Also look for override dir when sorting candidates.
b9042c
b9042c
Fixes src/tests/man-9 failing when --with-override-dir=od
b9042c
is passed to ./configure.
b9042c
b9042c
Reported-by: Nikola Forró <nforro@redhat.com>
b9042c
Tested-by: Nikola Forró <nforro@redhat.com>
b9042c
---
b9042c
 src/man.c  | 33 +++++++++++++++++++++++++++++++++
b9042c
 src/manp.c | 52 +++++++++++++++++++++-------------------------------
b9042c
 2 files changed, 54 insertions(+), 31 deletions(-)
b9042c
b9042c
diff --git a/src/man.c b/src/man.c
b9042c
index 15a568a..8b11f43 100644
b9042c
--- a/src/man.c
b9042c
+++ b/src/man.c
b9042c
@@ -2665,6 +2665,32 @@ static int duplicate_candidates (struct candidate *left,
b9042c
 	return ret;
b9042c
 }
b9042c
 
b9042c
+static int cand1_differs_by_override_dir (const struct candidate *left,
b9042c
+		                          const struct candidate *right)
b9042c
+{
b9042c
+	size_t ov_len, pre_ov_len;
b9042c
+
b9042c
+	ov_len = strlen (OVERRIDE_DIR);
b9042c
+	if (!ov_len)
b9042c
+		return 0;
b9042c
+
b9042c
+	if (!STREQ (left->source->name, right->source->name))
b9042c
+		return 0;
b9042c
+
b9042c
+	pre_ov_len = strlen(right->path);
b9042c
+	if (!STRNEQ (left->path, right->path, pre_ov_len))
b9042c
+		return 0;
b9042c
+
b9042c
+	if (left->path[pre_ov_len] != '/')
b9042c
+		return 0;
b9042c
+	pre_ov_len++;
b9042c
+
b9042c
+	if (STREQ (left->path + pre_ov_len, OVERRIDE_DIR))
b9042c
+		return 1;
b9042c
+
b9042c
+	return 0;
b9042c
+}
b9042c
+
b9042c
 static int compare_candidates (const struct candidate *left,
b9042c
 			       const struct candidate *right)
b9042c
 {
b9042c
@@ -2749,6 +2775,13 @@ static int compare_candidates (const struct candidate *left,
b9042c
 	if (cmp)
b9042c
 		return cmp;
b9042c
 
b9042c
+	/* Sort override dir first
b9042c
+	 */
b9042c
+	if (cand1_differs_by_override_dir(left, right))
b9042c
+		return -1;
b9042c
+	if (cand1_differs_by_override_dir(right, left))
b9042c
+		return 1;
b9042c
+
b9042c
 	/* Try comparing based on language. We used to prefer to display a
b9042c
 	 * page in the user's preferred language than a page from a better
b9042c
 	 * section, but that attracted objections, so now we prefer to get
b9042c
diff --git a/src/manp.c b/src/manp.c
b9042c
index 0d864f1..b78a50f 100644
b9042c
--- a/src/manp.c
b9042c
+++ b/src/manp.c
b9042c
@@ -931,23 +931,6 @@ static char *def_path (int flag)
b9042c
 }
b9042c
 
b9042c
 /*
b9042c
- * If specified with configure, append OVERRIDE_DIR to dir param and add it
b9042c
- * to the lp list.
b9042c
- */
b9042c
-static void insert_override_dir (char **lp, const char *dir)
b9042c
-{
b9042c
-	char *override_dir = NULL;
b9042c
-
b9042c
-	if (!strlen (OVERRIDE_DIR))
b9042c
-		return;
b9042c
-
b9042c
-	if ((override_dir = xasprintf ("%s/%s", dir, OVERRIDE_DIR))) {
b9042c
-		add_dir_to_list (lp, override_dir);
b9042c
-		free (override_dir);
b9042c
-	}
b9042c
-}
b9042c
-
b9042c
-/*
b9042c
  * For each directory in the user's path, see if it is one of the
b9042c
  * directories listed in the man_db.config file.  If so, and it is
b9042c
  * not already in the manpath, add it.  If the directory is not listed
b9042c
@@ -994,8 +977,6 @@ char *get_manpath_from_path (const char *path, int mandatory)
b9042c
 		if (mandir_list) {
b9042c
 			debug ("is in the config file\n");
b9042c
 			while (mandir_list) {
b9042c
-				insert_override_dir (tmplist,
b9042c
-						     mandir_list->cont);
b9042c
 				add_dir_to_list (tmplist, mandir_list->cont);
b9042c
 				mandir_list = iterate_over_list
b9042c
 					(mandir_list, p, MANPATH_MAP);
b9042c
@@ -1014,7 +995,6 @@ char *get_manpath_from_path (const char *path, int mandatory)
b9042c
 				       "../share/man, or share/man "
b9042c
 				       "subdirectory\n");
b9042c
 
b9042c
-				insert_override_dir (tmplist, t);
b9042c
 				add_dir_to_list (tmplist, t);
b9042c
 				free (t);
b9042c
 		 	} else
b9042c
@@ -1030,10 +1010,8 @@ char *get_manpath_from_path (const char *path, int mandatory)
b9042c
 		debug ("\nadding mandatory man directories\n\n");
b9042c
 
b9042c
 		for (list = namestore; list; list = list->next)
b9042c
-			if (list->flag == MANDATORY) {
b9042c
-				insert_override_dir (tmplist, list->key);
b9042c
+			if (list->flag == MANDATORY)
b9042c
 				add_dir_to_list (tmplist, list->key);
b9042c
-			}
b9042c
 	}
b9042c
 
b9042c
 	len = 0;
b9042c
@@ -1201,18 +1179,30 @@ void create_pathlist (const char *manp, char **mp)
b9042c
 	const char *p, *end;
b9042c
 	char **mphead = mp;
b9042c
 
b9042c
-	/* Expand the manpath into a list for easier handling. */
b9042c
+	/* Expand the manpath into a list for easier handling.
b9042c
+	 * For each entry, add corresponding OVERRIDE_DIR.
b9042c
+	 * */
b9042c
 
b9042c
 	for (p = manp;; p = end + 1) {
b9042c
+		char *element, *element_override;
b9042c
+		ssize_t p_len;
b9042c
+
b9042c
 		end = strchr (p, ':');
b9042c
-		if (end) {
b9042c
-			char *element = xstrndup (p, end - p);
b9042c
-			mp = add_dir_to_path_list (mphead, mp, element);
b9042c
-			free (element);
b9042c
-		} else {
b9042c
-			mp = add_dir_to_path_list (mphead, mp, p);
b9042c
-			break;
b9042c
+		p_len = end ? end - p : (ssize_t)strlen(p);
b9042c
+
b9042c
+		element = xstrndup (p, p_len);
b9042c
+
b9042c
+		if (strlen(OVERRIDE_DIR)) {
b9042c
+			element_override = xasprintf("%s/%s", element, OVERRIDE_DIR);
b9042c
+			mp = add_dir_to_path_list (mphead, mp, element_override);
b9042c
+			free (element_override);
b9042c
 		}
b9042c
+
b9042c
+		mp = add_dir_to_path_list (mphead, mp, element);
b9042c
+		free (element);
b9042c
+
b9042c
+		if (!end)
b9042c
+			break;
b9042c
 	}
b9042c
 	*mp = NULL;
b9042c
 
b9042c
-- 
b9042c
2.7.4
b9042c