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

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